diff --git a/NEWS b/NEWS index 5c02fed2..bd96ff53 100644 --- a/NEWS +++ b/NEWS @@ -3,8 +3,11 @@ Version 1.5.2 * Add sensors module (enable it with -e option) * Improve CPU stats (IO wait, Nice, IRQ) - * More stats in lower space (yes it is possible) + * More stats in lower space (yes it's possible) * Refactor processes list and count (lower CPU/MEM footprint) + * Add functions to the RCP method + * Completed unit test + * and fixes... Version 1.5.1 ============= diff --git a/glances/glances.py b/glances/glances.py index 25f5a278..a320fc02 100755 --- a/glances/glances.py +++ b/glances/glances.py @@ -209,9 +209,10 @@ class glancesLimits: # Exemple: # limits_list['STD'] = [50, 70, 90] - #_______________________________CAREFUL WARNING CRITICAL + #_______________________CAREFUL WARNING CRITICAL __limits_list = {'STD': [50, 70, 90], - 'LOAD': [0.7, 1.0, 5.0]} + 'LOAD': [0.7, 1.0, 5.0], + 'TEMP': [50, 70, 80]} def __init__(self, careful=50, warning=70, critical=90): self.__limits_list['STD'] = [careful, warning, critical] @@ -234,6 +235,15 @@ class glancesLimits: def getLOADCritical(self, core=1): return self.__limits_list['LOAD'][2] * core + def getTEMPCareful(self): + return self.__limits_list['TEMP'][0] + + def getTEMPWarning(self): + return self.__limits_list['TEMP'][1] + + def getTEMPCritical(self): + return self.__limits_list['TEMP'][2] + class glancesLogs: """ @@ -1290,6 +1300,28 @@ class glancesScreen: def __getProcessColor(self, current=0, max=100): return self.__getColor2(current, max) + def __getSensorsAlert(self, current=0): + # Alert for Sensors (temperature in degre) + # If current < CAREFUL then alert = OK + # If current > CAREFUL then alert = CAREFUL + # If current > WARNING then alert = WARNING + # If current > CRITICALthen alert = CRITICAL + + if current > limits.getTEMPCritical(): + return 'CRITICAL' + elif current > limits.getTEMPWarning(): + return 'WARNING' + elif current > limits.getTEMPCareful(): + return 'CAREFUL' + + return 'OK' + + def __getSensorsColor(self, current=0): + """ + Return color for Sensors temperature (non logged stats) + """ + return self.__colors_list2[self.__getSensorsAlert(current)] + def __catchKey(self): # Get key self.pressedkey = self.term_window.getch() @@ -1878,7 +1910,8 @@ class glancesScreen: sensors[i]['label'], 21) self.term_window.addnstr( self.sensors_y + 1 + i, self.sensors_x + 20, - format(sensors[i]['value'], '>3'), 3) + format(sensors[i]['value'], '>3'), 3, + self.__getSensorsColor(sensors[i]['value'])) ret = ret + 1 return ret return 0 diff --git a/glances/unitest.py b/glances/unitest.py index 23289c58..97ccdff4 100755 --- a/glances/unitest.py +++ b/glances/unitest.py @@ -37,44 +37,83 @@ class TestGlancesStat(unittest.TestCase): def test_Glances_getSystem(self): self.stats.update() system = self.stats.getSystem() - print("System info: %s" % system) + #~ print("System info: %s" % system) + self.assertTrue(type(system) == dict) self.assertTrue(len(system) > 1) def test_Glances_getCore(self): self.stats.update() core = self.stats.getCore() - print("CPU Core number: %s" % core) + #~ print("CPU Core number: %s" % core) + self.assertTrue(type(core) == int) self.assertEqual(core, multiprocessing.cpu_count()) def test_Glances_getCpu(self): self.stats.update() cpu = self.stats.getCpu() - print("CPU stat %s:" % cpu) + #~ print("CPU stat %s:" % cpu) + self.assertTrue(type(cpu) == dict) self.assertTrue(len(cpu) > 1) def test_Glances_getPerCpu(self): self.stats.update() percpu = self.stats.getPerCpu() - print("PerCPU stat %s:" % percpu) + #~ print("PerCPU stat %s:" % percpu) + self.assertTrue(type(percpu) == list) self.assertEqual(len(percpu), multiprocessing.cpu_count()) def test_Glances_getMem(self): self.stats.update() mem = self.stats.getMem() - print("Mem stat %s:" % mem) + #~ print("Mem stat %s:" % mem) + self.assertTrue(type(mem) == dict) self.assertTrue(len(mem) > 2) def test_Glances_getMemSwap(self): self.stats.update() memswap = self.stats.getMemSwap() - print("MemSwap stat %s:" % memswap) + #~ print("MemSwap stat %s:" % memswap) + self.assertTrue(type(memswap) == dict) self.assertTrue(len(memswap) > 2) def test_Glances_getNetwork(self): self.stats.update() net = self.stats.getNetwork() - print("Network stat %s:" % net) - self.assertTrue(len(net) > 1) + #~ print("Network stat %s:" % net) + self.assertTrue(type(net) == list) + self.assertTrue(len(net) > 0) + + def test_Glances_getDiskIO(self): + self.stats.update() + diskio = self.stats.getDiskIO() + #~ print("DiskIO stat %s:" % diskio) + self.assertTrue(type(diskio) == list) + self.assertTrue(len(diskio) > 0) + + def test_Glances_getFs(self): + self.stats.update() + fs = self.stats.getFs() + #~ print("File system stat %s:" % fs) + self.assertTrue(type(fs) == list) + self.assertTrue(len(fs) > 0) + + def test_Glances_getProcess(self): + self.stats.update() + pc = self.stats.getProcessCount() + pl = self.stats.getProcessList() + #~ print("Processes stat %s:" % pc) + #~ print("Processes list %s:" % pl) + self.assertTrue(type(pc) == dict) + self.assertTrue(len(pc) > 2) + self.assertTrue(type(pl) == list) + self.assertTrue(len(pl) > 0) + + def test_Glances_getSensors(self): + self.stats.update() + sensors = self.stats.getSensors() + #~ print("Optionnal sensors stat %s:" % sensors) + self.assertTrue(type(sensors) == list) + #~ self.assertTrue(len(sensors) > 0) if __name__ == '__main__':