upload pm-support
[ta/cloudtaf.git] / testcases / pm-support / misc / custom-metrics_test.py
1 from prometheus_client import start_http_server, Histogram
2 import random
3 import time
4
5 function_exec = Histogram('function_exec_time',
6                           'Time spent processing a function',
7                           ['func_name'])
8
9 def func():
10     if (random.random() < 0.02):
11         time.sleep(2)
12         return
13 time.sleep(0.2)
14 start_http_server(9100)
15
16 while True:
17     start_time = time.time()
18     func()
19     function_exec.labels(func_name="func").observe(time.time() - start_time)