mirror of https://github.com/nicolargo/glances
SNMP client: replace input args by set and get method
parent
28c7f7f311
commit
0a0be7bbd7
|
@ -259,9 +259,11 @@ class GlancesStatsClientSNMP(GlancesStats):
|
|||
|
||||
# For each plugins, call the update method
|
||||
for p in self._plugins:
|
||||
# Set the input method to SNMP
|
||||
self._plugins[p].set_input('snmp')
|
||||
# print "DEBUG: Update %s stats using SNMP request" % p
|
||||
try:
|
||||
self._plugins[p].update(input='snmp')
|
||||
self._plugins[p].update()
|
||||
except Exception as e:
|
||||
print "ERROR: Update %s failed (%s)" % (p, e)
|
||||
# pass
|
||||
|
|
|
@ -53,7 +53,7 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Nothing to do here
|
||||
Just return the global glances_log
|
||||
|
|
|
@ -54,22 +54,21 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
|
||||
"""
|
||||
Update batterie capacity stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
self.stats = self.glancesgrabbat.getcapacitypercent()
|
||||
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# Not avalaible
|
||||
pass
|
||||
|
|
|
@ -46,17 +46,16 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update core stats
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
Stats is a dict (with both physical and log cpu number) instead of a integer
|
||||
"""
|
||||
|
||||
# Reset the stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# The PSUtil 2.0 include psutil.cpu_count() and psutil.cpu_count(logical=False)
|
||||
|
@ -70,7 +69,7 @@ class Plugin(GlancesPlugin):
|
|||
except NameError:
|
||||
self.reset()
|
||||
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# http://stackoverflow.com/questions/5662467/how-to-find-out-the-number-of-cpus-using-snmp
|
||||
pass
|
||||
|
|
|
@ -61,16 +61,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update CPU stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Grab CPU using the PSUtil cpu_times_percent method
|
||||
|
@ -93,7 +92,7 @@ class Plugin(GlancesPlugin):
|
|||
'guest', 'guest_nice']:
|
||||
if hasattr(cputimespercent, cpu):
|
||||
self.stats[cpu] = getattr(cputimespercent, cpu)
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
|
|
|
@ -55,16 +55,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update disk IO stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Grab the stat using the PsUtil disk_io_counters method
|
||||
# read_count: number of reads
|
||||
|
@ -111,7 +110,7 @@ class Plugin(GlancesPlugin):
|
|||
|
||||
# Save stats to compute next bitrate
|
||||
self.diskio_old = diskio_new
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO: no standard way for the moment
|
||||
pass
|
||||
|
|
|
@ -70,16 +70,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update the FS stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset the list
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Grab the stats using the PsUtil disk_partitions
|
||||
|
@ -109,7 +108,7 @@ class Plugin(GlancesPlugin):
|
|||
fs_current['percent'] = fs_usage.percent
|
||||
self.stats.append(fs_current)
|
||||
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
|
||||
# SNMP bulk command to get all file system in one shot
|
||||
|
|
|
@ -50,20 +50,19 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update HDD stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.stats = self.glancesgrabhddtemp.get()
|
||||
|
||||
elif input == 'snmp':
|
||||
else:
|
||||
# Update stats using SNMP
|
||||
# Not available for the moment
|
||||
pass
|
||||
|
|
|
@ -47,7 +47,7 @@ class Plugin(GlancesPlugin):
|
|||
# Enter -1 to diplay bottom
|
||||
self.line_curse = 0
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
No stats, it is just a plugin to display the help...
|
||||
"""
|
||||
|
|
|
@ -64,10 +64,9 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update load stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
|
@ -79,7 +78,7 @@ class Plugin(GlancesPlugin):
|
|||
except:
|
||||
nb_log_core = 0
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Get the load using the os standard lib
|
||||
|
@ -95,7 +94,7 @@ class Plugin(GlancesPlugin):
|
|||
'min5': load[1],
|
||||
'min15': load[2],
|
||||
'cpucore': nb_log_core }
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
|
|
|
@ -67,16 +67,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update MEM (RAM) stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Grab MEM using the PSUtil virtual_memory method
|
||||
vm_stats = psutil.virtual_memory()
|
||||
|
@ -110,7 +109,7 @@ class Plugin(GlancesPlugin):
|
|||
self.stats['free'] += self.stats['cached']
|
||||
# used=total-free
|
||||
self.stats['used'] = self.stats['total'] - self.stats['free']
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
|
|
|
@ -59,16 +59,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update MEM (SWAP) stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Grab SWAP using the PSUtil swap_memory method
|
||||
sm_stats = psutil.swap_memory()
|
||||
|
@ -84,7 +83,7 @@ class Plugin(GlancesPlugin):
|
|||
'sin', 'sout']:
|
||||
if hasattr(sm_stats, swap):
|
||||
self.stats[swap] = getattr(sm_stats, swap)
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
|
|
|
@ -50,12 +50,12 @@ class Plugin(GlancesPlugin):
|
|||
# print "DEBUG: Monitor plugin load config file %s" % config
|
||||
self.glances_monitors = glancesMonitorList(config)
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update the monitored list
|
||||
"""
|
||||
|
||||
if input == 'local':
|
||||
if self.get_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:
|
||||
|
|
|
@ -63,17 +63,16 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update network stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
Stats is a list of dict (one dict per interface)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Grab network interface stat using the PsUtil net_io_counter method
|
||||
|
@ -120,7 +119,7 @@ class Plugin(GlancesPlugin):
|
|||
# Save stats to compute next bitrate
|
||||
self.network_old = network_new
|
||||
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class Plugin(GlancesPlugin):
|
|||
# Enter -1 to diplay bottom
|
||||
self.line_curse = -1
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update current date/time
|
||||
"""
|
||||
|
|
|
@ -57,16 +57,15 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update Per CPU stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
|
||||
# Grab CPU using the PSUtil cpu_times method
|
||||
|
@ -132,7 +131,7 @@ class Plugin(GlancesPlugin):
|
|||
except Exception:
|
||||
self.reset()
|
||||
|
||||
elif input == 'snmp':
|
||||
else:
|
||||
# Update stats using SNMP
|
||||
pass
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ class GlancesPlugin(object):
|
|||
# Init the args
|
||||
self.args = args
|
||||
|
||||
# Init the input method
|
||||
self.input = 'local'
|
||||
|
||||
# Init the stats list
|
||||
self.stats = None
|
||||
|
||||
|
@ -54,6 +57,21 @@ class GlancesPlugin(object):
|
|||
# Return the human-readable stats
|
||||
return str(self.stats)
|
||||
|
||||
def set_input(self, input):
|
||||
"""
|
||||
Set the input method:
|
||||
* local: system local grab (PSUtil or direct access)
|
||||
* snmp: Client server mode via SNMP
|
||||
* glances: Client server mode via Glances API
|
||||
"""
|
||||
self.input = input
|
||||
|
||||
def get_input(self):
|
||||
"""
|
||||
Get the input method
|
||||
"""
|
||||
return self.input
|
||||
|
||||
def set_stats(self, input_stats):
|
||||
# Set the stats to input_stats
|
||||
self.stats = input_stats
|
||||
|
|
|
@ -49,23 +49,22 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update processes stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Here, update is call for processcount AND processlist
|
||||
glances_processes.update()
|
||||
|
||||
# Return the processes count
|
||||
self.stats = glances_processes.getcount()
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
pass
|
||||
|
|
|
@ -52,21 +52,20 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update processes stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
# Note: Update is done in the processcount plugin
|
||||
# Just return the processes list
|
||||
self.stats = glances_processes.getlist()
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
pass
|
||||
|
|
|
@ -40,7 +40,7 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = None
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update core stats
|
||||
"""
|
||||
|
@ -49,7 +49,7 @@ class Plugin(GlancesPlugin):
|
|||
self.reset()
|
||||
|
||||
# Return PsUtil version as a tuple
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# PsUtil version only available in local
|
||||
try:
|
||||
self.stats = tuple([int(num) for num in __psutil_version__.split('.')])
|
||||
|
|
|
@ -66,21 +66,20 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = []
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update sensors stats using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset the stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.hddtemp_plugin.update()
|
||||
self.stats = self.glancesgrabsensors.get()
|
||||
self.stats.extend(self.hddtemp_plugin.stats)
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# No standard: http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04
|
||||
pass
|
||||
|
|
|
@ -59,17 +59,16 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update the host/system info using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
Return the stats (dict)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.stats['os_name'] = platform.system()
|
||||
self.stats['hostname'] = platform.node()
|
||||
|
@ -91,7 +90,7 @@ class Plugin(GlancesPlugin):
|
|||
self.stats['os_version'] = ' '.join(os_version[::2])
|
||||
else:
|
||||
self.stats['os_version'] = ""
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
|
||||
|
|
|
@ -57,22 +57,21 @@ class Plugin(GlancesPlugin):
|
|||
"""
|
||||
self.stats = {}
|
||||
|
||||
def update(self, input='local'):
|
||||
def update(self):
|
||||
"""
|
||||
Update uptime stat using the input method
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset stats
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
if self.get_input() == 'local':
|
||||
# Update stats using the standard system lib
|
||||
uptime = datetime.now() - datetime.fromtimestamp(psutil.boot_time())
|
||||
|
||||
# Convert uptime to string (because datetime is not JSONifi)
|
||||
self.stats = str(uptime).split('.')[0]
|
||||
elif input == 'snmp':
|
||||
elif self.get_input() == 'snmp':
|
||||
# Update stats using SNMP
|
||||
uptime = self.set_stats_snmp(snmp_oid=snmp_oid)['_uptime']
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue