diff options
| author | Oleg Pykhalov <go.wigust@gmail.com> | 2022-03-18 23:17:00 +0300 |
|---|---|---|
| committer | Oleg Pykhalov <go.wigust@gmail.com> | 2022-03-19 10:53:46 +0300 |
| commit | 735dce4ccc4d1ecef30ddb1fdb5868949a368ac0 (patch) | |
| tree | bd4d0f44305f355dad23c0bdbf951a9b099da1da | |
| parent | ssh_exporter: Move Prometheus Counters inside main procedure. (diff) | |
| download | python-prometheus-ssh-exporter-origin/master.tar.gz | |
ssh_exporter: Specify config file via arguments.v2.0.0origin/mastermaster
| -rw-r--r-- | ssh_exporter/__main__.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ssh_exporter/__main__.py b/ssh_exporter/__main__.py index 49f2894..5adcecd 100644 --- a/ssh_exporter/__main__.py +++ b/ssh_exporter/__main__.py @@ -1,5 +1,6 @@ """Connect to server over SSH and collect metrics.""" +import argparse import yaml from prometheus_client import Counter, start_http_server import jc.parsers.ifconfig @@ -38,6 +39,10 @@ def main(): """Entry point.""" running_user = os.getenv("USERNAME", "root") + parser = argparse.ArgumentParser(description="Prometheus SSH exporter") + parser.add_argument("-c", "--config", help="Config file", type=str) + args = parser.parse_args() + node_network_receive_bytes_total = Counter( "node_network_receive_bytes_total", "Network device statistic receive_bytes.", @@ -62,12 +67,13 @@ def main(): ["device", "target"], ) - with open("/tmp/config.yml") as config_file: + with open(args.config) as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader) listen_addresses = config["listen"] if "listen" in config else "0.0.0.0:9101" interval = config["interval"] if "interval" in config else 10 start_http_server( - port=int(listen_addresses.split(":")[1]), addr=listen_addresses.split(":")[0] + port=int(listen_addresses.split(":")[1]), + addr=listen_addresses.split(":")[0], ) while True: for host in config["hosts"].keys(): |
