-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
28 lines (25 loc) · 888 Bytes
/
main.py
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
import requests
import time
import os
import psutil
MONITORING_CHART_URL = os.environ.get("MONITORING_CHART_URL")
MONITORING_PERIOD = int(os.environ.get("MONITORING_PERIOD"))
NODE_PREFIX = os.environ.get("NODE_PREFIX")
print("HOST PREFIX", NODE_PREFIX)
print("MONITORING PERIOD", MONITORING_PERIOD)
print("MONITORING CHART URL", MONITORING_CHART_URL)
while True:
request = []
time.sleep(MONITORING_PERIOD)
cpus = psutil.cpu_percent(percpu=True)
for i, cpu_perc in enumerate(cpus):
request.append({
"key": "{}-cpu_{}".format(NODE_PREFIX, str(i)),
"value": cpu_perc
})
request.append({
"key": "{}-memory_u_s_e_d".format(NODE_PREFIX),
"value": psutil.virtual_memory().percent
})
print("trying on", MONITORING_CHART_URL + "/addPoints")
requests.post(MONITORING_CHART_URL + "/addPoints", json=request)