Add NET+DISKIO+FS to the sidebar

This commit is contained in:
Nicolas Hennion 2014-02-15 12:16:09 +01:00
parent 5c4d3eca4d
commit d038e619f4
7 changed files with 196 additions and 76 deletions

View File

@ -3,31 +3,12 @@
careful=50
warning=70
critical=90
# Limit values for CPU user in %
[percpu]
# Default values if not defined: 50/70/90
user_careful=50
user_warning=70
user_critical=90
# Limit values for CPU system in %
# Default values if not defined: 50/70/90
system_careful=50
system_warning=70
system_critical=90
# Limit values for CPU iowait in %
# Default values if not defined: 40/60/80
# Not easy to tweak...
# Source: http://blog.scoutapp.com/articles/2011/02/10/understanding-disk-i-o-when-should-you-be-worried
# http://blog.logicmonitor.com/2011/04/20/troubleshooting-server-performance-and-application-monitoring-a-real-example/
# http://blog.developpeur-neurasthenique.fr/auto-hebergement-iowait-ma-tuer-1-2-vmstat-mpstat-atop-pidstat.html (FR)
iowait_careful=40
iowait_warning=60
iowait_critical=80
# Limit values for CPU steal in %
# Default values if not defined: 10/15/20
# Source: http://blog.scoutapp.com/articles/2013/07/25/understanding-cpu-steal-time-when-should-you-be-worried
steal_careful=10
steal_warning=15
steal_critical=20
careful=50
warning=70
critical=90
[load]
# Value * number of cores
@ -56,6 +37,17 @@ critical=90
# Define the list of hidden network interfaces (comma separeted)
#hide=lo
[diskio]
# Define the list of hidden disks (comma separeted)
#hide=sda2,sda5
[fs]
# Default limits for free filesytem space in %
# Default values if not defined: 50/70/90
careful=50
warning=70
critical=90
[temperature]
# Temperatures in °C for sensors
# Default values if not defined: 60/70/80
@ -70,13 +62,6 @@ careful=45
warning=52
critical=60
[filesystem]
# Default limits for free filesytem space in %
# Default values if not defined: 50/70/90
careful=50
warning=70
critical=90
[process]
# Limit values for CPU per process in %
# Default values if not defined: 50/70/90
@ -89,10 +74,6 @@ mem_careful=50
mem_warning=70
mem_critical=90
[iodisk]
# Define the list of hidden disks (comma separeted)
#hide=sda2,sda5
[monitor]
# Define the list of processes to monitor
# *** This section is optional ***

View File

@ -170,4 +170,3 @@ class Plugin(GlancesPlugin):
# Return the message with decoration
return ret

View File

@ -33,6 +33,15 @@ class Plugin(GlancesPlugin):
def __init__(self):
GlancesPlugin.__init__(self)
# 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 = 0
# Enter -1 to diplay bottom
self.line_curse = 3
def update(self):
"""
@ -79,9 +88,34 @@ class Plugin(GlancesPlugin):
self.stats = self.diskio
def get_stats(self):
# Return the stats object for the RPC API
# !!! Sort it by disk name (why do it here ? Better in client side ?)
self.stats = sorted(self.stats, key=lambda network: network['disk_name'])
return GlancesPlugin.get_stats(self)
def msg_curse(self, args=None):
"""
Return the dict to display in the curse interface
"""
# Init the return message
ret = []
# Build the string message
# Header
msg = "{0:8}".format(_("DISK I/O"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = " {0:>6}".format(_("In/s"))
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(_("Out/s"))
ret.append(self.curse_add_line(msg))
# Disk list (sorted by name)
for i in sorted(self.stats, key=lambda diskio: diskio['disk_name']):
# !!! TODO: manage the hide tag
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(i['disk_name'])
ret.append(self.curse_add_line(msg))
rxps = self.auto_unit(int(i['write_bytes'] // i['time_since_update']))
txps = self.auto_unit(int(i['read_bytes'] // i['time_since_update']))
msg = " {0:>6}".format(rxps)
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(txps)
ret.append(self.curse_add_line(msg))
return ret

View File

@ -22,38 +22,10 @@ from psutil import disk_partitions, disk_usage
from glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
"""
Glances's File System (fs) Plugin
stats is a list
"""
def __init__(self):
GlancesPlugin.__init__(self)
# Init the FS class
self.glancesgrabfs = glancesGrabFs()
def update(self):
"""
Update stats
"""
self.stats = self.glancesgrabfs.get()
def get_stats(self):
# Return the stats object for the RPC API
# !!! Sort it by mount name (why do it here ? Better in client side ?)
self.stats = sorted(self.stats, key=lambda network: network['mnt_point'])
return GlancesPlugin.get_stats(self)
class glancesGrabFs:
"""
Get FS stats
Did not exist in PSUtil, so had to create it from scratch
"""
def __init__(self):
@ -102,7 +74,78 @@ class glancesGrabFs:
fs_current['used'] = fs_usage.used
fs_current['avail'] = fs_usage.free
self.fs_list.append(fs_current)
def get(self):
self.__update__()
return self.fs_list
class Plugin(GlancesPlugin):
"""
Glances's File System (fs) Plugin
stats is a list
"""
def __init__(self):
GlancesPlugin.__init__(self)
# Init the FS class
self.glancesgrabfs = glancesGrabFs()
# 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 = 0
# Enter -1 to diplay bottom
self.line_curse = 4
def update(self):
"""
Update stats
"""
self.stats = self.glancesgrabfs.get()
def msg_curse(self, args=None):
"""
Return the dict to display in the curse interface
"""
# Init the return message
ret = []
# Build the string message
# Header
msg = "{0:8}".format(_("MOUNT"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = " {0:>6}".format(_("Used"))
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(_("Total"))
ret.append(self.curse_add_line(msg))
# Disk list (sorted by name)
for i in sorted(self.stats, key=lambda fs: fs['mnt_point']):
# New line
ret.append(self.curse_new_line())
# Cut mount point name if it is too long
if (len(i['mnt_point']) > 8):
mnt_point = '_' + i['mnt_point'][-7:]
else:
mnt_point = i['mnt_point']
msg = "{0:8}".format(mnt_point)
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(self.auto_unit(i['used']))
ret.append(self.curse_add_line(msg,
self.get_alert(i['used'],
max=i['size'])))
msg = " {0:>6}".format(self.auto_unit(i['size']))
ret.append(self.curse_add_line(msg))
return ret

View File

@ -118,9 +118,11 @@ class Plugin(GlancesPlugin):
# Build the string message
# Header
msg = "{0:6}".format(_("NETWORK"))
msg = "{0:8}".format(_("NETWORK"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = "{0:>7} {1:>7}".format(_("Rx/s"), _("Tx/s"))
msg = " {0:>6}".format(_("Rx/s"))
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(_("Tx/s"))
ret.append(self.curse_add_line(msg))
# Interface list (sorted by name)
for i in sorted(self.stats, key=lambda network: network['interface_name']):
@ -137,9 +139,11 @@ class Plugin(GlancesPlugin):
# New line
ret.append(self.curse_new_line())
msg = "{0:7}".format(ifname)
msg = "{0:8}".format(ifname)
ret.append(self.curse_add_line(msg))
msg = "{0:>7} {1:>7}".format(rxps, txps)
msg = " {0:>6}".format(rxps)
ret.append(self.curse_add_line(msg))
msg = " {0:>6}".format(txps)
ret.append(self.curse_add_line(msg))
return ret

View File

@ -35,6 +35,15 @@ class Plugin(GlancesPlugin):
def __init__(self):
GlancesPlugin.__init__(self)
# 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 = 0
# Enter -1 to diplay bottom
self.line_curse = 1
def update(self):
"""
@ -105,3 +114,54 @@ class Plugin(GlancesPlugin):
self.percputime_total_old = self.percputime_total_new
except Exception, err:
self.stats = []
def msg_curse(self, args=None):
"""
Return the dict to display in the curse interface
"""
# Init the return message
ret = []
# Build the string message
# Header
msg = "{0:8}".format(_("PER CPU"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Total CPU usage
for cpu in self.stats:
msg = " {0}".format(format((100 - cpu['idle']) / 100, '>6.1%'))
ret.append(self.curse_add_line(msg))
# User CPU
if ('user' in self.stats[0]):
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("user:"))
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'])))
# System CPU
if ('user' in self.stats[0]):
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("system:"))
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'])))
# IoWait CPU
if ('user' in self.stats[0]):
# New line
ret.append(self.curse_new_line())
msg = "{0:8}".format(_("iowait:"))
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'])))
# Return the message with decoration
return ret

View File

@ -150,7 +150,6 @@ class GlancesPlugin(object):
def get_limit_warning(self):
return self.limits[self.plugin_name + '_' + 'warning']
def get_limit_careful(self):
return self.limits[self.plugin_name + '_' + 'careful']