mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-29 04:04:03 +03:00
SNMP grab OK for file system
This commit is contained in:
parent
5cbe52aa39
commit
7d4024a9f0
@ -239,9 +239,10 @@ 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:
|
||||
# !!! try/catch only for dev
|
||||
except Exception as e:
|
||||
# print "ERROR: %s" % e
|
||||
pass
|
||||
|
||||
|
@ -48,7 +48,6 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Init the stats
|
||||
self.reset()
|
||||
self.diskio_old = self.stats
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
@ -74,10 +73,13 @@ class Plugin(GlancesPlugin):
|
||||
# write_bytes: number of bytes written
|
||||
# read_time: time spent reading from disk (in milliseconds)
|
||||
# write_time: time spent writing to disk (in milliseconds)
|
||||
diskiocounters = psutil.disk_io_counters(perdisk=True)
|
||||
try:
|
||||
diskiocounters = psutil.disk_io_counters(perdisk=True)
|
||||
except:
|
||||
return self.stats
|
||||
|
||||
# Previous disk IO stats are stored in the diskio_old variable
|
||||
if self.diskio_old == []:
|
||||
if not hasattr(self, 'diskio_old'):
|
||||
# First call, we init the network_old var
|
||||
try:
|
||||
self.diskio_old = diskiocounters
|
||||
@ -106,10 +108,12 @@ class Plugin(GlancesPlugin):
|
||||
continue
|
||||
else:
|
||||
self.stats.append(diskstat)
|
||||
|
||||
# Save stats to compute next bitrate
|
||||
self.diskio_old = diskio_new
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
# !!! TODO: no standard way for the moment
|
||||
pass
|
||||
|
||||
return self.stats
|
||||
|
@ -21,69 +21,26 @@ import psutil
|
||||
|
||||
from glances.plugins.glances_plugin import GlancesPlugin
|
||||
|
||||
|
||||
class glancesGrabFs:
|
||||
"""
|
||||
Get FS stats
|
||||
Did not exist in PSUtil, so had to create it from scratch
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Init FS stats
|
||||
"""
|
||||
|
||||
# Init the stats
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Reset/init the stats
|
||||
"""
|
||||
self.fs_list = []
|
||||
|
||||
def __update__(self):
|
||||
"""
|
||||
Update the stats
|
||||
"""
|
||||
# Reset the list
|
||||
self.reset()
|
||||
|
||||
# Grab the stats using the PsUtil disk_partitions
|
||||
# If 'all'=False return physical devices only (e.g. hard disks, cd-rom drives, USB keys)
|
||||
# and ignore all others (e.g. memory partitions such as /dev/shm)
|
||||
try:
|
||||
fs_stat = psutil.disk_partitions(all=False)
|
||||
except UnicodeDecodeError:
|
||||
self.stats = []
|
||||
return self.stats
|
||||
|
||||
# Loop over fs
|
||||
for fs in range(len(fs_stat)):
|
||||
fs_current = {}
|
||||
fs_current['device_name'] = fs_stat[fs].device
|
||||
fs_current['fs_type'] = fs_stat[fs].fstype
|
||||
fs_current['mnt_point'] = fs_stat[fs].mountpoint
|
||||
# Grab the disk usage
|
||||
try:
|
||||
fs_usage = psutil.disk_usage(fs_current['mnt_point'])
|
||||
except OSError:
|
||||
# Correct issue #346
|
||||
# Disk is ejected during the command
|
||||
continue
|
||||
fs_current['size'] = fs_usage.total
|
||||
fs_current['used'] = fs_usage.used
|
||||
fs_current['avail'] = fs_usage.free
|
||||
fs_current['percent'] = fs_usage.percent
|
||||
self.fs_list.append(fs_current)
|
||||
|
||||
return self.fs_list
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Update and return the stats
|
||||
"""
|
||||
return self.__update__()
|
||||
# SNMP OID
|
||||
# The snmpd.conf needs to be edited.
|
||||
# Add the following to enable it on all disk
|
||||
# ...
|
||||
# includeAllDisks 10%
|
||||
# ...
|
||||
# The OIDs are as follows (for the first disk)
|
||||
# Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
|
||||
# Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
|
||||
# Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
|
||||
# Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
|
||||
# Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
|
||||
# Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
|
||||
# Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1
|
||||
fs_oid = { 'mnt_point': '1.3.6.1.4.1.2021.9.1.2',
|
||||
'device_name': '1.3.6.1.4.1.2021.9.1.3',
|
||||
'size': '1.3.6.1.4.1.2021.9.1.6',
|
||||
'used': '1.3.6.1.4.1.2021.9.1.8',
|
||||
# 'avail': '1.3.6.1.4.1.2021.9.1.7',
|
||||
'percent': '1.3.6.1.4.1.2021.9.1.9'}
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
@ -96,9 +53,6 @@ class Plugin(GlancesPlugin):
|
||||
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
|
||||
@ -123,16 +77,58 @@ class Plugin(GlancesPlugin):
|
||||
Input method could be: local (mandatory) or snmp (optionnal)
|
||||
"""
|
||||
|
||||
# Reset the stats
|
||||
self.reset()
|
||||
# Reset the list
|
||||
self.reset()
|
||||
|
||||
if input == 'local':
|
||||
# Update stats using the standard system lib
|
||||
self.stats = self.glancesgrabfs.get()
|
||||
|
||||
# Grab the stats using the PsUtil disk_partitions
|
||||
# If 'all'=False return physical devices only (e.g. hard disks, cd-rom drives, USB keys)
|
||||
# and ignore all others (e.g. memory partitions such as /dev/shm)
|
||||
try:
|
||||
fs_stat = psutil.disk_partitions(all=False)
|
||||
except UnicodeDecodeError:
|
||||
return self.stats
|
||||
|
||||
# Loop over fs
|
||||
for fs in range(len(fs_stat)):
|
||||
fs_current = {}
|
||||
fs_current['device_name'] = fs_stat[fs].device
|
||||
fs_current['fs_type'] = fs_stat[fs].fstype
|
||||
fs_current['mnt_point'] = fs_stat[fs].mountpoint
|
||||
# Grab the disk usage
|
||||
try:
|
||||
fs_usage = psutil.disk_usage(fs_current['mnt_point'])
|
||||
except OSError:
|
||||
# Correct issue #346
|
||||
# Disk is ejected during the command
|
||||
continue
|
||||
fs_current['size'] = fs_usage.total
|
||||
fs_current['used'] = fs_usage.used
|
||||
# fs_current['avail'] = fs_usage.free
|
||||
fs_current['percent'] = fs_usage.percent
|
||||
self.stats.append(fs_current)
|
||||
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! TODO
|
||||
pass
|
||||
|
||||
# Loop over disks
|
||||
diskIndex = 1
|
||||
while (diskIndex < 1024):
|
||||
# Add disk index to the fs OID
|
||||
snmp_oid = dict((k, v + '.' + str(diskIndex)) for (k, v) in fs_oid.items())
|
||||
fs_current = self.set_stats_snmp(snmp_oid=snmp_oid)
|
||||
if str(fs_current['mnt_point']) == '':
|
||||
break
|
||||
# Size returned by SNMP is in kilobyte, convert it in byte
|
||||
fs_current['size'] = int(fs_current['size']) * 1024
|
||||
fs_current['used'] = int(fs_current['used']) * 1024
|
||||
# fs_current['avail'] = int(fs_current['avail'])
|
||||
self.stats.append(fs_current)
|
||||
diskIndex += 1
|
||||
|
||||
# print self.stats
|
||||
|
||||
return self.stats
|
||||
|
||||
|
@ -119,6 +119,7 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Save stats to compute next bitrate
|
||||
self.network_old = network_new
|
||||
|
||||
elif input == 'snmp':
|
||||
# Update stats using SNMP
|
||||
# !!! High CPU consumption on the client side
|
||||
@ -135,26 +136,26 @@ class Plugin(GlancesPlugin):
|
||||
network_new = {}
|
||||
ifIndex = 1
|
||||
ifCpt = 1
|
||||
while (ifCpt < ifNumber) or (ifIndex > 1024):
|
||||
while (ifCpt < ifNumber) and (ifIndex < 1024):
|
||||
# Add interface index to netif OID
|
||||
net_oid = dict((k, v + '.' + str(ifIndex)) for (k, v) in netif_oid.items())
|
||||
netstat = self.set_stats_snmp(snmp_oid=net_oid)
|
||||
if str(netstat['interface_name']) == '':
|
||||
net_stat = self.set_stats_snmp(snmp_oid=net_oid)
|
||||
if str(net_stat['interface_name']) == '':
|
||||
ifIndex += 1
|
||||
continue
|
||||
else:
|
||||
ifCpt += 1
|
||||
network_new[ifIndex] = netstat
|
||||
network_new[ifIndex] = net_stat
|
||||
if hasattr(self, 'network_old'):
|
||||
netstat['time_since_update'] = time_since_update
|
||||
netstat['rx'] = (float(network_new[ifIndex]['cumulative_rx']) -
|
||||
net_stat['time_since_update'] = time_since_update
|
||||
net_stat['rx'] = (float(network_new[ifIndex]['cumulative_rx']) -
|
||||
float(self.network_old[ifIndex]['cumulative_rx']))
|
||||
netstat['tx'] = (float(network_new[ifIndex]['cumulative_tx']) -
|
||||
net_stat['tx'] = (float(network_new[ifIndex]['cumulative_tx']) -
|
||||
float(self.network_old[ifIndex]['cumulative_tx']))
|
||||
netstat['cumulative_cx'] = (float(netstat['cumulative_rx']) +
|
||||
float(netstat['cumulative_tx']))
|
||||
netstat['cx'] = netstat['rx'] + netstat['tx']
|
||||
self.stats.append(netstat)
|
||||
net_stat['cumulative_cx'] = (float(net_stat['cumulative_rx']) +
|
||||
float(net_stat['cumulative_tx']))
|
||||
net_stat['cx'] = net_stat['rx'] + net_stat['tx']
|
||||
self.stats.append(net_stat)
|
||||
ifIndex += 1
|
||||
|
||||
# Save stats to compute next bitrate
|
||||
|
Loading…
Reference in New Issue
Block a user