From 09a0bf84d8d7f8c9c90e5f0675e53a57e730a172 Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Mon, 13 Mar 2023 14:14:44 +0000 Subject: [PATCH] Adds environment variables to set listen address and port Thi is useful to prevent it listening on all interfaces. --- os_capacity/prometheus.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/os_capacity/prometheus.py b/os_capacity/prometheus.py index 2155e2a..a29e217 100755 --- a/os_capacity/prometheus.py +++ b/os_capacity/prometheus.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import os import collections import json import time @@ -343,7 +344,12 @@ def collect(self): if __name__ == "__main__": - prom_client.start_http_server(9000) + kwargs = { + "port": int(os.environ.get('OS_CAPACITY_EXPORTER_PORT', 9000)), + "addr": os.environ.get('OS_CAPACITY_EXPORTER_LISTEN_ADDRESS', '0.0.0.0'), + } + prom_client.start_http_server(**kwargs) + prom_core.REGISTRY.register(OpenStackCapacityCollector()) # there must be a better way! while True: