diff options
-rw-r--r-- | nginx-vod-status-exporter/modules/__init__.py | 0 | ||||
-rwxr-xr-x | nginx-vod-status-exporter/modules/nginx_vod.py | 74 |
2 files changed, 74 insertions, 0 deletions
diff --git a/nginx-vod-status-exporter/modules/__init__.py b/nginx-vod-status-exporter/modules/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/nginx-vod-status-exporter/modules/__init__.py diff --git a/nginx-vod-status-exporter/modules/nginx_vod.py b/nginx-vod-status-exporter/modules/nginx_vod.py new file mode 100755 index 0000000..c4547cf --- /dev/null +++ b/nginx-vod-status-exporter/modules/nginx_vod.py @@ -0,0 +1,74 @@ +#!/bin/env python2.6 + +import sys +import os +import inspect +sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/client_python") + +import httplib +import xml.etree.ElementTree as XET + +from prometheus_client import start_http_server, 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() +""" + +def rec_xml_loop(xml, data, path=""): + children = xml.getchildren() + if len(children) < 1: + data[path + xml.tag] = xml.text + else: + for c in children: + if path == "": + rec_xml_loop(c, data, xml.tag) + else: + rec_xml_loop(c, data, path + "_" + xml.tag) + + 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) + resp = vod_status_con.getresponse() + + if resp.status == 200: + data = resp.read() + vod_status_con.close() + return data + else: + vod_status_con.close() + raise Exception("Unable to fetch info from http server {}:{}/{}".format(host, port, path)) + +def init_datapoints(data_dict, labels): + 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) + +def update_datapoints(data_dict, label_vals): + from_xml_data = dict() + xml_obj = XET.fromstring(get_xml()) + xml_data_dict = rec_xml_loop(xml_obj, from_xml_data) + for key in data_dict: + if key in xml_data_dict: + try: + float(xml_data_dict[key]) + except ValueError: + pass + else: + data_dict[key].labels(*label_vals).set(xml_data_dict[key]) + + |