Skip to content

Commit

Permalink
Provide evironment variables (#48)
Browse files Browse the repository at this point in the history
* As alternative to command line parameters `--config` and `--port` we now
provide environment variables `P3E_CONFIG` and `P3E_PORT`
* Add documentation
* Add changelog entry
  • Loading branch information
cmeissner authored Sep 13, 2022
1 parent 4cc3a95 commit a0e6495
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
---

### New
* Fix \#47 - add environment variables for fundamental parameters

### Changes

Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ We also release all versions on [pypi](https://pypi.org/project/p3exporter/) so
pip install p3exporter
```

This will install the exporter and all of its dependencies. Now you can start it as every other program. You need to add `--config` or `-c` option with path to your `p3.yml` file.
This will install the exporter and all of its dependencies. Now you can start it as every other program. You need to provide a valid configuration file either by adding `--config` or `-c` option with path to your `p3.yml` file or by defining an environment variable `P3E_CONFIG` which points to your configuration.

```text
$ curl --silent https://raw.githubusercontent.com/codeaffen/p3exporter/develop/p3.yml --output ~/tmp/p3.yml
Expand Down Expand Up @@ -92,11 +92,11 @@ docker run -d --net="host" --pid="host" -v "/:/host:ro,rslave" p3exporter:latest

## Collectors

Name | Description
---- | -----------
example | example collector that actually does nothing but show how long a function has been executed
loadavg | collects average load in 1, 5 and 15 minutes interval
netdev | collects netword device information and statistics
| Name | Description |
| ---- | ----------- |
| example | example collector that actually does nothing but show how long a function has been executed |
| loadavg | collects average load in 1, 5 and 15 minutes interval |
| netdev | collects netword device information and statistics |

### Activation and Deactivation of collectors

Expand All @@ -115,3 +115,12 @@ collector_opts:
- docker0
- lo
```
### Start-up Configuration
You can define two fundamental Parameters on program start-up. The following table summarized you options:
| Parameter | Environment variable | Default | Description |
| --------- | -------------------- | ------- | ----------- |
| --config | P3E_CONFIG | p3.yml | Path to the used configuration file |
| --port | P3E_PORT | 5876 | TCP port on which the p3exporter listen for connections |
5 changes: 3 additions & 2 deletions p3exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import yaml
import logging
import os
import signal
import sys
import time
Expand Down Expand Up @@ -31,9 +32,9 @@ def main():
logging.getLogger().setLevel(logging.INFO)

parser = argparse.ArgumentParser(description="Python programmable Prometheus exporter.")
parser.add_argument('-c', '--config', default='p3.yml',
parser.add_argument('-c', '--config', default=os.getenv('P3E_CONFIG', 'p3.yml'),
help='path to configuration file.')
parser.add_argument('-p', '--port', default=5876,
parser.add_argument('-p', '--port', default=os.getenv('P3E_PORT', 5876),
help='exporter exposed port')
args = parser.parse_args()

Expand Down

0 comments on commit a0e6495

Please sign in to comment.