Commit f8f8ac0e authored by Mario Hock's avatar Mario Hock
Browse files

Curses GUI

added CPU util
parent f605f06c
__pycache__/
*.pyc
.kdev4/
*.kdev4
......@@ -3,10 +3,13 @@
import psutil
import time
import sys
import traceback
from collections import namedtuple
import helpers
import curses_display as ui
def get_time():
""" Unified/comparable clock access """
......@@ -127,7 +130,8 @@ def desplay_network_traffic(measurement, nics = None):
## XXX TESTING
def display(measurement):
nics = ("eth0", "wlan0", "lo")
#nics = ("eth0", "wlan0", "lo")
nics = ("eth0", "wlan0")
display_cpu(measurement)
desplay_network_traffic( measurement, nics )
......@@ -150,10 +154,33 @@ def displayX(measurement):
## XXX TESTING -- NOTE: takes unnecessary Readings!!
def test_loop():
for i in range(100):
display( measure(2.0) )
err = None
try:
ui.init()
ui.nics = ("eth0", "wlan0")
while ui.display( measure(1.0) ):
pass
except KeyboardInterrupt:
pass
except Exception as e:
err = e
exc_type, exc_value, exc_traceback = sys.exc_info()
finally:
ui.close()
## On error: Print error message *after* curses has quit.
if ( err ):
print( "Unexpected exception happened: '" + str(err) + "'" )
print
traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
print
print( "QUIT." )
## XXX TESTING
#display( measure() )
......
......@@ -60,23 +60,49 @@ def init():
def display(measurement):
global stdscr
## Press 'q' to quit.
pressedkey = stdscr.getch()
if pressedkey == ord('q'):
return False
## Header
stdscr.clear()
stdscr.border(0)
timenow = time.strftime("%H:%M:%S")
stdscr.addstr(1, 1, 'CPUnetLOG Time: {0} Interval: {1}s'.format(timenow, round(measurement.timespan, 1)), curses.A_BOLD)
stdscr.addstr(1, 1, 'CPUnetLOG Time: {0} Interval: {1}s'.format(timenow, round(measurement.timespan, 1)), curses.A_BOLD)
stdscr.refresh()
y = 3
## CPU ##
num=1
for cpu in measurement.cpu_times_percent:
stdscr.addstr(y, 1, 'CPU{0}'.format( num ), curses.color_pair(1))
stdscr.addstr(y, 20, 'util:', curses.color_pair(2))
stdscr.addstr(y, 26, '{0:.2%}'.format( (100-cpu.idle)/100.0 ), curses.color_pair(3))
stdscr.addstr(y, 50, 'user:', curses.color_pair(2))
stdscr.addstr(y, 56, '{0:.2%}'.format( cpu.user/100.0 ), curses.color_pair(3))
stdscr.addstr(y, 66, 'system:', curses.color_pair(2))
stdscr.addstr(y, 74, '{0:.2%}'.format( cpu.system/100.0 ), curses.color_pair(3))
num += 1
y += 1
## Network ##
y += 1
stdscr.hline(y, 1, "-", 85)
y += 1
# display all nics (if not set otherwise)
if nics:
active_nics = nics
else:
active_nics = measurement.net_io.keys()
y=3
sum_sending = 0
sum_receiving = 0
......@@ -101,9 +127,11 @@ def display(measurement):
y+=1
stdscr.addstr(y, 1, 'Total:', curses.color_pair(4))
stdscr.addstr(y, 20, 'Sent:', curses.color_pair(2))
stdscr.addstr(y, 26, '{0} {1}/s'.format(_format_net_speed(sum_sending), unit), curses.color_pair(3) | curses.A_STANDOUT)
#stdscr.addstr(y, 26, '{0} {1}/s'.format(_format_net_speed(sum_sending), unit), curses.color_pair(3) | curses.A_STANDOUT)
stdscr.addstr(y, 26, '{0} {1}/s'.format(_format_net_speed(sum_sending), unit), curses.color_pair(3))
stdscr.addstr(y, 50, 'Received:', curses.color_pair(2))
stdscr.addstr(y, 60, '{0} {1}/s'.format(_format_net_speed(sum_receiving),unit), curses.color_pair(3) | curses.A_STANDOUT)
#stdscr.addstr(y, 60, '{0} {1}/s'.format(_format_net_speed(sum_receiving),unit), curses.color_pair(3) | curses.A_STANDOUT)
stdscr.addstr(y, 60, '{0} {1}/s'.format(_format_net_speed(sum_receiving),unit), curses.color_pair(3))
stdscr.refresh()
......
......@@ -81,4 +81,3 @@ def calculate_cpu_times_percent(cpu_times_older, cpu_times_younger, percpu=False
for t1, t2 in zip(cpu_times_older, cpu_times_younger):
ret.append(calculate(t1, t2))
return ret
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment