提交 d947d6e0 编写于 作者: N Nicolas Hennion

Process display, first draft

上级 d038e619
......@@ -36,6 +36,10 @@ class Plugin(GlancesPlugin):
# Init the sensor class
self.glancesgrabhddtemp = glancesGrabHDDTemp()
# We do not want to display the stat in a dedicated area
# The HDD temp is displayed within the sensors plugin
self.display_curse = False
def update(self):
"""
......@@ -45,13 +49,6 @@ class Plugin(GlancesPlugin):
self.stats = self.glancesgrabhddtemp.get()
def get_stats(self):
# Return the stats object for the RPC API
# !!! Sort it by label name (why do it here ? Better in client side ?)
self.stats = sorted(self.stats, key=lambda sensors: sensors['label'])
return GlancesPlugin.get_stats(self)
class glancesGrabHDDTemp:
"""
Get hddtemp stats using a socket connection
......
......@@ -40,7 +40,7 @@ class Plugin(GlancesPlugin):
# Set the message position
# It is NOT the curse position but the Glances column/line
# Enter -1 to right align
self.column_curse = -1
self.column_curse = 0
# Enter -1 to diplay bottom
self.line_curse = -1
......
......@@ -21,6 +21,7 @@
from glances_plugin import GlancesPlugin
from _processes import processes
class Plugin(GlancesPlugin):
"""
Glances's processes Plugin
......@@ -33,6 +34,15 @@ class Plugin(GlancesPlugin):
# Nothing else to do...
# 'processes' is already init in the _processes.py script
# 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 = 2
def update(self):
......@@ -40,6 +50,52 @@ class Plugin(GlancesPlugin):
Update processes stats
"""
# !!! Update is call twisse (one for processcount and one for processlist)
# Here, update is call for processcount AND processlist
processes.update()
self.stats = processes.getcount()
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} ".format(_("TASKS"))
ret.append(self.curse_add_line(msg, "TITLE"))
# Compute processes
other = self.stats['total']
msg = "{0}".format(str(self.stats['total']))
ret.append(self.curse_add_line(msg))
if ('thread' in self.stats):
msg = " ({0} {1}),".format(str(self.stats['thread']), _("thr"))
ret.append(self.curse_add_line(msg))
if ('running' in self.stats):
other -= self.stats['running']
msg = " {0} {1},".format(str(self.stats['running']), _("run"))
ret.append(self.curse_add_line(msg))
if ('sleeping' in self.stats):
other -= self.stats['sleeping']
msg = " {0} {1},".format(str(self.stats['sleeping']), _("slp"))
ret.append(self.curse_add_line(msg))
msg = " {0} {1} ".format(str(other), _("oth"))
ret.append(self.curse_add_line(msg))
# Display sort information
if (args.process_sorted_by == 'auto'):
msg = "{0}".format(_("sorted automatically"))
else:
msg = "{0}".format(_("sorted by ") + args.process_sorted_by)
ret.append(self.curse_add_line(msg, 'UNDERLINE'))
# Return the message with decoration
return ret
......@@ -18,6 +18,8 @@
# 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/>.
from datetime import timedelta
from glances_plugin import GlancesPlugin
from _processes import processes
......@@ -41,7 +43,115 @@ class Plugin(GlancesPlugin):
Update processes stats
"""
# !!! Update is call twisse (one for processcount and one for processlist)
processes.update()
# Note: Update is done in the processcount plugin
self.stats = processes.getlist()
# 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 = 3
def msg_curse(self, args=None):
"""
Return the dict to display in the curse interface
"""
# Init the return message
ret = []
# Header
msg="{0:15}".format(_(""))
ret.append(self.curse_add_line(msg))
msg="{0:>6}".format(_("CPU%"))
ret.append(self.curse_add_line(msg))
msg="{0:>6}".format(_("MEM%"))
ret.append(self.curse_add_line(msg))
msg="{0:>6}".format(_("VIRT"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>6}".format(_("RES"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>6}".format(_("PID"))
ret.append(self.curse_add_line(msg, optional=True))
msg=" {0:10}".format(_("USER"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>3}".format(_("NI"))
ret.append(self.curse_add_line(msg, optional=True))
msg=" {0:1}".format(_("S"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>9}".format(_("TIME+"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>6}".format(_("IOr/s"))
ret.append(self.curse_add_line(msg, optional=True))
msg="{0:>6}".format(_("IOw/s"))
ret.append(self.curse_add_line(msg, optional=True))
msg=" {0:8}".format(_("Command"))
ret.append(self.curse_add_line(msg, optional=True))
# Trying to display proc time
tag_proc_time = True
# Loop over processes (sorted by args.process_sorted_by)
for p in sorted(self.stats, key=lambda process: process['cpu_percent'], reverse=True):
ret.append(self.curse_new_line())
# Name
msg="{0:15}".format(p['name'][:15])
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))
# MEM
msg = "{0:>6}".format(format(p['memory_percent'], '>5.1f'))
ret.append(self.curse_add_line(msg))
# VMS
msg = "{0:>6}".format(self.auto_unit(p['memory_info'][1], low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# RSS
msg = "{0:>6}".format(self.auto_unit(p['memory_info'][0], low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# PID
msg = "{0:>6}".format(p['pid'])
ret.append(self.curse_add_line(msg, optional=True))
# USER
msg = " {0:9}".format(p['username'][:9])
ret.append(self.curse_add_line(msg, optional=True))
# NICE
msg = " {0:>3}".format(p['nice'])
ret.append(self.curse_add_line(msg, optional=True))
# STATUS
msg = " {0:>1}".format(p['status'])
ret.append(self.curse_add_line(msg, optional=True))
# TIME+
if (tag_proc_time):
try:
dtime = timedelta(seconds=sum(p['cpu_times']))
except Exception:
# Catched on some Amazon EC2 server
# See https://github.com/nicolargo/glances/issues/87
tag_proc_time = False
else:
msg = "{0}:{1}.{2}".format(
str(dtime.seconds // 60 % 60),
str(dtime.seconds % 60).zfill(2),
str(dtime.microseconds)[:2].zfill(2))
else:
msg = " "
msg = "{0:>9}".format(msg)
ret.append(self.curse_add_line(msg, optional=True))
# IO read
io_rs = (p['io_counters'][0] - p['io_counters'][2]) / p['time_since_update']
msg = "{0:>6}".format(self.auto_unit(io_rs, low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
# IO write
io_ws = (p['io_counters'][1] - p['io_counters'][3]) / p['time_since_update']
msg = "{0:>6}".format(self.auto_unit(io_ws, low_precision=False))
ret.append(self.curse_add_line(msg, optional=True))
msg = " {0}".format(p['cmdline'])
ret.append(self.curse_add_line(msg, optional=True))
# Return the message with decoration
return ret
......@@ -27,35 +27,7 @@ except:
pass
from glances_plugin import GlancesPlugin, getTimeSinceLastUpdate
class Plugin(GlancesPlugin):
"""
Glances's sensors Plugin
stats is a list
"""
def __init__(self):
GlancesPlugin.__init__(self)
# Init the sensor class
self.glancesgrabsensors = glancesGrabSensors()
def update(self):
"""
Update Sensors stats
"""
self.stats = self.glancesgrabsensors.get()
def get_stats(self):
# Return the stats object for the RPC API
# !!! Sort it by label name (why do it here ? Better in client side ?)
self.stats = sorted(self.stats, key=lambda sensors: sensors['label'])
return GlancesPlugin.get_stats(self)
from glances_hddtemp import Plugin as HddTempPlugin
class glancesGrabSensors:
......@@ -102,4 +74,74 @@ class glancesGrabSensors:
def quit(self):
if self.initok:
sensors.cleanup()
\ No newline at end of file
sensors.cleanup()
class Plugin(GlancesPlugin):
"""
Glances's sensors Plugin
stats is a list
"""
def __init__(self):
GlancesPlugin.__init__(self)
# Init the sensor class
self.glancesgrabsensors = glancesGrabSensors()
# Instance for the CorePlugin in order to display the core number
self.hddtemp_plugin = HddTempPlugin()
# 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 = 5
def update(self):
"""
Update Sensors stats
"""
self.stats = self.glancesgrabsensors.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(_("SENSORS"))
ret.append(self.curse_add_line(msg, "TITLE"))
msg = "{0:>16}".format(_("Temp °C"))
ret.append(self.curse_add_line(msg))
# Sensors list (sorted by name): Sensors
sensor_list = sorted(self.stats, key=lambda sensors: sensors['label'])
for i in sensor_list:
# New line
ret.append(self.curse_new_line())
msg = "{0:<15}".format(i['label'])
ret.append(self.curse_add_line(msg))
msg = "{0:>8}".format(i['value'])
ret.append(self.curse_add_line(msg))
# Sensors list (sorted by name): HDDTemp
self.hddtemp_plugin.update()
sensor_list = sorted(self.hddtemp_plugin.stats, key=lambda sensors: sensors['label'])
for i in sensor_list:
# New line
ret.append(self.curse_new_line())
msg = "{0:<15}".format("Disk " + i['label'])
ret.append(self.curse_add_line(msg))
msg = "{0:>8}".format(i['value'])
ret.append(self.curse_add_line(msg))
return ret
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册