Adding router graph

This commit is contained in:
Will Bradley 2015-03-27 21:38:04 +00:00
parent ab8792f388
commit 5aae4bb524

View File

@ -21,15 +21,20 @@ encoding = locale.getpreferredencoding()
# Variables # Variables
internet_host = "8.8.8.8" internet_host = "8.8.8.8"
router_host = "192.168.1.1"
ping_frequency = 5 ping_frequency = 5
class Pinger: class Pinger:
internet_log = [] internet_log = []
router_log = []
def run(self): def run(self):
internet_latency = self.ping(internet_host,self.internet_log) internet_latency = self.ping(internet_host,self.internet_log)
self.draw("Internet:",self.internet_log,internet_latency,0) self.draw("Internet:",self.internet_log,internet_latency,0)
router_latency = self.ping(router_host,self.router_log)
self.draw("Router:",self.router_log,router_latency,2)
# Schedule next run # Schedule next run
GObject.timeout_add_seconds(self.timeout, self.run) GObject.timeout_add_seconds(self.timeout, self.run)
@ -101,27 +106,30 @@ class Pinger:
return {'graph': graph, 'color': color, 'subjective': subjective, 'ping': float(ping)} return {'graph': graph, 'color': color, 'subjective': subjective, 'ping': float(ping)}
def __init__(self, stdscr): def __init__(self, stdscr):
# Initialize color pairs
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK)
# Hide cursor
curses.curs_set(0)
# initialize screen and parameters # initialize screen and parameters
self.stdscr = stdscr self.stdscr = stdscr
self.window_size = stdscr.getmaxyx() # returns an array [height,width] self.window_size = stdscr.getmaxyx() # returns an array [height,width]
self.ping_log_max_size = self.window_size[1] # max width self.ping_log_max_size = self.window_size[1] # max width
self.timeout = ping_frequency self.timeout = ping_frequency
# start the ping process # start the ping process
self.run() self.run()
# Keep running until ctrl+c
self.loop = GLib.MainLoop() self.loop = GLib.MainLoop()
self.loop.run() self.loop.run()
def main(stdscr): def main(stdscr):
# Initialize runtime class
# Initialize color pairs
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLACK)
# Create runtime class
pinger = Pinger(stdscr) pinger = Pinger(stdscr)
if __name__ == '__main__': if __name__ == '__main__':