X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fcloudtaf.git;a=blobdiff_plain;f=testcases%2Fpm-support%2Fmisc%2Fcustom-metrics_test.py;fp=testcases%2Fpm-support%2Fmisc%2Fcustom-metrics_test.py;h=ce3132f341c50f67246a79d410714565cef1e104;hp=0000000000000000000000000000000000000000;hb=fab50fee1cc75156a4113a20dcbb13e41ca2a7c4;hpb=15c350f3e5491c681ead4de5b049693d50d53fc7 diff --git a/testcases/pm-support/misc/custom-metrics_test.py b/testcases/pm-support/misc/custom-metrics_test.py new file mode 100644 index 0000000..ce3132f --- /dev/null +++ b/testcases/pm-support/misc/custom-metrics_test.py @@ -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)