summaryrefslogtreecommitdiff
path: root/python-status-exporter/modules
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 /python-status-exporter/modules
parent2aa38ce2ee82c5435e597773edf2569c56e3b1cf (diff)
nginx_vod beta module datafetcher done.
Diffstat (limited to 'python-status-exporter/modules')
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
3 files changed, 24 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
+