提交 af7d3146 编写于 作者: N Nicolargo

Some PEP8 enhancement

上级 2b1fd87d
......@@ -32,9 +32,9 @@ snmp_oid = {'default': {'user': '1.3.6.1.4.1.2021.11.9.0',
'idle': '1.3.6.1.4.1.2021.11.11.0'},
'windows': {'percent': '1.3.6.1.2.1.25.3.3.1.2'},
'esxi': {'percent': '1.3.6.1.2.1.25.3.3.1.2'},
'netapp': {'system': '1.3.6.1.4.1.789.1.2.1.3.0',
'idle': '1.3.6.1.4.1.789.1.2.1.5.0',
'nb_log_core': '1.3.6.1.4.1.789.1.2.1.6.0'}}
'netapp': {'system': '1.3.6.1.4.1.789.1.2.1.3.0',
'idle': '1.3.6.1.4.1.789.1.2.1.5.0',
'nb_log_core': '1.3.6.1.4.1.789.1.2.1.6.0'}}
# Define the history items list
# - 'name' define the stat identifier
......@@ -55,7 +55,8 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None):
"""Init the CPU plugin."""
GlancesPlugin.__init__(self, args=args, items_history_list=items_history_list)
GlancesPlugin.__init__(
self, args=args, items_history_list=items_history_list)
# We want to display the stat in the curse interface
self.display_curse = True
......@@ -73,7 +74,8 @@ class Plugin(GlancesPlugin):
# Reset stats
self.reset()
# Grab CPU stats using psutil's cpu_percent and cpu_times_percent methods
# Grab CPU stats using psutil's cpu_percent and cpu_times_percent
# methods
if self.get_input() == 'local':
# Get all possible values for CPU stats: user, system, idle,
# nice (UNIX), iowait (Linux), irq (Linux, FreeBSD), steal (Linux 2.6.11+)
......@@ -105,16 +107,19 @@ class Plugin(GlancesPlugin):
self.stats['idle'] += float(cpu_stats['percent.3'])
self.stats['nb_log_core'] += 1
if self.stats['nb_log_core'] > 0:
self.stats['idle'] = self.stats['idle'] / self.stats['nb_log_core']
self.stats['idle'] = self.stats[
'idle'] / self.stats['nb_log_core']
self.stats['idle'] = 100 - self.stats['idle']
self.stats['total'] = 100 - self.stats['idle']
else:
# Default behavor
try:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()])
self.stats = self.set_stats_snmp(
snmp_oid=snmp_oid[self.get_short_system_name()])
except KeyError:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid['default'])
self.stats = self.set_stats_snmp(
snmp_oid=snmp_oid['default'])
if self.stats['idle'] == '':
self.reset()
......@@ -140,7 +145,8 @@ class Plugin(GlancesPlugin):
return ret
# Build the string message
# If user stat is not here, display only idle / total CPU usage (for exemple on Windows OS)
# If user stat is not here, display only idle / total CPU usage (for
# exemple on Windows OS)
idle_tag = 'user' not in self.stats
# Header
msg = '{0:8}'.format(_("CPU"))
......@@ -148,7 +154,8 @@ class Plugin(GlancesPlugin):
# Total CPU usage
msg = '{0:>5}%'.format(self.stats['total'])
if idle_tag:
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['total'], header="system")))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['total'], header="system")))
else:
ret.append(self.curse_add_line(msg))
# Nice CPU
......@@ -164,7 +171,8 @@ class Plugin(GlancesPlugin):
msg = '{0:8}'.format(_("user:"))
ret.append(self.curse_add_line(msg))
msg = '{0:>5}%'.format(self.stats['user'])
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['user'], header="user")))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['user'], header="user")))
elif 'idle' in self.stats:
msg = '{0:8}'.format(_("idle:"))
ret.append(self.curse_add_line(msg))
......@@ -183,7 +191,8 @@ class Plugin(GlancesPlugin):
msg = '{0:8}'.format(_("system:"))
ret.append(self.curse_add_line(msg))
msg = '{0:>5}%'.format(self.stats['system'])
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['system'], header="system")))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['system'], header="system")))
else:
msg = '{0:8}'.format(_("core:"))
ret.append(self.curse_add_line(msg))
......@@ -194,7 +203,8 @@ class Plugin(GlancesPlugin):
msg = ' {0:8}'.format(_("iowait:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = '{0:>5}%'.format(self.stats['iowait'])
ret.append(self.curse_add_line(msg, self.get_alert_log(self.stats['iowait'], header="iowait"), optional=True))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['iowait'], header="iowait"), optional=True))
# New line
ret.append(self.curse_new_line())
# Idle CPU
......@@ -208,7 +218,8 @@ class Plugin(GlancesPlugin):
msg = ' {0:8}'.format(_("steal:"))
ret.append(self.curse_add_line(msg, optional=True))
msg = '{0:>5}%'.format(self.stats['steal'])
ret.append(self.curse_add_line(msg, self.get_alert(self.stats['steal'], header="steal"), optional=True))
ret.append(self.curse_add_line(
msg, self.get_alert(self.stats['steal'], header="steal"), optional=True))
# Return the message with decoration
return ret
......@@ -48,11 +48,11 @@ snmp_oid = {'default': {'mnt_point': '1.3.6.1.4.1.2021.9.1.2',
'alloc_unit': '1.3.6.1.2.1.25.2.3.1.4',
'size': '1.3.6.1.2.1.25.2.3.1.5',
'used': '1.3.6.1.2.1.25.2.3.1.6'},
'netapp': {'mnt_point': '1.3.6.1.4.1.789.1.5.4.1.2',
'device_name': '1.3.6.1.4.1.789.1.5.4.1.10',
'size': '1.3.6.1.4.1.789.1.5.4.1.3',
'used': '1.3.6.1.4.1.789.1.5.4.1.4',
'percent': '1.3.6.1.4.1.789.1.5.4.1.6'}}
'netapp': {'mnt_point': '1.3.6.1.4.1.789.1.5.4.1.2',
'device_name': '1.3.6.1.4.1.789.1.5.4.1.10',
'size': '1.3.6.1.4.1.789.1.5.4.1.3',
'used': '1.3.6.1.4.1.789.1.5.4.1.4',
'percent': '1.3.6.1.4.1.789.1.5.4.1.6'}}
snmp_oid['esxi'] = snmp_oid['windows']
# Define the history items list
......@@ -70,7 +70,8 @@ class Plugin(GlancesPlugin):
def __init__(self, args=None):
"""Init the plugin."""
GlancesPlugin.__init__(self, args=args, items_history_list=items_history_list)
GlancesPlugin.__init__(
self, args=args, items_history_list=items_history_list)
# We want to display the stat in the curse interface
self.display_curse = True
......@@ -144,9 +145,12 @@ class Plugin(GlancesPlugin):
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['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()
self.stats.append(fs_current)
else:
......@@ -202,7 +206,8 @@ class Plugin(GlancesPlugin):
mnt_point = i['mnt_point'][-fsname_max_width + 1:]
elif len(i['mnt_point']) + len(i['device_name'].split('/')[-1]) <= fsname_max_width - 3:
# If possible concatenate mode info... Glances touch inside :)
mnt_point = i['mnt_point'] + ' (' + i['device_name'].split('/')[-1] + ')'
mnt_point = i['mnt_point'] + \
' (' + i['device_name'].split('/')[-1] + ')'
elif len(i['mnt_point']) > fsname_max_width:
# Cut mount point name if it is too long
mnt_point = '_' + i['mnt_point'][-fsname_max_width + 1:]
......
......@@ -30,13 +30,14 @@ from glances.plugins.glances_plugin import GlancesPlugin
# SNMP OID
snmp_oid = {'default': {'hostname': '1.3.6.1.2.1.1.5.0',
'system_name': '1.3.6.1.2.1.1.1.0'},
'netapp': {'hostname': '1.3.6.1.2.1.1.5.0',
'system_name': '1.3.6.1.2.1.1.1.0',
'platform': '1.3.6.1.4.1.789.1.1.5.0'}}
'netapp': {'hostname': '1.3.6.1.2.1.1.5.0',
'system_name': '1.3.6.1.2.1.1.1.0',
'platform': '1.3.6.1.4.1.789.1.1.5.0'}}
# SNMP to human read
# Dict (key: OS short name) of dict (reg exp OID to human)
# Windows: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx
# Windows:
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx
snmp_to_human = {'windows': {'Windows Version 6.3': 'Windows 8.1 or Server 2012R2',
'Windows Version 6.2': 'Windows 8 or Server 2012',
'Windows Version 6.1': 'Windows 7 or Server 2008R2',
......@@ -121,7 +122,8 @@ class Plugin(GlancesPlugin):
elif self.stats['os_name'] == "Windows":
os_version = platform.win32_ver()
self.stats['os_version'] = ' '.join(os_version[::2])
# if the python version is 32 bit perhaps the windows operating system is 64bit
# if the python version is 32 bit perhaps the windows operating
# system is 64bit
if self.stats['platform'] == '32bit':
if 'PROCESSOR_ARCHITEW6432' in os.environ:
self.stats['platform'] = '64bit'
......@@ -131,13 +133,15 @@ class Plugin(GlancesPlugin):
if self.stats['os_name'] == "Linux":
self.stats['hr_name'] = self.stats['linux_distro']
else:
self.stats['hr_name'] = '{0} {1}'.format(self.stats['os_name'], self.stats['os_version'])
self.stats['hr_name'] = '{0} {1}'.format(
self.stats['os_name'], self.stats['os_version'])
self.stats['hr_name'] += ' ({0})'.format(self.stats['platform'])
elif self.get_input() == 'snmp':
# Update stats using SNMP
try:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid[self.get_short_system_name()])
self.stats = self.set_stats_snmp(
snmp_oid=snmp_oid[self.get_short_system_name()])
except KeyError:
self.stats = self.set_stats_snmp(snmp_oid=snmp_oid['default'])
# Default behavor: display all the information
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册