提交 fadb75e0 编写于 作者: N nicolargo

Correct Flake8 issue in pkugins

上级 97b36d0b
......@@ -96,8 +96,8 @@ tree_new = {
'_no': {
# Low swap means you have a "real" IO wait problem. The next step is to see what's hogging your IO.
# iotop is an awesome tool for identifying io offenders. Two things to note:
# unless you've already installed iotop, it's probably not already on your system.
# Recommendation: install it before you need it - - it's no fun trying to install a troubleshooting
# unless you've already installed iotop, it's probably not already on your system.
# Recommendation: install it before you need it - - it's no fun trying to install a troubleshooting
# tool on an overloaded machine (iotop requies a Linux of 2.62 or above)
'_msg': "I/O issue"
}
......@@ -109,15 +109,15 @@ tree_new = {
'cpu_user': {
'_yes': {
# We expect the usertime percentage to be high.
# There's most likely a program or service you've configured on you server that's hogging CPU.
# Checking the % user time just confirms this. When you see that the % usertime is high,
# There's most likely a program or service you've configured on you server that's hogging CPU.
# Checking the % user time just confirms this. When you see that the % usertime is high,
# it's time to see what executable is monopolizing the CPU
# Once you've confirmed that the % usertime is high, check the process list(also provided by top).
# Once you've confirmed that the % usertime is high, check the process list(also provided by top).
# Be default, top sorts the process list by % CPU, so you can just look at the top process or processes.
# If there's a single process hogging the CPU in a way that seems abnormal, it's an anomalous situation
# that a service restart can fix. If there are are multiple processes taking up CPU resources, or it
# there's one process that takes lots of resources while otherwise functioning normally, than your setup
# may just be underpowered. You'll need to upgrade your server(add more cores), or split services out onto
# If there's a single process hogging the CPU in a way that seems abnormal, it's an anomalous situation
# that a service restart can fix. If there are are multiple processes taking up CPU resources, or it
# there's one process that takes lots of resources while otherwise functioning normally, than your setup
# may just be underpowered. You'll need to upgrade your server(add more cores), or split services out onto
# other boxes. In either case, you have a resolution:
# - if situation seems anomalous: kill the offending processes.
# - if situation seems typical given history: upgrade server or add more servers.
......
......@@ -22,7 +22,7 @@ from __future__ import unicode_literals
import operator
from glances.compat import u, nativestr, n, PermissionError
from glances.compat import u, nativestr, PermissionError
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
......
......@@ -88,8 +88,8 @@ class Plugin(GlancesPlugin):
stats = self.get_init_value()
if not self.nvml_ready:
# !!!
# Uncomment to test on computer without GPU
# !!!
# Uncomment to test on computer without GPU
# One GPU sample:
# self.stats = [
# {
......
......@@ -22,7 +22,6 @@
import os
import operator
from glances.logger import logger
from glances.globals import LINUX
from glances.timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
......
......@@ -126,9 +126,11 @@ class Plugin(GlancesPlugin):
# Add specifics informations
try:
# Alert and log
self.views['min15']['decoration'] = self.get_alert_log(self.stats['min15'], maximum=100 * self.stats['cpucore'])
self.views['min15']['decoration'] = self.get_alert_log(self.stats['min15'],
maximum=100 * self.stats['cpucore'])
# Alert only
self.views['min5']['decoration'] = self.get_alert(self.stats['min5'], maximum=100 * self.stats['cpucore'])
self.views['min5']['decoration'] = self.get_alert(self.stats['min5'],
maximum=100 * self.stats['cpucore'])
except KeyError:
# try/except mandatory for Windows compatibility (no load stats)
pass
......
......@@ -19,7 +19,6 @@
"""Virtual memory plugin."""
from glances.logger import logger
from glances.compat import iterkeys
from glances.plugins.glances_plugin import GlancesPlugin
......@@ -83,10 +82,15 @@ class Plugin(GlancesPlugin):
# Get all the memory stats (copy/paste of the psutil documentation)
# total: total physical memory available.
# available: the actual amount of available memory that can be given instantly to processes that request more memory in bytes; this is calculated by summing different memory values depending on the platform (e.g. free + buffers + cached on Linux) and it is supposed to be used to monitor actual memory usage in a cross platform fashion.
# available: the actual amount of available memory that can be given instantly
# to processes that request more memory in bytes; this is calculated by summing
# different memory values depending on the platform (e.g. free + buffers + cached on Linux)
# and it is supposed to be used to monitor actual memory usage in a cross platform fashion.
# percent: the percentage usage calculated as (total - available) / total * 100.
# used: memory used, calculated differently depending on the platform and designed for informational purposes only.
# free: memory not being used at all (zeroed) that is readily available; note that this doesn’t reflect the actual memory available (use ‘available’ instead).
# used: memory used, calculated differently depending on the platform and designed for informational
# purposes only.
# free: memory not being used at all (zeroed) that is readily available; note that this doesn’t
# reflect the actual memory available (use ‘available’ instead).
# Platform-specific fields:
# active: (UNIX): memory currently in use or very recently used, and so it is in RAM.
# inactive: (UNIX): memory that is marked as not used.
......
......@@ -81,7 +81,7 @@ class Plugin(GlancesPlugin):
# sout: the number of bytes the system has swapped out from disk
# (cumulative)
for swap in ['total', 'used', 'free', 'percent',
'sin', 'sout']:
'sin', 'sout']:
if hasattr(sm_stats, swap):
stats[swap] = getattr(sm_stats, swap)
elif self.input_method == 'snmp':
......
......@@ -21,11 +21,10 @@
from __future__ import unicode_literals
import base64
import operator
from glances.timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
from glances.compat import n, u, b, nativestr
from glances.compat import n
from glances.logger import logger
import psutil
......
......@@ -19,9 +19,7 @@
"""Now (current date) plugin."""
from time import tzname, localtime, strftime
from glances.globals import WINDOWS
from time import tzname, strftime
from glances.plugins.glances_plugin import GlancesPlugin
......
......@@ -19,7 +19,6 @@
"""Per-CPU plugin."""
from glances.logger import logger
from glances.cpu_percent import cpu_percent
from glances.plugins.glances_plugin import GlancesPlugin
......
......@@ -191,10 +191,10 @@ class GlancesPlugin(object):
# Stats is a list of data
# Iter throught it (for exemple, iter throught network
# interface)
for l in self.get_export():
for l_export in self.get_export():
self.stats_history.add(
nativestr(l[item_name]) + '_' + nativestr(i['name']),
l[i['name']],
nativestr(l_export[item_name]) + '_' + nativestr(i['name']),
l_export[i['name']],
description=i['description'],
history_max_size=self._limits['history_size'])
else:
......@@ -455,11 +455,11 @@ class GlancesPlugin(object):
self.views[i[self.get_key(
)]][f]['hidden'] = self.views[i[self.get_key()]][f]['_zero'] and i[f] == 0
elif isinstance(self.get_raw(), dict) and self.get_raw() is not None:
#
# Warning: This code has never been tested because
#
# Warning: This code has never been tested because
# no plugin with dict instance use the hidden function...
# vvvv
#
#
# Stats are stored in a dict (ex: CPU, LOAD...)
for key in listkeys(self.get_raw()):
if any([self.get_raw()[f] for f in self.hide_zero_fields]):
......@@ -479,7 +479,7 @@ class GlancesPlugin(object):
'optional': False, >>> Is the stat optional
'additional': False, >>> Is the stat provide additional information
'splittable': False, >>> Is the stat can be cut (like process lon name)
'hidden': False, >>> Is the stats should be hidden in the UI
'hidden': False, >>> Is the stats should be hidden in the UI
'_zero': True} >>> For internal purpose only
"""
ret = {}
......@@ -900,7 +900,11 @@ class GlancesPlugin(object):
additional: True if the stat is additional (display only if space is available after optional)
spittable: Line can be splitted to fit on the screen (default is not)
"""
return {'msg': msg, 'decoration': decoration, 'optional': optional, 'additional': additional, 'splittable': splittable}
return {'msg': msg,
'decoration': decoration,
'optional': optional,
'additional': additional,
'splittable': splittable}
def curse_new_line(self):
"""Go to a new line."""
......
......@@ -57,7 +57,8 @@ class Plugin(GlancesPlugin):
self.display_curse = True
# Init stats
self.stats = GlancesPortsList(config=config, args=args).get_ports_list() + GlancesWebList(config=config, args=args).get_web_list()
self.stats = GlancesPortsList(config=config, args=args).get_ports_list() + \
GlancesWebList(config=config, args=args).get_web_list()
# Init global Timer
self.timer_ports = Timer(0)
......@@ -333,7 +334,7 @@ class ThreadScanner(threading.Thread):
port['status'] = counter.get()
else:
port['status'] = False
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
# Correct issue #1084: No Offline status for timeouted ports
port['status'] = False
except Exception as e:
......@@ -350,7 +351,7 @@ class ThreadScanner(threading.Thread):
socket.setdefaulttimeout(port['timeout'])
_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except Exception as e:
logger.debug("{}: Error while creating scanning socket".format(self.plugin_name))
logger.debug("{}: Error while creating scanning socket ({})".format(self.plugin_name, e))
# Scan port
ip = self._resolv_name(port['host'])
......
......@@ -20,9 +20,7 @@
"""Process list plugin."""
import os
import shlex
import copy
from datetime import timedelta
from glances.logger import logger
from glances.globals import WINDOWS
......@@ -121,7 +119,9 @@ class Plugin(GlancesPlugin):
# Set the default sort key if it is defined in the configuration file
if config is not None:
if 'processlist' in config.as_dict() and 'sort_key' in config.as_dict()['processlist']:
logger.debug('Configuration overwrites processes sort key by {}'.format(config.as_dict()['processlist']['sort_key']))
logger.debug(
'Configuration overwrites processes sort key by {}'.format(
config.as_dict()['processlist']['sort_key']))
glances_processes.set_sort_key(config.as_dict()['processlist']['sort_key'], False)
# Note: 'glances_processes' is already init in the processes.py script
......@@ -254,7 +254,7 @@ class Plugin(GlancesPlugin):
try:
# Sum user and system time
user_system_time = p['cpu_times'][0] + p['cpu_times'][1]
except (OverflowError, TypeError) as e:
except (OverflowError, TypeError):
# Catch OverflowError on some Amazon EC2 server
# See https://github.com/nicolargo/glances/issues/87
# Also catch TypeError on macOS
......@@ -573,7 +573,9 @@ class Plugin(GlancesPlugin):
msg = self.layout_header['user'].format('USER')
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'username' else 'DEFAULT'))
msg = self.layout_header['time'].format('TIME+')
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'cpu_times' else 'DEFAULT', optional=True))
ret.append(self.curse_add_line(msg,
sort_style if process_sort_key == 'cpu_times' else 'DEFAULT',
optional=True))
msg = self.layout_header['thread'].format('THR')
ret.append(self.curse_add_line(msg))
msg = self.layout_header['nice'].format('NI')
......@@ -581,9 +583,15 @@ class Plugin(GlancesPlugin):
msg = self.layout_header['status'].format('S')
ret.append(self.curse_add_line(msg))
msg = self.layout_header['ior'].format('R/s')
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True, additional=True))
ret.append(self.curse_add_line(msg,
sort_style if process_sort_key == 'io_counters' else 'DEFAULT',
optional=True,
additional=True))
msg = self.layout_header['iow'].format('W/s')
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'io_counters' else 'DEFAULT', optional=True, additional=True))
ret.append(self.curse_add_line(msg,
sort_style if process_sort_key == 'io_counters' else 'DEFAULT',
optional=True,
additional=True))
msg = self.layout_header['command'].format('Command',
"('k' to kill)" if args.is_standalone else "")
ret.append(self.curse_add_line(msg, sort_style if process_sort_key == 'name' else 'DEFAULT'))
......@@ -610,14 +618,17 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg,
decoration=self.__mmm_deco(mmm)))
# VIRT and RES memory sum
if 'memory_info' in self.stats[0] and self.stats[0]['memory_info'] is not None and self.stats[0]['memory_info'] != '':
if 'memory_info' in self.stats[0] and \
self.stats[0]['memory_info'] is not None and self.stats[0]['memory_info'] != '':
# VMS
msg = self.layout_stat['virt'].format(self.auto_unit(self.__sum_stats('memory_info', indice=1, mmm=mmm), low_precision=False))
msg = self.layout_stat['virt'].format(self.auto_unit(self.__sum_stats('memory_info', indice=1, mmm=mmm),
low_precision=False))
ret.append(self.curse_add_line(msg,
decoration=self.__mmm_deco(mmm),
optional=True))
# RSS
msg = self.layout_stat['res'].format(self.auto_unit(self.__sum_stats('memory_info', indice=0, mmm=mmm), low_precision=False))
msg = self.layout_stat['res'].format(self.auto_unit(self.__sum_stats('memory_info', indice=0, mmm=mmm),
low_precision=False))
ret.append(self.curse_add_line(msg,
decoration=self.__mmm_deco(mmm),
optional=True))
......
......@@ -170,9 +170,11 @@ class Plugin(GlancesPlugin):
if not i['value']:
continue
if i['type'] == 'battery':
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(100 - i['value'], header=i['type'])
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(100 - i['value'],
header=i['type'])
else:
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(i['value'], header=i['type'])
self.views[i[self.get_key()]]['value']['decoration'] = self.get_alert(i['value'],
header=i['type'])
def msg_curse(self, args=None, max_width=None):
"""Return the dict to display in the curse interface."""
......
......@@ -200,7 +200,7 @@ class Plugin(GlancesPlugin):
for smart_stat in sorted([i for i in device_stat.keys() if i != 'DeviceName'], key=int):
ret.append(self.curse_new_line())
msg = ' {:{width}}'.format(device_stat[smart_stat]['name'][:name_max_width-1].replace('_', ' '),
width=name_max_width-1)
width=name_max_width-1)
ret.append(self.curse_add_line(msg))
msg = '{:>8}'.format(device_stat[smart_stat]['raw'])
ret.append(self.curse_add_line(msg))
......
......@@ -145,7 +145,7 @@ class Plugin(GlancesPlugin):
ret = 'WARNING'
elif value <= self.get_limit('careful', stat_name=self.plugin_name):
ret = 'CAREFUL'
except (TypeError, KeyError) as e:
except (TypeError, KeyError):
# Catch TypeError for issue1373
ret = 'DEFAULT'
......@@ -200,7 +200,8 @@ class Plugin(GlancesPlugin):
msg = '{:{width}}'.format(nativestr(hotspotname),
width=ifname_max_width)
ret.append(self.curse_add_line(msg))
msg = '{:>7}'.format(i['signal'], width=ifname_max_width)
msg = '{:>7}'.format(i['signal'],
width=ifname_max_width)
ret.append(self.curse_add_line(msg,
self.get_views(item=i[self.get_key()],
key='signal',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册