forked from prometheus/client_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
36 lines (27 loc) · 977 Bytes
/
Copy pathexample.py
File metadata and controls
36 lines (27 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from prometheus_client import start_http_server, Summary
import random
import time
import glob
import pandas as pd
from pandas.errors import EmptyDataError
from prometheus_client import Counter
COUNTER = Counter('tables', 'results', ['name', 'status', 'info'])
def show_results(csv_dir: str):
data = []
for filename in glob.glob(f"{csv_dir}/*.csv"):
try:
df = pd.read_csv(filename, names=["table", "status", "info"], index_col=False)
data.append(df)
except EmptyDataError as ex:
print(filename)
df = pd.concat(data, axis=0, ignore_index=True)
for idx, row in df.iterrows():
COUNTER.labels(row["table"], row["status"], row["info"]).inc()
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
show_results(csv_dir="data")
# sleep 5 minutes = 5 * 60 seconds
time.sleep(5*60)