upload pm-support
[ta/cloudtaf.git] / testcases / pm-support / misc / custom-metrics_test.py
diff --git a/testcases/pm-support/misc/custom-metrics_test.py b/testcases/pm-support/misc/custom-metrics_test.py
new file mode 100644 (file)
index 0000000..ce3132f
--- /dev/null
@@ -0,0 +1,19 @@
+from prometheus_client import start_http_server, Histogram
+import random
+import time
+
+function_exec = Histogram('function_exec_time',
+                          'Time spent processing a function',
+                          ['func_name'])
+
+def func():
+    if (random.random() < 0.02):
+        time.sleep(2)
+        return
+time.sleep(0.2)
+start_http_server(9100)
+
+while True:
+    start_time = time.time()
+    func()
+    function_exec.labels(func_name="func").observe(time.time() - start_time)