diff options
author | Nicolas Hennion <nicolas@nicolargo.com> | 2014-02-26 21:31:36 +0100 |
---|---|---|
committer | Nicolas Hennion <nicolas@nicolargo.com> | 2014-02-26 21:31:36 +0100 |
commit | 43c9c805be8c01c51fd1cc33b31229478942e604 (patch) | |
tree | 4b2c7e58b7290482234d0fa44a3d2b63da00cb5b | |
parent | 471b04fe85fb4f8fa41f21449fe7d503399aba2f (diff) |
Alert is working in v2
-rw-r--r-- | conf/glances-monitor.conf | 27 | ||||
-rw-r--r-- | conf/glances.conf | 27 | ||||
-rw-r--r-- | glances/core/glances_logs.py | 7 | ||||
-rw-r--r-- | glances/plugins/glances_alert.py | 48 | ||||
-rw-r--r-- | glances/plugins/glances_cpu.py | 12 | ||||
-rw-r--r-- | glances/plugins/glances_percpu.py | 6 | ||||
-rw-r--r-- | glances/plugins/glances_processlist.py | 6 |
7 files changed, 107 insertions, 26 deletions
diff --git a/conf/glances-monitor.conf b/conf/glances-monitor.conf index 377a5a13..9521ee45 100644 --- a/conf/glances-monitor.conf +++ b/conf/glances-monitor.conf @@ -1,14 +1,29 @@ [cpu] # Default values if not defined: 50/70/90 -careful=50 -warning=70 -critical=90 +user_careful=50 +user_warning=70 +user_critical=90 +iowait_careful=50 +iowait_warning=70 +iowait_critical=90 +system_careful=50 +system_warning=70 +system_critical=90 +steal_careful=50 +steal_warning=70 +steal_critical=90 [percpu] # Default values if not defined: 50/70/90 -careful=50 -warning=70 -critical=90 +user_careful=50 +user_warning=70 +user_critical=90 +iowait_careful=50 +iowait_warning=70 +iowait_critical=90 +system_careful=50 +system_warning=70 +system_critical=90 [load] # Value * number of cores diff --git a/conf/glances.conf b/conf/glances.conf index 23551d58..ab306d3d 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -1,14 +1,29 @@ [cpu] # Default values if not defined: 50/70/90 -careful=50 -warning=70 -critical=90 +user_careful=50 +user_warning=70 +user_critical=90 +iowait_careful=50 +iowait_warning=70 +iowait_critical=90 +system_careful=50 +system_warning=70 +system_critical=90 +steal_careful=50 +steal_warning=70 +steal_critical=90 [percpu] # Default values if not defined: 50/70/90 -careful=50 -warning=70 -critical=90 +user_careful=50 +user_warning=70 +user_critical=90 +iowait_careful=50 +iowait_warning=70 +iowait_critical=90 +system_careful=50 +system_warning=70 +system_critical=90 [load] # Value * number of cores diff --git a/glances/core/glances_logs.py b/glances/core/glances_logs.py index 60a8cec3..f594d967 100644 --- a/glances/core/glances_logs.py +++ b/glances/core/glances_logs.py @@ -71,9 +71,11 @@ class glancesLogs: An item exist in the list if: * end is < 0 * item_type is matching + Return the item position if exist + -1 if the item is not found """ for i in range(self.len()): - if self.logs_list[i][1] < 0 and self.logs_list[i][3] == item_type: + if ((self.logs_list[i][1] < 0) and (self.logs_list[i][3] == item_type)): return i return -1 @@ -117,8 +119,7 @@ class glancesLogs: item = [] # START DATE item.append(time.mktime(datetime.now().timetuple())) - # END DATE - item.append(-1) + item.append(-1) # END DATE item.append(item_state) # STATE: WARNING|CRITICAL item.append(item_type) # TYPE: CPU, LOAD, MEM... item.append(item_value) # MAX diff --git a/glances/plugins/glances_alert.py b/glances/plugins/glances_alert.py index e6c37986..e6bac439 100644 --- a/glances/plugins/glances_alert.py +++ b/glances/plugins/glances_alert.py @@ -18,6 +18,9 @@ # You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# Import system lib
+from datetime import datetime, timedelta
+
# Import Glances lib
from glances_plugin import GlancesPlugin
from glances.core.glances_globals import glances_logs
@@ -62,10 +65,51 @@ class Plugin(GlancesPlugin): # Build the string message
# Header
if (self.stats == []):
- msg = "{0:8}".format(_("No alert detected"))
+ msg = "{0}".format(_("No warning or critical alert detected"))
ret.append(self.curse_add_line(msg, "TITLE"))
else:
- msg = "{0:8}".format(_("ALERT"))
+ # Header
+ msg = "{0}".format(_("Warning or critical alerts"))
+ ret.append(self.curse_add_line(msg, "TITLE"))
+ logs_len = glances_logs.len()
+ if (logs_len > 1):
+ msg = " {0}".format(_("(lasts %s entries)") % logs_len)
+ else:
+ msg = " {0}".format(_("(one entry)"))
ret.append(self.curse_add_line(msg, "TITLE"))
+ # Loop over alerts
+ for alert in glances_logs.get():
+ # New line
+ ret.append(self.curse_new_line())
+ # Start
+ msg = "{0}".format(datetime.fromtimestamp(alert[0]))
+ ret.append(self.curse_add_line(msg))
+ # Duration
+ if (alert[1] > 0):
+ # If finished display duration
+ msg = " ({0})".format(datetime.fromtimestamp(alert[1]) - datetime.fromtimestamp(alert[0]))
+ else:
+ msg = _(" (ongoing)")
+ ret.append(self.curse_add_line(msg))
+ ret.append(self.curse_add_line(" - "))
+ # Infos
+ if (alert[1] > 0):
+ # If finished do not display status
+ msg = "{0} {1} {2}".format(alert[2], _("on"), alert[3])
+ ret.append(self.curse_add_line(msg))
+ else:
+ msg = "{0}".format(alert[3])
+ ret.append(self.curse_add_line(msg, decoration=alert[2]))
+ # Min / Mean / Max
+ msg = " ({0:2}/{1:2}/{2:2})".format(alert[6], alert[5], alert[4])
+ ret.append(self.curse_add_line(msg))
+
+ # else:
+ # msg = " {0}".format(_("Running..."))
+ # ret.append(self.curse_add_line(msg))
+
+ # !!! Debug only
+ # msg = " | {0}".format(alert)
+ # ret.append(self.curse_add_line(msg))
return ret
diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 72eedaff..adcc8ee5 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -146,7 +146,8 @@ class Plugin(GlancesPlugin): msg = " {0:8}".format(_("steal:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = "{0}".format(format(self.stats['steal'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert(self.stats['steal']), optional=True))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert(self.stats['steal'], header="steal"), optional=True))
# New line
ret.append(self.curse_new_line())
# User CPU
@@ -154,13 +155,15 @@ class Plugin(GlancesPlugin): msg = "{0:8}".format(_("user:"))
ret.append(self.curse_add_line(msg))
msg = "{0}".format(format(self.stats['user'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['user'])))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert_log(self.stats['user'], header="user")))
# IOWait CPU
if ('iowait' in self.stats):
msg = " {0:8}".format(_("iowait:"))
ret.append(self.curse_add_line(msg))
msg = "{0}".format(format(self.stats['iowait'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['iowait']), optional=True))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert_log(self.stats['iowait'], header="iowait"), optional=True))
# New line
ret.append(self.curse_new_line())
# System CPU
@@ -168,7 +171,8 @@ class Plugin(GlancesPlugin): msg = "{0:8}".format(_("system:"))
ret.append(self.curse_add_line(msg))
msg = "{0}".format(format(self.stats['system'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['system'])))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert_log(self.stats['system'], header="system")))
# IRQ CPU
if ('irq' in self.stats):
msg = " {0:7} {1}".format(
diff --git a/glances/plugins/glances_percpu.py b/glances/plugins/glances_percpu.py index 10e7a29c..c517b4c2 100644 --- a/glances/plugins/glances_percpu.py +++ b/glances/plugins/glances_percpu.py @@ -141,7 +141,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0}".format(format(cpu['user'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert(cpu['user'])))
+ ret.append(self.curse_add_line(msg, self.get_alert(cpu['user'], header="user")))
# System CPU
if ('user' in self.stats[0]):
@@ -151,7 +151,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0}".format(format(cpu['system'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert(cpu['system'])))
+ ret.append(self.curse_add_line(msg, self.get_alert(cpu['system'], header="system")))
# IoWait CPU
if ('user' in self.stats[0]):
@@ -161,7 +161,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg))
for cpu in self.stats:
msg = " {0}".format(format(cpu['iowait'] / 100, '>6.1%'))
- ret.append(self.curse_add_line(msg, self.get_alert(cpu['iowait'])))
+ ret.append(self.curse_add_line(msg, self.get_alert(cpu['iowait'], header="iowait")))
# Return the message with decoration
return ret
diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index cb371b1d..b66417e0 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -103,10 +103,12 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg))
# CPU
msg = "{0:>6}".format(format(p['cpu_percent'], '>5.1f'))
- ret.append(self.curse_add_line(msg, self.get_alert(p['cpu_percent'], header="cpu")))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert(p['cpu_percent'], header="cpu")))
# MEM
msg = "{0:>6}".format(format(p['memory_percent'], '>5.1f'))
- ret.append(self.curse_add_line(msg, self.get_alert(p['memory_percent'], header="mem")))
+ ret.append(self.curse_add_line(msg,
+ self.get_alert(p['memory_percent'], header="mem")))
# VMS
msg = "{0:>6}".format(self.auto_unit(p['memory_info'][1], low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
|