diff options
Diffstat (limited to 'glances/plugins/glances_alert.py')
-rw-r--r-- | glances/plugins/glances_alert.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/glances/plugins/glances_alert.py b/glances/plugins/glances_alert.py index a334398c..25eff22a 100644 --- a/glances/plugins/glances_alert.py +++ b/glances/plugins/glances_alert.py @@ -20,6 +20,7 @@ """Alert plugin.""" # Import system lib +import types from datetime import datetime # Import Glances libs @@ -40,12 +41,9 @@ class Plugin(GlancesPlugin): # We want to display the stat in the curse interface self.display_curse = True + # Set the message position - # It is NOT the curse position but the Glances column/line - # Enter -1 to right align - self.column_curse = 1 - # Enter -1 to diplay bottom - self.line_curse = -1 + self.set_align('bottom') # Init the stats self.reset() @@ -107,7 +105,7 @@ class Plugin(GlancesPlugin): msg = str(alert[3]) ret.append(self.curse_add_line(msg, decoration=alert[2])) # Min / Mean / Max - if alert[6] == alert[4]: + if self.approx_equal(alert[6], alert[4], tolerance=0.1): msg = ' ({0:.1f})'.format(alert[5]) else: msg = _(" (Min:{0:.1f} Mean:{1:.1f} Max:{2:.1f})").format(alert[6], alert[5], alert[4]) @@ -122,3 +120,12 @@ class Plugin(GlancesPlugin): # ret.append(self.curse_add_line(msg)) return ret + + def approx_equal(self, a, b, tolerance=0.0): + """ + Compare a with b using the tolerance (if numerical) + """ + if str(int(a)).isdigit() and str(int(b)).isdigit(): + return abs(a-b) <= max(abs(a), abs(b)) * tolerance + else: + return a == b |