提交 af0bd377 编写于 作者: A Alessio Sergi

flake8

- import statements are in the wrong order.
- missing whitespace around arithmetic operator
- blind except: statement
- multiple imports on one line
- trailing whitespace
- blank line contains whitespace
- line break before binary operator
- missing whitespace after ','
- block comment should start with '# '
- multiple spaces before operator
- 'logger' imported but unused
- expected 2 blank lines, found 1
上级 5e5c6817
......@@ -59,6 +59,7 @@ if psutil_version < psutil_min_version:
print('PSutil 2.0 or higher is needed. Glances cannot start.')
sys.exit(1)
def __signal_handler(signal, frame):
"""Callback for CTRL-C."""
end()
......
......@@ -19,11 +19,12 @@
"""Manage on alert actions."""
# Import system lib
from subprocess import Popen
# Import Glances lib
from glances.core.glances_logging import logger
# Import system lib
from subprocess import Popen
try:
import pystache
except ImportError:
......
......@@ -19,10 +19,10 @@
"""CPU percent stats shared between CPU and Quicklook plugins."""
import psutil
from glances.core.glances_timer import Timer
import psutil
class CpuPercent(object):
......
......@@ -22,13 +22,13 @@ import collections
import os
import re
# Import psutil
import psutil
# Import Glances lib
from glances.core.glances_globals import is_bsd, is_linux, is_mac, is_windows
from glances.core.glances_logging import logger
from glances.core.glances_timer import getTimeSinceLastUpdate, Timer
from glances.core.glances_timer import Timer, getTimeSinceLastUpdate
# Import psutil
import psutil
def is_kernel_thread(proc):
......
......@@ -25,7 +25,7 @@ import re
import sys
import threading
from glances.core.glances_globals import plugins_path, exports_path, sys_path
from glances.core.glances_globals import exports_path, plugins_path, sys_path
from glances.core.glances_logging import logger
# SNMP OID regexp pattern to short system name dict
......@@ -152,7 +152,7 @@ class GlancesStats(object):
# For standalone and server modes
# For each plugins, call the update method
for p in self._plugins:
# logger.debug("Update %s stats" % p)
# logger.debug("Update %s stats" % p)
self._plugins[p].update()
def export(self, input_stats=None):
......
......@@ -80,7 +80,7 @@ class Export(GlancesExport):
# First line: header
if self.first_line:
fieldnames = item.keys()
csv_header += map(lambda x: plugin+'_'+item[item['key']]+'_'+x, item)
csv_header += map(lambda x: plugin + '_' + item[item['key']] + '_' + x, item)
# Others lines: stats
fieldvalues = item.values()
csv_data += fieldvalues
......@@ -88,7 +88,7 @@ class Export(GlancesExport):
# First line: header
if self.first_line:
fieldnames = all_stats[i].keys()
csv_header += map(lambda x: plugin+'_'+x, fieldnames)
csv_header += map(lambda x: plugin + '_' + x, fieldnames)
# Others lines: stats
fieldvalues = all_stats[i].values()
csv_data += fieldvalues
......
......@@ -103,7 +103,7 @@ class Export(GlancesExport):
password=self.password,
database=self.db)
get_all_db = [i['name'] for i in db.get_list_database()]
except:
except Exception:
logger.critical("Can not connect to InfluxDB database '%s' (%s)" % (self.db, e))
sys.exit(2)
......
......@@ -20,7 +20,9 @@
"""JMS interface class."""
# Import sys libs
import sys, socket, datetime
import datetime
import socket
import sys
from numbers import Number
# Import Glances lib
......@@ -82,7 +84,11 @@ class Export(GlancesExport):
if not self.export_enable:
return None
try:
parameters = pika.URLParameters("amqp://"+self.rabbitmq_user+":"+self.rabbitmq_password+"@"+self.rabbitmq_host+":"+self.rabbitmq_port+"/")
parameters = pika.URLParameters(
'amqp://' + self.rabbitmq_user +
':' + self.rabbitmq_password +
'@' + self.rabbitmq_host +
':' + self.rabbitmq_port + '/')
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
return channel
......@@ -92,7 +98,8 @@ class Export(GlancesExport):
def export(self, name, columns, points):
"""Write the points in RabbitMQ."""
data = "hostname="+self.hostname+", name="+name+", dateinfo="+datetime.datetime.utcnow().isoformat()
data = ('hostname=' + self.hostname + ', name=' + name +
', dateinfo=' + datetime.datetime.utcnow().isoformat())
for i in range(0, len(columns)):
if not isinstance(points[i], Number):
continue
......
......@@ -20,8 +20,8 @@
"""Manage bars for Glances output."""
# Import system lib
from math import modf
import locale
from math import modf
class Bar(object):
......
......@@ -59,12 +59,12 @@ class GlancesBottle(object):
"""Define route."""
self._app.route('/', method="GET", callback=self._index)
self._app.route('/<refresh_time:int>', method=["GET", "POST"], callback=self._index)
self._app.route('/<filename:re:.*\.css>', method="GET", callback=self._css)
self._app.route('/<filename:re:.*\.js>', method="GET", callback=self._js)
self._app.route('/<filename:re:.*\.js.map>', method="GET", callback=self._js_map)
self._app.route('/<filename:re:.*\.html>', method="GET", callback=self._html)
self._app.route('/<filename:re:.*\.png>', method="GET", callback=self._images)
self._app.route('/favicon.ico', method="GET", callback=self._favicon)
......@@ -114,7 +114,7 @@ class GlancesBottle(object):
"""Bottle callback for *.html files."""
# Return the static file
return static_file(filename, root=os.path.join(self.STATIC_PATH, 'html'))
def _css(self, filename):
"""Bottle callback for *.css files."""
# Return the static file
......@@ -134,7 +134,7 @@ class GlancesBottle(object):
"""Bottle callback for *.png files."""
# Return the static file
return static_file(filename, root=os.path.join(self.STATIC_PATH, 'images'))
def _favicon(self):
"""Bottle callback for favicon."""
# Return the static file
......@@ -153,8 +153,8 @@ class GlancesBottle(object):
plist = json.dumps(view_data, sort_keys=True)
except Exception as e:
abort(404, "Cannot get help view data (%s)" % str(e))
return plist
return plist
def _api_plugins(self):
"""
@api {get} /api/2/pluginslist Get plugins list
......@@ -204,7 +204,7 @@ class GlancesBottle(object):
if not self.args.debug:
# Update the stat
self.stats.update()
try:
# Get the JSON value of the stat ID
statval = json.dumps(self.stats.getAllAsDict())
......@@ -213,10 +213,10 @@ class GlancesBottle(object):
return statval
else:
path = "~/glances/"
if is_windows:
if is_windows:
path = "D:\\glances\\"
filepath = path + "debug.json"
f = open(filepath)
return f.read()
......
......@@ -20,8 +20,8 @@
"""Curses interface class."""
# Import system lib
import sys
import re
import sys
# Import Glances lib
from glances.core.glances_globals import is_mac, is_windows
......@@ -570,10 +570,9 @@ class _GlancesCurses(object):
# Display left sidebar (NETWORK+DISKIO+FS+SENSORS+Current time)
# ==================================================================
self.init_column()
if (not (self.args.disable_network and self.args.disable_diskio
and self.args.disable_fs and self.args.disable_raid
and self.args.disable_sensors)) \
and not self.args.disable_left_sidebar:
if not (self.args.disable_network and self.args.disable_diskio and
self.args.disable_fs and self.args.disable_raid and
self.args.disable_sensors) and not self.args.disable_left_sidebar:
self.new_line()
self.display_plugin(stats_network)
self.new_line()
......@@ -875,11 +874,11 @@ class _GlancesCurses(object):
try:
if without_option:
# Size without options
c = len(max(''.join([(re.sub(r'[^\x00-\x7F]+',' ', i['msg']) if not i['optional'] else "")
c = len(max(''.join([(re.sub(r'[^\x00-\x7F]+', ' ', i['msg']) if not i['optional'] else "")
for i in curse_msg['msgdict']]).split('\n'), key=len))
else:
# Size with all options
c = len(max(''.join([re.sub(r'[^\x00-\x7F]+',' ', i['msg'])
c = len(max(''.join([re.sub(r'[^\x00-\x7F]+', ' ', i['msg'])
for i in curse_msg['msgdict']]).split('\n'), key=len))
except Exception:
return 0
......@@ -1077,7 +1076,7 @@ class GlancesCursesBrowser(_GlancesCurses):
return False
# Display the Glances server list
#================================
# ================================
# Table of table
# Item description: [stats_id, column name, column size]
......
......@@ -19,10 +19,10 @@
"""CPU core plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
class Plugin(GlancesPlugin):
......
......@@ -19,11 +19,10 @@
"""CPU plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_cpu_percent import cpu_percent
# from glances.core.glances_logging import logger
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
......
......@@ -21,12 +21,13 @@
import operator
import psutil
# Import Glances libs
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# Define the history items list
# All items in this list will be historised if the --enable-history tag is set
# 'color' define the graph color in #RGB format
......
......@@ -24,8 +24,8 @@ import os
import re
# Import Glances libs
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.core.glances_logging import logger
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
# Docker-py library (optional and Linux-only)
......@@ -172,7 +172,7 @@ class Plugin(GlancesPlugin):
try:
# self.docker_stats[c['Id']] = self.docker_client.stats(c['Id'], decode=True)
all_stats = self.docker_stats[c['Id']].next()
except:
except Exception:
all_stats = {}
c['cpu'] = self.get_docker_cpu(c['Id'], all_stats)
......
......@@ -21,9 +21,10 @@
import operator
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
# SNMP OID
# The snmpd.conf needs to be edited.
......
......@@ -24,8 +24,8 @@ import os
import socket
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_logging import logger
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
......
......@@ -61,36 +61,36 @@ class Plugin(GlancesPlugin):
msg_col = ' {0:1} {1:35}'
msg_col2 = ' {0:1} {1:35}'
self.view_data['sort_auto'] = msg_col.format("a", 'Sort processes automatically')
self.view_data['sort_network'] = msg_col2.format("b", 'Bytes or bits for network I/O')
self.view_data['sort_cpu'] = msg_col.format("c", 'Sort processes by CPU%')
self.view_data['show_hide_alert'] = msg_col2.format("l", 'Show/hide alert logs')
self.view_data['sort_mem'] = msg_col.format("m", 'Sort processes by MEM%')
self.view_data['sort_user'] = msg_col.format("u", 'Sort processes by USER')
self.view_data['delete_warning_alerts'] = msg_col2.format("w", 'Delete warning alerts')
self.view_data['sort_proc'] = msg_col.format("p", 'Sort processes by name')
self.view_data['delete_warning_critical_alerts'] = msg_col2.format("x", 'Delete warning and critical alerts')
self.view_data['sort_io'] = msg_col.format("i", 'Sort processes by I/O rate')
self.view_data['percpu'] = msg_col2.format("1", 'Global CPU or per-CPU stats')
self.view_data['sort_cpu_times'] = msg_col.format("t", 'Sort processes by TIME')
self.view_data['show_hide_help'] = msg_col2.format("h", 'Show/hide this help screen')
self.view_data['show_hide_diskio'] = msg_col.format("d", 'Show/hide disk I/O stats')
self.view_data['view_network_io_combination'] = msg_col2.format("T", 'View network I/O as combination')
self.view_data['show_hide_filesystem'] = msg_col.format("f", 'Show/hide filesystem stats')
self.view_data['view_cumulative_network'] = msg_col2.format("U", 'View cumulative network I/O')
self.view_data['show_hide_network'] = msg_col.format("n", 'Show/hide network stats')
self.view_data['show_hide_filesytem_freespace'] = msg_col2.format("F", 'Show filesystem free space')
self.view_data['show_hide_sensors'] = msg_col.format("s", 'Show/hide sensors stats')
self.view_data['generate_graphs'] = msg_col2.format("g", 'Generate graphs for current history')
self.view_data['show_hide_left_sidebar'] = msg_col.format("2", 'Show/hide left sidebar')
self.view_data['reset_history'] = msg_col2.format("r", 'Reset history')
self.view_data['enable_disable_process_stats'] = msg_col.format("z", 'Enable/disable processes stats')
self.view_data['quit'] = msg_col2.format("q", 'Quit (Esc and Ctrl-C also work)')
self.view_data['enable_disable_top_extends_stats'] = msg_col.format("e", 'Enable/disable top extended stats')
self.view_data['enable_disable_short_processname'] = msg_col.format("/", 'Enable/disable short processes name')
self.view_data['enable_disable_docker'] = msg_col2.format("D", 'Enable/disable Docker stats')
self.view_data['enable_disable_quick_look'] = msg_col.format("3", 'Enable/disable quick look plugin')
self.view_data['edit_pattern_filter'] = '{0}: {1}'.format("ENTER", 'Edit the process filter pattern')
self.view_data['sort_auto'] = msg_col.format('a', 'Sort processes automatically')
self.view_data['sort_network'] = msg_col2.format('b', 'Bytes or bits for network I/O')
self.view_data['sort_cpu'] = msg_col.format('c', 'Sort processes by CPU%')
self.view_data['show_hide_alert'] = msg_col2.format('l', 'Show/hide alert logs')
self.view_data['sort_mem'] = msg_col.format('m', 'Sort processes by MEM%')
self.view_data['sort_user'] = msg_col.format('u', 'Sort processes by USER')
self.view_data['delete_warning_alerts'] = msg_col2.format('w', 'Delete warning alerts')
self.view_data['sort_proc'] = msg_col.format('p', 'Sort processes by name')
self.view_data['delete_warning_critical_alerts'] = msg_col2.format('x', 'Delete warning and critical alerts')
self.view_data['sort_io'] = msg_col.format('i', 'Sort processes by I/O rate')
self.view_data['percpu'] = msg_col2.format('1', 'Global CPU or per-CPU stats')
self.view_data['sort_cpu_times'] = msg_col.format('t', 'Sort processes by TIME')
self.view_data['show_hide_help'] = msg_col2.format('h', 'Show/hide this help screen')
self.view_data['show_hide_diskio'] = msg_col.format('d', 'Show/hide disk I/O stats')
self.view_data['view_network_io_combination'] = msg_col2.format('T', 'View network I/O as combination')
self.view_data['show_hide_filesystem'] = msg_col.format('f', 'Show/hide filesystem stats')
self.view_data['view_cumulative_network'] = msg_col2.format('U', 'View cumulative network I/O')
self.view_data['show_hide_network'] = msg_col.format('n', 'Show/hide network stats')
self.view_data['show_hide_filesytem_freespace'] = msg_col2.format('F', 'Show filesystem free space')
self.view_data['show_hide_sensors'] = msg_col.format('s', 'Show/hide sensors stats')
self.view_data['generate_graphs'] = msg_col2.format('g', 'Generate graphs for current history')
self.view_data['show_hide_left_sidebar'] = msg_col.format('2', 'Show/hide left sidebar')
self.view_data['reset_history'] = msg_col2.format('r', 'Reset history')
self.view_data['enable_disable_process_stats'] = msg_col.format('z', 'Enable/disable processes stats')
self.view_data['quit'] = msg_col2.format('q', 'Quit (Esc and Ctrl-C also work)')
self.view_data['enable_disable_top_extends_stats'] = msg_col.format('e', 'Enable/disable top extended stats')
self.view_data['enable_disable_short_processname'] = msg_col.format('/', 'Enable/disable short processes name')
self.view_data['enable_disable_docker'] = msg_col2.format('D', 'Enable/disable Docker stats')
self.view_data['enable_disable_quick_look'] = msg_col.format('3', 'Enable/disable quick look plugin')
self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern'
def get_view_data(self, args=None):
return self.view_data
......
......@@ -19,10 +19,10 @@
"""Virtual memory plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
# Total RAM used: .1.3.6.1.4.1.2021.4.6.0
......@@ -123,7 +123,7 @@ class Plugin(GlancesPlugin):
self.reset()
else:
for fs in fs_stat:
# The Physical Memory (Windows) or Real Memory (VmWare)
# The Physical Memory (Windows) or Real Memory (VMware)
# gives statistics on RAM usage and availability.
if fs in ('Physical Memory', 'Real Memory'):
self.stats['total'] = int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
......
......@@ -19,10 +19,10 @@
"""Swap memory plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
# Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
......@@ -95,9 +95,10 @@ class Plugin(GlancesPlugin):
self.reset()
else:
for fs in fs_stat:
# The virtual memory concept is used by the operating system to extend (virtually) the physical
# memory and thus to run more programs by swapping
# unused memory zone (page) to a disk file.
# The virtual memory concept is used by the operating
# system to extend (virtually) the physical memory and
# thus to run more programs by swapping unused memory
# zone (page) to a disk file.
if fs == 'Virtual Memory':
self.stats['total'] = int(
fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit'])
......
......@@ -20,7 +20,6 @@
"""Monitor plugin."""
# Import Glances lib
from glances.core.glances_logging import logger
from glances.core.glances_monitor_list import MonitorList as glancesMonitorList
from glances.plugins.glances_plugin import GlancesPlugin
......
......@@ -22,11 +22,11 @@
import base64
import operator
import psutil
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
# SNMP OID
# http://www.net-snmp.org/docs/mibs/interfaces.html
# Dict key = interface_name
......@@ -269,20 +269,20 @@ class Plugin(GlancesPlugin):
if args.network_cumul:
rx = self.auto_unit(int(i['cumulative_rx']))
tx = self.auto_unit(int(i['cumulative_tx']))
sx = self.auto_unit(int(i['cumulative_tx'])
+ int(i['cumulative_tx']))
sx = self.auto_unit(int(i['cumulative_tx']) +
int(i['cumulative_tx']))
else:
rx = self.auto_unit(int(i['rx'] // i['time_since_update']))
tx = self.auto_unit(int(i['tx'] // i['time_since_update']))
sx = self.auto_unit(int(i['rx'] // i['time_since_update'])
+ int(i['tx'] // i['time_since_update']))
sx = self.auto_unit(int(i['rx'] // i['time_since_update']) +
int(i['tx'] // i['time_since_update']))
else:
# Bits per second (for real network administrator | Default)
if args.network_cumul:
rx = self.auto_unit(int(i['cumulative_rx'] * 8)) + "b"
tx = self.auto_unit(int(i['cumulative_tx'] * 8)) + "b"
sx = self.auto_unit(int(i['cumulative_rx'] * 8)
+ int(i['cumulative_tx'] * 8)) + "b"
sx = self.auto_unit(int(i['cumulative_rx'] * 8) +
int(i['cumulative_tx'] * 8)) + "b"
else:
rx = self.auto_unit(int(i['rx'] // i['time_since_update'] * 8)) + "b"
tx = self.auto_unit(int(i['tx'] // i['time_since_update'] * 8)) + "b"
......
......@@ -19,10 +19,10 @@
"""Per-CPU plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
class Plugin(GlancesPlugin):
......
......@@ -29,10 +29,10 @@ from datetime import datetime
from operator import itemgetter
# Import Glances lib
from glances.core.glances_actions import GlancesActions
from glances.core.glances_globals import is_py3
from glances.core.glances_logging import logger
from glances.core.glances_logs import glances_logs
from glances.core.glances_actions import GlancesActions
class GlancesPlugin(object):
......
......@@ -17,10 +17,10 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from psutil import __version__ as __psutil_version
from glances.plugins.glances_plugin import GlancesPlugin
from psutil import __version__ as __psutil_version
class Plugin(GlancesPlugin):
......
......@@ -19,12 +19,11 @@
"""Quicklook plugin."""
import psutil
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_cpu_percent import cpu_percent
from glances.outputs.glances_bars import Bar
#from glances.core.glances_logging import logger
from glances.plugins.glances_plugin import GlancesPlugin
import psutil
class Plugin(GlancesPlugin):
......
......@@ -22,12 +22,12 @@
# Import system libs
from datetime import datetime, timedelta
# Import psutil
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
# Import psutil
import psutil
# SNMP OID
snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册