blob: d358d15101b2404ca918f718f67e9e38ccba32b2 (
plain) (
tree)
|
|
# -*- python -*-
from plugins.snmp import SNMP
from plugins.snmp6 import SNMP6
from plugins.uptime import Uptime
from plugins.vmstat import VMStat
from common import *
class MyStat(Entry):
def __init__(self, *args, **kwargs):
self.keys_4 = SNMP().keys
self.keys_6 = SNMP6().keys
self.keys_vm = VMStat().keys
self.show_group = 0
self.show_value_4 = 0
self.show_value_6 = 0
self.show_value_vm = 0
Entry.__init__(self, *args, **kwargs)
def action(self, col, button, x, y):
if button == LEFT_BUTTON:
n = self.show_group + 1
if n < 4:
self.show_group = n
self.invalidate()
elif button == MIDDLE_BUTTON:
self.invalidate()
elif button == RIGHT_BUTTON:
n = self.show_group
if n > 0:
self.show_group = n - 1
self.invalidate()
elif button == SCROLL_UP:
if self.show_group == 0:
n = self.show_value_4
if n + 1 < len(self.keys_4):
self.show_value_4 = n + 1
self.invalidate()
elif self.show_group == 1:
n = self.show_value_6
if n + 1 < len(self.keys_6):
self.show_value_6 = n + 1
self.invalidate()
elif self.show_group == 2:
n = self.show_value_vm
if n + 1 < len(self.keys_vm):
self.show_value_vm = n + 1
self.invalidate()
elif self.show_group == 3:
pass
elif button == SCROLL_DOWN:
if self.show_group == 0:
n = self.show_value_4
if n > 0:
self.show_value_4 = n - 1
self.invalidate()
elif self.show_group == 1:
n = self.show_value_6
if n > 0:
self.show_value_6 = n - 1
self.invalidate()
elif self.show_group == 2:
n = self.show_value_vm
if n > 0:
self.show_value_vm = n - 1
self.invalidate()
elif self.show_group == 3:
pass
def function(self):
try:
if self.show_group == 0:
label = self.keys_4[self.show_value_4]
value = SNMP()[label]
elif self.show_group == 1:
label = self.keys_6[self.show_value_6]
value = SNMP6()[label]
elif self.show_group == 2:
label = self.keys_vm[self.show_value_vm]
value = VMStat()[label]
label = ''.join(w[:1].upper() + w[1:] for w in label.split('_'))
elif self.show_group == 3:
uptime = Uptime()
avg = uptime.uptime_seconds - uptime.average_idle_seconds
wrk = (avg) * 100 / uptime.uptime_seconds
up = '%id%i:%02i' % uptime.uptime[:3]
avg = '%id%i:%02i' % Uptime.split_time(avg)[:3]
return 'Uptime: %.0f%% %s / %s' % (wrk, avg, up)
return '%s: %i' % (label, value)
except Exception as e:
return str(e)
|