summaryrefslogtreecommitdiffstats
path: root/clover/monitoring/validate.py
diff options
context:
space:
mode:
authorQiLiang <liangqi1@huawei.com>2018-03-15 12:20:59 +0800
committerQiLiang <liangqi1@huawei.com>2018-03-29 17:02:36 +0800
commit9423f2e5911a9933744e827c9b09e2e9025b4aee (patch)
treeb7f503dc6eb2b64af131de7d3291ccd65237f4bd /clover/monitoring/validate.py
parent9f3d87d798cf04c243e82d284a7dc4f7b3ec5c1a (diff)
Initial commit for monitoring by prometheus
- install prometheus - validate the installation - add prometheus query function - TODO: test collecting telemetry data from istio JIRA: CLOVER-7 Change-Id: I983be2db78c8c5c20c0acee9ae81e891884e07fb Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'clover/monitoring/validate.py')
-rw-r--r--clover/monitoring/validate.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/clover/monitoring/validate.py b/clover/monitoring/validate.py
new file mode 100644
index 0000000..fafe5df
--- /dev/null
+++ b/clover/monitoring/validate.py
@@ -0,0 +1,70 @@
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+from monitoring import Monitoring
+from kubernetes import client, config
+
+PROMETHEUS_URL = "http://127.0.0.1:9090"
+PROMETHEUS_DEPLOYMENT = "prometheus"
+PROMETHEUS_LABELS = "app=prometheus"
+ISTIO_NAMESPACE = "istio-system"
+
+
+def validateDeploy():
+ config.load_kube_config()
+ appsv1 = client.AppsV1Api()
+ corev1 = client.CoreV1Api()
+ find_flag = False
+ prom_pod_name = None
+
+ # check prometheus deploytment
+ ret = appsv1.list_deployment_for_all_namespaces(watch=False)
+ for i in ret.items:
+ if PROMETHEUS_DEPLOYMENT == i.metadata.name and \
+ ISTIO_NAMESPACE == i.metadata.namespace:
+ find_flag = True
+ break
+ if find_flag == False:
+ print("ERROR: Deployment: {} doesn't present in {} namespace".format(
+ PROMETHEUS_DEPLOYMENT, ISTIO_NAMESPACE))
+ return False
+
+ # find prometheus pod by label selector
+ ret = corev1.list_namespaced_pod(ISTIO_NAMESPACE, label_selector=PROMETHEUS_LABELS)
+ for i in ret.items:
+ prom_pod_name = i.metadata.name
+ if prom_pod_name == None:
+ print("ERROR: prometheus pod not found")
+ return False
+
+ # check prometheus pod status
+ ret = corev1.read_namespaced_pod_status(prom_pod_name, ISTIO_NAMESPACE)
+ if ret.status.phase != "Running":
+ print("ERROR: prometheus pod %s is under %s state" % (prom_pod_name, ret.status.phase))
+ return False
+
+ return True
+
+
+def validateService():
+ m = Monitoring(PROMETHEUS_URL)
+
+ return m.is_targets_healthy()
+
+
+def main():
+ if validateDeploy() and validateService():
+ print"Prometheus monitoring validation has passed"
+ return True
+ else:
+ print"ERROR: Prometheus monitoring validation has failed"
+ return False
+
+
+if __name__ == '__main__':
+ main()
+