Last active
August 29, 2015 14:06
-
-
Save cscorley/a26d1771b7cbf46d9431 to your computer and use it in GitHub Desktop.
internet uptime script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sqlite3 | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
from dateutil.parser import parse | |
conn = sqlite3.connect('iup.db') | |
c = conn.cursor() | |
c.execute("create table if not exists log (time text primary key, status integer)") | |
with open('iup.log') as log: | |
for line in log: | |
time, status = line.split(',') | |
status = int(status) | |
try: | |
c.execute("insert into log values (?,?)", (time, status)) | |
except sqlite3.IntegrityError: | |
pass | |
conn.commit() | |
c.execute("select * from log") | |
rows = c.fetchall() | |
dates = [parse(r[0]) for r in rows] | |
status = [r[1] == 0 for r in rows] | |
y2 = [0] * len(status) | |
y3 = [1] * len(status) | |
#plt.ylim([-0.1, 1.1]) | |
p, = plt.plot_date(x=dates, y=status, xdate=True, ydate=False, fmt='r', | |
label="Disconnected", antialiased=False) | |
plt.fill_between(dates, status, y2, color='g') | |
plt.fill_between(dates, status, y3, color='r') | |
plt.gca().xaxis.set_major_formatter( mdates.DateFormatter('%d.%H') ) | |
l1 = plt.legend(handles=[p]) | |
plt.gca().add_artist(l1) | |
plt.savefig('downtime.png', format='png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while true; do | |
sleep 60 | |
ping -c 1 google.com &> /dev/null | |
echo $(date "+%Y-%m-%d %H:%M:%S"),$? >> /jffs/iup.log | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment