Add ping.py

This commit is contained in:
Stefan Ritter 2024-01-12 13:03:53 +01:00
commit f6ce25b678
1 changed files with 18 additions and 0 deletions

18
ping.py Normal file
View File

@ -0,0 +1,18 @@
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)