Adding router graph
This commit is contained in:
parent
ab8792f388
commit
5aae4bb524
24
netwatch.py
24
netwatch.py
|
@ -21,15 +21,20 @@ encoding = locale.getpreferredencoding()
|
|||
|
||||
# Variables
|
||||
internet_host = "8.8.8.8"
|
||||
router_host = "192.168.1.1"
|
||||
ping_frequency = 5
|
||||
|
||||
class Pinger:
|
||||
internet_log = []
|
||||
router_log = []
|
||||
|
||||
def run(self):
|
||||
internet_latency = self.ping(internet_host,self.internet_log)
|
||||
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
|
||||
GObject.timeout_add_seconds(self.timeout, self.run)
|
||||
|
||||
|
@ -101,6 +106,15 @@ class Pinger:
|
|||
return {'graph': graph, 'color': color, 'subjective': subjective, 'ping': float(ping)}
|
||||
|
||||
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
|
||||
self.stdscr = stdscr
|
||||
self.window_size = stdscr.getmaxyx() # returns an array [height,width]
|
||||
|
@ -110,18 +124,12 @@ class Pinger:
|
|||
# start the ping process
|
||||
self.run()
|
||||
|
||||
# Keep running until ctrl+c
|
||||
self.loop = GLib.MainLoop()
|
||||
self.loop.run()
|
||||
|
||||
|
||||
def main(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)
|
||||
|
||||
# Create runtime class
|
||||
# Initialize runtime class
|
||||
pinger = Pinger(stdscr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user