grafana-prometheus-ping/ping.py

18 lines
382 B
Python
Raw Permalink Normal View History

2024-01-12 13:03:53 +01:00
from pythonping import ping
from time import sleep
from prometheus_client import start_http_server, Gauge
def get_ms():
res = ping('8.8.8.8', size=40, count=1, timeout=10)
if res.rtt_avg_ms == 10000:
ms = -1
else:
ms = round(res.rtt_avg_ms)
return(ms)
t = Gauge('ping', 'Ping')
start_http_server(9101)
while True:
t.set(get_ms())
sleep(60)