Prometheus client
Initial prometheus client
Change-Id: I8c02be6fe7e58c2f37ac19547fd7a795896af4bc
Reviewed-on: https://review.gerrithub.io/368732
Reviewed-by: Tatyanka Leontovich <tleontovich@mirantis.com>
Tested-by: Tatyanka Leontovich <tleontovich@mirantis.com>
diff --git a/tcp_tests/managers/clients/prometheus/prometheus_client.py b/tcp_tests/managers/clients/prometheus/prometheus_client.py
new file mode 100644
index 0000000..bf748af
--- /dev/null
+++ b/tcp_tests/managers/clients/prometheus/prometheus_client.py
@@ -0,0 +1,31 @@
+import json
+
+from tcp_tests.managers.clients import http_client
+
+
+class PrometheusClient(object):
+ def __init__(self, host, port, proto):
+ self.url = '{0}://{1}:{2}'.format(proto, host, port)
+ self.client = http_client.HttpClient(base_url=self.url)
+
+ def get_targets(self):
+ _, resp = self.client.get("/api/v1/targets")
+ targets = json.loads(resp)
+ return targets["data"]["activeTargets"]
+
+ def get_query(self, query, timestamp=None):
+ params = {
+ "query": query
+ }
+
+ if timestamp is not None:
+ params.update({"time": timestamp})
+
+ _, resp = self.client.get("/api/v1/query", params=params)
+
+ query_result = json.loads(resp)
+ if query_result["status"] != "success":
+ raise Exception("Failed resp: {}".format(resp))
+
+ if query_result["data"]["resultType"] == "vector":
+ return query_result["data"]["result"]