Add ping.py
This commit is contained in:
commit
f6ce25b678
|
@ -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)
|
Loading…
Reference in New Issue