mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-29 04:04:03 +03:00
SNMP client: all plugin OK except processing list. To hight CPU consump with the standard loop
This commit is contained in:
parent
ff5bbefa1b
commit
2222cf0fbc
@ -239,10 +239,5 @@ class GlancesStatsClientSNMP(GlancesStats):
|
||||
# For each plugins, call the update method
|
||||
for p in self._plugins:
|
||||
# print "DEBUG: Update %s stats using SNMP request" % p
|
||||
# !!! TO BE REFACTOR: try/catch only for dev
|
||||
try:
|
||||
self._plugins[p].update(input='snmp')
|
||||
except Exception as e:
|
||||
# print "ERROR with plugin %s: %s" % (p, e)
|
||||
pass
|
||||
self._plugins[p].update(input='snmp')
|
||||
|
||||
|
@ -45,13 +45,36 @@ class Plugin(GlancesPlugin):
|
||||
# Init the sensor class
|
||||
self.glancesgrabbat = glancesGrabBat()
|
||||
|
||||
def update(self):
|
||||
# Init stats
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Update batterie capacity stats
|
||||
Reset/init the stats
|
||||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
|
||||
"""
|
||||
Update batterie capacity stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
self.stats = self.glancesgrabbat.getcapacitypercent()
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
self.stats = self.glancesgrabbat.getcapacitypercent()
|
||||
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# Not avalaible
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
||||
class glancesGrabBat:
|
||||
"""
|
||||
|
@ -40,11 +40,35 @@ class Plugin(GlancesPlugin):
|
||||
# The HDD temp is displayed within the sensors plugin
|
||||
self.display_curse = False
|
||||
|
||||
def update(self):
|
||||
# Init stats
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Update HDD stats
|
||||
Reset/init the stats
|
||||
"""
|
||||
self.stats = self.glancesgrabhddtemp.get()
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update HDD stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.stats = self.glancesgrabhddtemp.get()
|
||||
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# Not available for the moment
|
||||
pass
|
||||
|
||||
|
||||
return self.stats
|
||||
|
||||
|
||||
class glancesGrabHDDTemp:
|
||||
|
@ -47,7 +47,7 @@ class Plugin(GlancesPlugin):
|
||||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 0
|
||||
|
||||
def update(self):
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
No stats, it is just a plugin to display the help...
|
||||
"""
|
||||
|
@ -50,19 +50,24 @@ class Plugin(GlancesPlugin):
|
||||
# print "DEBUG: Monitor plugin load config file %s" % config
|
||||
self.glances_monitors = glancesMonitorList(config)
|
||||
|
||||
def update(self):
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update the monitored list
|
||||
"""
|
||||
# Check if the glances_monitor instance is init
|
||||
if self.glances_monitors is None:
|
||||
return self.stats
|
||||
|
||||
# Update the monitored list (result of command)
|
||||
self.glances_monitors.update()
|
||||
if input == 'local':
|
||||
# Monitor list only available in a full Glances environment
|
||||
# Check if the glances_monitor instance is init
|
||||
if self.glances_monitors is None:
|
||||
return self.stats
|
||||
|
||||
# Put it on the stats var
|
||||
self.stats = self.glances_monitors.get()
|
||||
# Update the monitored list (result of command)
|
||||
self.glances_monitors.update()
|
||||
|
||||
# Put it on the stats var
|
||||
self.stats = self.glances_monitors.get()
|
||||
else:
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
||||
|
@ -44,7 +44,7 @@ class Plugin(GlancesPlugin):
|
||||
# Enter -1 to diplay bottom
|
||||
self.line_curse = -1
|
||||
|
||||
def update(self):
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update current date/time
|
||||
"""
|
||||
|
@ -47,78 +47,96 @@ class Plugin(GlancesPlugin):
|
||||
self.line_curse = 1
|
||||
|
||||
# Init stats
|
||||
self.stats = []
|
||||
self.reset()
|
||||
self.percputime_total_new = []
|
||||
self.percputime_new = []
|
||||
|
||||
def update(self):
|
||||
def reset(self):
|
||||
"""
|
||||
Update Per CPU stats
|
||||
Reset/init the stats
|
||||
"""
|
||||
# Grab CPU using the PSUtil cpu_times method
|
||||
# Per-CPU
|
||||
percputime = psutil.cpu_times(percpu=True)
|
||||
percputime_total = []
|
||||
for i in range(len(percputime)):
|
||||
percputime_total.append(percputime[i].user +
|
||||
percputime[i].system +
|
||||
percputime[i].idle)
|
||||
self.stats = []
|
||||
|
||||
# Only available on some OS
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'nice'):
|
||||
percputime_total[i] += percputime[i].nice
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'iowait'):
|
||||
percputime_total[i] += percputime[i].iowait
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'irq'):
|
||||
percputime_total[i] += percputime[i].irq
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'softirq'):
|
||||
percputime_total[i] += percputime[i].softirq
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'steal'):
|
||||
percputime_total[i] += percputime[i].steal
|
||||
if not hasattr(self, 'percputime_old'):
|
||||
self.percputime_old = percputime
|
||||
self.percputime_total_old = percputime_total
|
||||
self.stats = []
|
||||
else:
|
||||
self.percputime_new = percputime
|
||||
self.percputime_total_new = percputime_total
|
||||
perpercent = []
|
||||
self.stats = []
|
||||
try:
|
||||
for i in range(len(self.percputime_new)):
|
||||
perpercent.append(100 / (self.percputime_total_new[i] -
|
||||
self.percputime_total_old[i]))
|
||||
cpu = {'user': (self.percputime_new[i].user -
|
||||
self.percputime_old[i].user) * perpercent[i],
|
||||
'system': (self.percputime_new[i].system -
|
||||
self.percputime_old[i].system) * perpercent[i],
|
||||
'idle': (self.percputime_new[i].idle -
|
||||
self.percputime_old[i].idle) * perpercent[i]}
|
||||
if hasattr(self.percputime_new[i], 'nice'):
|
||||
cpu['nice'] = (self.percputime_new[i].nice -
|
||||
self.percputime_old[i].nice) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'iowait'):
|
||||
cpu['iowait'] = (self.percputime_new[i].iowait -
|
||||
self.percputime_old[i].iowait) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'irq'):
|
||||
cpu['irq'] = (self.percputime_new[i].irq -
|
||||
self.percputime_old[i].irq) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'softirq'):
|
||||
cpu['softirq'] = (self.percputime_new[i].softirq -
|
||||
self.percputime_old[i].softirq) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'steal'):
|
||||
cpu['steal'] = (self.percputime_new[i].steal -
|
||||
self.percputime_old[i].steal) * perpercent[i]
|
||||
self.stats.append(cpu)
|
||||
self.percputime_old = self.percputime_new
|
||||
self.percputime_total_old = self.percputime_total_new
|
||||
except Exception:
|
||||
self.stats = []
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update Per CPU stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Grab CPU using the PSUtil cpu_times method
|
||||
# Per-CPU
|
||||
percputime = psutil.cpu_times(percpu=True)
|
||||
percputime_total = []
|
||||
for i in range(len(percputime)):
|
||||
percputime_total.append(percputime[i].user +
|
||||
percputime[i].system +
|
||||
percputime[i].idle)
|
||||
|
||||
# Only available on some OS
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'nice'):
|
||||
percputime_total[i] += percputime[i].nice
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'iowait'):
|
||||
percputime_total[i] += percputime[i].iowait
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'irq'):
|
||||
percputime_total[i] += percputime[i].irq
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'softirq'):
|
||||
percputime_total[i] += percputime[i].softirq
|
||||
for i in range(len(percputime)):
|
||||
if hasattr(percputime[i], 'steal'):
|
||||
percputime_total[i] += percputime[i].steal
|
||||
if not hasattr(self, 'percputime_old'):
|
||||
self.percputime_old = percputime
|
||||
self.percputime_total_old = percputime_total
|
||||
else:
|
||||
self.percputime_new = percputime
|
||||
self.percputime_total_new = percputime_total
|
||||
perpercent = []
|
||||
try:
|
||||
for i in range(len(self.percputime_new)):
|
||||
perpercent.append(100 / (self.percputime_total_new[i] -
|
||||
self.percputime_total_old[i]))
|
||||
cpu = {'user': (self.percputime_new[i].user -
|
||||
self.percputime_old[i].user) * perpercent[i],
|
||||
'system': (self.percputime_new[i].system -
|
||||
self.percputime_old[i].system) * perpercent[i],
|
||||
'idle': (self.percputime_new[i].idle -
|
||||
self.percputime_old[i].idle) * perpercent[i]}
|
||||
if hasattr(self.percputime_new[i], 'nice'):
|
||||
cpu['nice'] = (self.percputime_new[i].nice -
|
||||
self.percputime_old[i].nice) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'iowait'):
|
||||
cpu['iowait'] = (self.percputime_new[i].iowait -
|
||||
self.percputime_old[i].iowait) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'irq'):
|
||||
cpu['irq'] = (self.percputime_new[i].irq -
|
||||
self.percputime_old[i].irq) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'softirq'):
|
||||
cpu['softirq'] = (self.percputime_new[i].softirq -
|
||||
self.percputime_old[i].softirq) * perpercent[i]
|
||||
if hasattr(self.percputime_new[i], 'steal'):
|
||||
cpu['steal'] = (self.percputime_new[i].steal -
|
||||
self.percputime_old[i].steal) * perpercent[i]
|
||||
self.stats.append(cpu)
|
||||
self.percputime_old = self.percputime_new
|
||||
self.percputime_total_old = self.percputime_total_new
|
||||
except Exception:
|
||||
self.reset()
|
||||
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
"""
|
||||
@ -128,6 +146,12 @@ class Plugin(GlancesPlugin):
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
||||
# No per CPU stat ? Exit...
|
||||
if self.stats == []:
|
||||
msg = "{0}".format(_("PER CPU not available"))
|
||||
ret.append(self.curse_add_line(msg, "TITLE"))
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
# Header
|
||||
msg = "{0:8}".format(_("PER CPU"))
|
||||
|
@ -32,12 +32,30 @@ class Plugin(GlancesPlugin):
|
||||
def __init__(self):
|
||||
GlancesPlugin.__init__(self)
|
||||
|
||||
def update(self):
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Reset/init the stats
|
||||
"""
|
||||
self.stats = None
|
||||
|
||||
def update(self, input='local'):
|
||||
"""
|
||||
Update core stats
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
# Return PsUtil version as a tuple
|
||||
try:
|
||||
self.stats = tuple([int(num) for num in __psutil_version__.split('.')])
|
||||
except NameError:
|
||||
self.stats = None
|
||||
if input == 'local':
|
||||
# PsUtil version only available in local
|
||||
try:
|
||||
self.stats = tuple([int(num) for num in __psutil_version__.split('.')])
|
||||
except NameError:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
Loading…
Reference in New Issue
Block a user