mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-01 14:04:50 +03:00
Replace dictionary creation with dictionary literal
This commit is contained in:
parent
85508e773d
commit
576883822e
@ -96,16 +96,15 @@ class Plugin(GlancesPlugin):
|
||||
diskio_new = diskiocounters
|
||||
for disk in diskio_new:
|
||||
try:
|
||||
# Try necessary to manage dynamic disk creation/del
|
||||
diskstat = {}
|
||||
diskstat['time_since_update'] = time_since_update
|
||||
diskstat['disk_name'] = disk
|
||||
diskstat['read_bytes'] = (
|
||||
diskio_new[disk].read_bytes -
|
||||
self.diskio_old[disk].read_bytes)
|
||||
diskstat['write_bytes'] = (
|
||||
diskio_new[disk].write_bytes -
|
||||
self.diskio_old[disk].write_bytes)
|
||||
read_bytes = (diskio_new[disk].read_bytes -
|
||||
self.diskio_old[disk].read_bytes)
|
||||
write_bytes = (diskio_new[disk].write_bytes -
|
||||
self.diskio_old[disk].write_bytes)
|
||||
diskstat = {
|
||||
'time_since_update': time_since_update,
|
||||
'disk_name': disk,
|
||||
'read_bytes': read_bytes,
|
||||
'write_bytes': write_bytes}
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
|
@ -115,10 +115,6 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Loop over fs
|
||||
for fs in fs_stat:
|
||||
fs_current = {}
|
||||
fs_current['device_name'] = fs.device
|
||||
fs_current['fs_type'] = fs.fstype
|
||||
fs_current['mnt_point'] = fs.mountpoint
|
||||
# Grab the disk usage
|
||||
try:
|
||||
fs_usage = psutil.disk_usage(fs.mountpoint)
|
||||
@ -126,11 +122,15 @@ class Plugin(GlancesPlugin):
|
||||
# Correct issue #346
|
||||
# Disk is ejected during the command
|
||||
continue
|
||||
fs_current['size'] = fs_usage.total
|
||||
fs_current['used'] = fs_usage.used
|
||||
fs_current['free'] = fs_usage.total - fs_usage.used
|
||||
fs_current['percent'] = fs_usage.percent
|
||||
fs_current['key'] = self.get_key()
|
||||
fs_current = {
|
||||
'device_name': fs.device,
|
||||
'fs_type': fs.fstype,
|
||||
'mnt_point': fs.mountpoint,
|
||||
'size': fs_usage.total,
|
||||
'used': fs_usage.used,
|
||||
'free': fs_usage.total - fs_usage.used,
|
||||
'percent': fs_usage.percent,
|
||||
'key': self.get_key()}
|
||||
self.stats.append(fs_current)
|
||||
|
||||
elif self.input_method == 'snmp':
|
||||
@ -148,30 +148,30 @@ class Plugin(GlancesPlugin):
|
||||
if self.short_system_name in ('windows', 'esxi'):
|
||||
# Windows or ESXi tips
|
||||
for fs in fs_stat:
|
||||
# Memory stats are grabed in the same OID table (ignore it)
|
||||
# Memory stats are grabbed in the same OID table (ignore it)
|
||||
if fs == 'Virtual Memory' or fs == 'Physical Memory' or fs == 'Real Memory':
|
||||
continue
|
||||
fs_current = {}
|
||||
fs_current['device_name'] = ''
|
||||
fs_current['mnt_point'] = fs.partition(' ')[0]
|
||||
fs_current['size'] = int(
|
||||
fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
|
||||
fs_current['used'] = int(
|
||||
fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit'])
|
||||
fs_current['percent'] = float(
|
||||
fs_current['used'] * 100 / fs_current['size'])
|
||||
fs_current['key'] = self.get_key()
|
||||
size = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
|
||||
used = int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit'])
|
||||
percent = float(used * 100 / size)
|
||||
fs_current = {
|
||||
'device_name': '',
|
||||
'mnt_point': fs.partition(' ')[0],
|
||||
'size': size,
|
||||
'used': used,
|
||||
'percent': percent,
|
||||
'key': self.get_key()}
|
||||
self.stats.append(fs_current)
|
||||
else:
|
||||
# Default behavor
|
||||
# Default behavior
|
||||
for fs in fs_stat:
|
||||
fs_current = {}
|
||||
fs_current['device_name'] = fs_stat[fs]['device_name']
|
||||
fs_current['mnt_point'] = fs
|
||||
fs_current['size'] = int(fs_stat[fs]['size']) * 1024
|
||||
fs_current['used'] = int(fs_stat[fs]['used']) * 1024
|
||||
fs_current['percent'] = float(fs_stat[fs]['percent'])
|
||||
fs_current['key'] = self.get_key()
|
||||
fs_current = {
|
||||
'device_name': fs_stat[fs]['device_name'],
|
||||
'mnt_point': fs,
|
||||
'size': int(fs_stat[fs]['size']) * 1024,
|
||||
'used': int(fs_stat[fs]['used']) * 1024,
|
||||
'percent': float(fs_stat[fs]['percent']),
|
||||
'key': self.get_key()}
|
||||
self.stats.append(fs_current)
|
||||
|
||||
# Update the history list
|
||||
|
@ -101,19 +101,21 @@ class Plugin(GlancesPlugin):
|
||||
network_new = netiocounters
|
||||
for net in network_new:
|
||||
try:
|
||||
# Try necessary to manage dynamic network interface
|
||||
netstat = {}
|
||||
netstat['interface_name'] = net
|
||||
netstat['time_since_update'] = time_since_update
|
||||
netstat['cumulative_rx'] = network_new[net].bytes_recv
|
||||
netstat['rx'] = (network_new[net].bytes_recv -
|
||||
self.network_old[net].bytes_recv)
|
||||
netstat['cumulative_tx'] = network_new[net].bytes_sent
|
||||
netstat['tx'] = (network_new[net].bytes_sent -
|
||||
self.network_old[net].bytes_sent)
|
||||
netstat['cumulative_cx'] = (netstat['cumulative_rx'] +
|
||||
netstat['cumulative_tx'])
|
||||
netstat['cx'] = netstat['rx'] + netstat['tx']
|
||||
cumulative_rx = network_new[net].bytes_recv
|
||||
cumulative_tx = network_new[net].bytes_sent
|
||||
cumulative_cx = cumulative_rx + cumulative_tx
|
||||
rx = cumulative_rx - self.network_old[net].bytes_recv
|
||||
tx = cumulative_tx - self.network_old[net].bytes_sent
|
||||
cx = rx + tx
|
||||
netstat = {
|
||||
'interface_name': net,
|
||||
'time_since_update': time_since_update,
|
||||
'cumulative_rx': cumulative_rx,
|
||||
'rx': rx,
|
||||
'cumulative_tx': cumulative_tx,
|
||||
'tx': tx,
|
||||
'cumulative_cx': cumulative_cx,
|
||||
'cx': cx}
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
@ -150,27 +152,30 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
for net in network_new:
|
||||
try:
|
||||
# Try necessary to manage dynamic network interface
|
||||
netstat = {}
|
||||
# Windows: a tips is needed to convert HEX to TXT
|
||||
# http://blogs.technet.com/b/networking/archive/2009/12/18/how-to-query-the-list-of-network-interfaces-using-snmp-via-the-ifdescr-counter.aspx
|
||||
if self.short_system_name == 'windows':
|
||||
try:
|
||||
netstat['interface_name'] = str(base64.b16decode(net[2:-2].upper()))
|
||||
interface_name = str(base64.b16decode(net[2:-2].upper()))
|
||||
except TypeError:
|
||||
netstat['interface_name'] = net
|
||||
interface_name = net
|
||||
else:
|
||||
netstat['interface_name'] = net
|
||||
netstat['time_since_update'] = time_since_update
|
||||
netstat['cumulative_rx'] = float(network_new[net]['cumulative_rx'])
|
||||
netstat['rx'] = (float(network_new[net]['cumulative_rx']) -
|
||||
float(self.network_old[net]['cumulative_rx']))
|
||||
netstat['cumulative_tx'] = float(network_new[net]['cumulative_tx'])
|
||||
netstat['tx'] = (float(network_new[net]['cumulative_tx']) -
|
||||
float(self.network_old[net]['cumulative_tx']))
|
||||
netstat['cumulative_cx'] = (netstat['cumulative_rx'] +
|
||||
netstat['cumulative_tx'])
|
||||
netstat['cx'] = netstat['rx'] + netstat['tx']
|
||||
interface_name = net
|
||||
cumulative_rx = float(network_new[net]['cumulative_rx'])
|
||||
cumulative_tx = float(network_new[net]['cumulative_tx'])
|
||||
cumulative_cx = cumulative_rx + cumulative_tx
|
||||
rx = cumulative_rx - float(self.network_old[net]['cumulative_rx'])
|
||||
tx = cumulative_tx - float(self.network_old[net]['cumulative_tx'])
|
||||
cx = rx + tx
|
||||
netstat = {
|
||||
'interface_name': interface_name,
|
||||
'time_since_update': time_since_update,
|
||||
'cumulative_rx': cumulative_rx,
|
||||
'rx': rx,
|
||||
'cumulative_tx': cumulative_tx,
|
||||
'tx': tx,
|
||||
'cumulative_cx': cumulative_cx,
|
||||
'cx': cx}
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user