summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Luttermann Poulsen <llp@nordu.net>2017-09-01 13:24:54 +0200
committerLasse Luttermann Poulsen <llp@nordu.net>2017-09-01 13:24:54 +0200
commitad0081372073797e7cadcee323ff694de2dd270d (patch)
tree667fa6d8cc6ae8008ef5c3ec75fc3358ab12ba2a
parent2aa38ce2ee82c5435e597773edf2569c56e3b1cf (diff)
nginx_vod beta module datafetcher done.
m---------python-status-exporter/modules/client_python0
-rwxr-xr-xpython-status-exporter/modules/nginx_vod.py34
-rw-r--r--python-status-exporter/modules/tools.py10
-rwxr-xr-xpython-status-exporter/python-status-exporter.py53
4 files changed, 77 insertions, 20 deletions
diff --git a/python-status-exporter/modules/client_python b/python-status-exporter/modules/client_python
new file mode 160000
+Subproject 7fb50581ec03fe9f320dcecfcba0952b683d279
diff --git a/python-status-exporter/modules/nginx_vod.py b/python-status-exporter/modules/nginx_vod.py
index c4547cf..1ce42ac 100755
--- a/python-status-exporter/modules/nginx_vod.py
+++ b/python-status-exporter/modules/nginx_vod.py
@@ -4,18 +4,15 @@ import sys
import os
import inspect
sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/client_python")
+sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
-import httplib
+import tools
+import http.client
import xml.etree.ElementTree as XET
-from prometheus_client import start_http_server, Summary, Gauge
+from prometheus_client import Summary, Gauge
-"""
-vod_status_con = httplib.HTTPConnection('127.0.0.1', 87, timeout=2)
-vod_status_con.request("GET", "/vod_status")
-
-resp = vod_status_con.getresponse()
-"""
+SETTINGS = [tools.primary_ip(), 87, "/vod_status"]
def rec_xml_loop(xml, data, path=""):
children = xml.getchildren()
@@ -31,16 +28,10 @@ def rec_xml_loop(xml, data, path=""):
if path == "":
return data
-VOD_HOST = "127.0.0.1"
-VOD_PORT = 87
-VOD_PATH = "/vod_status"
-
-# REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
-# TEST_SEC = Gauge('time_now_sec', 'Current value for det second hand on our clock')
-def get_xml(host=VOD_HOST, port=VOD_PORT, path=VOD_PATH):
- vod_status_con = httplib.HTTPConnection(host, port, timeout=2)
- vod_status_con.request("GET", path)
+def get_xml(host="127.0.0.1", port=SETTINGS[1], path=SETTINGS[2]):
+ vod_status_con = http.client.HTTPConnection(host, port, timeout=2)
+ vod_status_con.request("GET", path, None)
resp = vod_status_con.getresponse()
if resp.status == 200:
@@ -51,14 +42,17 @@ def get_xml(host=VOD_HOST, port=VOD_PORT, path=VOD_PATH):
vod_status_con.close()
raise Exception("Unable to fetch info from http server {}:{}/{}".format(host, port, path))
-def init_datapoints(data_dict, labels):
+def init_datapoints(data_dict, labels = ['host', 'port', 'path']):
from_xml_data = dict()
xml_obj = XET.fromstring(get_xml())
xml_data_dict = rec_xml_loop(xml_obj, from_xml_data)
for key in xml_data_dict:
- data_dict[key] = Gauge(key, key, labels)
+ try:
+ data_dict[key] = Gauge(key, key, labels)
+ except ValueError:
+ pass
-def update_datapoints(data_dict, label_vals):
+def update_datapoints(data_dict, label_vals = SETTINGS):
from_xml_data = dict()
xml_obj = XET.fromstring(get_xml())
xml_data_dict = rec_xml_loop(xml_obj, from_xml_data)
diff --git a/python-status-exporter/modules/tools.py b/python-status-exporter/modules/tools.py
new file mode 100644
index 0000000..f54099d
--- /dev/null
+++ b/python-status-exporter/modules/tools.py
@@ -0,0 +1,10 @@
+
+
+import socket
+def primary_ip():
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.connect(("8.8.8.8", 80))
+ ip = s.getsockname()[0]
+ s.close()
+ return ip
+
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)
+