summaryrefslogtreecommitdiff
path: root/python-status-exporter/python-status-exporter.py
diff options
context:
space:
mode:
Diffstat (limited to 'python-status-exporter/python-status-exporter.py')
-rwxr-xr-xpython-status-exporter/python-status-exporter.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/python-status-exporter/python-status-exporter.py b/python-status-exporter/python-status-exporter.py
new file mode 100755
index 0000000..b6c0807
--- /dev/null
+++ b/python-status-exporter/python-status-exporter.py
@@ -0,0 +1,53 @@
+#!/bin/env python3
+
+import sys
+import os
+import inspect
+sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/modules/client_python")
+
+from prometheus_client import start_http_server
+
+import argparse
+import importlib
+
+from pprint import pprint
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-m", "--module", help="Module to load", action="append", nargs="+", required=True, type=str)
+ args = parser.parse_args()
+
+ """
+On the other hand, the statement from spam.ham import eggs, sausage as saus results in
+
+_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], -1)
+eggs = _temp.eggs
+saus = _temp.sausage
+
+Here, the spam.ham module is returned from __import__(). From this object, the names to import are retrieved and assigned to their respective names.
+
+"""
+ mods = list()
+ for m in args.module:
+ mod = importlib.import_module("modules." + m[0])
+ mods.append(mod)
+
+ for m in mods:
+ pprint(m)
+ pprint(dir(m))
+
+ prom_data = dict()
+
+ for m in mods:
+ m.init_datapoints(prom_data)
+ m.update_datapoints(prom_data)
+ start_http_server(8000)
+ while True:
+ try:
+ time.sleep(15)
+ except Exception:
+ pass
+ for m in mods:
+ m.init_datapoints(prom_data)
+ m.update_datapoints(prom_data)
+