Complete overhaul of imports

Explicit is better than implicit.
This commit is contained in:
Alessio Sergi 2014-04-17 17:04:04 +02:00
parent db37ff4ad2
commit b7bbd69a65
30 changed files with 151 additions and 198 deletions

View File

@ -21,8 +21,8 @@ Init the Glances software
"""
# Import system lib
import sys
import signal
import sys
# Import Glances libs
# Note: others Glances libs will be imported optionnaly

View File

@ -17,25 +17,22 @@
# 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/>.
"""
Manage the Glances' client
Manage the Glances' client
"""
# Import system libs
import sys
import socket
import json
import socket
import sys
try:
from xmlrpc.client import ServerProxy, ProtocolError
except ImportError: # Python 2
from xmlrpclib import ServerProxy, ProtocolError
# Import Glances libs
from glances.core.glances_globals import __version__
from glances.outputs.glances_curses import glancesCurses
from glances.core.glances_stats import GlancesStatsClient
try:
# Python 2
from xmlrpclib import ServerProxy, ProtocolError
except ImportError:
# Python 3
from xmlrpc.client import ServerProxy, ProtocolError
from glances.outputs.glances_curses import glancesCurses
class GlancesClient():
@ -86,7 +83,7 @@ class GlancesClient():
self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
# Load limits from the configuration file
# Each client can choose its owns limits
# Each client can choose its owns limits
self.stats.load_limits(self.config)
# Init screen
@ -104,7 +101,7 @@ class GlancesClient():
Return the client/server connection status:
- Connected: Connection OK
- Disconnected: Connection NOK
"""
"""
# Update the stats
try:
server_stats = json.loads(self.client.getAll())

View File

@ -17,24 +17,25 @@
# 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/>.
__appname__ = 'glances'
# Import Glances lib
from glances.core.glances_globals import *
# Import system libs
import os
try:
# Python 2
from ConfigParser import RawConfigParser
from ConfigParser import NoOptionError
except ImportError:
# Python 3
from configparser import RawConfigParser
from configparser import NoOptionError
except ImportError: # Python 2
from ConfigParser import RawConfigParser
from ConfigParser import NoOptionError
# Import Glances lib
from glances.core.glances_globals import (
__appname__,
is_Linux,
is_python3,
work_path
)
class Config:
class Config(object):
"""
This class is used to access/read config file, if it exists

View File

@ -19,31 +19,31 @@
# Glances informations
__appname__ = 'glances'
__version__ = "2.0_Alpha02"
__author__ = "Nicolas Hennion <nicolas@nicolargo.com>"
__license__ = "LGPL"
__version__ = '2.0_Alpha02'
__author__ = 'Nicolas Hennion <nicolas@nicolargo.com>'
__license__ = 'LGPL'
# Import system libs
import sys
import os
import gettext
import locale
import os
import sys
# Import PsUtil
# Import psutil
try:
from psutil import __version__ as __psutil_version__
except ImportError:
print('PsUtil module not found. Glances cannot start.')
print('psutil module not found. Glances cannot start.')
sys.exit(1)
# PSutil version
# psutil version
psutil_version = tuple([int(num) for num in __psutil_version__.split('.')])
# Check PsUtil version
# Check psutil version
psutil_min_version = (2, 0, 0)
if (psutil_version < psutil_min_version):
print('PsUtil version %s detected.' % __psutil_version__)
print('PsUtil 2.0 or higher is needed. Glances cannot start.')
print('psutil version %s detected.' % __psutil_version__)
print('psutil 2.0 or higher is needed. Glances cannot start.')
sys.exit(1)
# Path definitions
@ -75,8 +75,8 @@ else:
locale_dir = None
gettext.install(gettext_domain, locale_dir)
# Instances shared between all Glances's scripts
#===============================================
# Instances shared between all Glances' scripts
# ===============================================
# glances_processes for processcount and processlist plugins
from glances.core.glances_processes import glancesProcesses

View File

@ -18,8 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import system libs
import time
from datetime import datetime
import time
# Import Glances libs
from glances.core.glances_globals import glances_processes
@ -34,9 +34,9 @@ class glancesLogs:
item_type = "CPU*|LOAD|MEM|MON"
item_value = value
Item is defined by:
["begin",
"end",
"WARNING|CRITICAL",
["begin",
"end",
"WARNING|CRITICAL",
"CPU|LOAD|MEM",
MAX, AVG, MIN, SUM, COUNT,
[top3 process list],
@ -71,7 +71,7 @@ class glancesLogs:
An item exist in the list if:
* end is < 0
* item_type is matching
Return the item position if exist
Return the item position if exist
-1 if the item is not found
"""
for i in range(self.len()):
@ -138,7 +138,7 @@ class glancesLogs:
item.append(item_value) # MIN
item.append(item_value) # SUM
item.append(1) # COUNT
# Process list is sorted automaticaly
# Process list is sorted automaticaly
# Overwrite the user choise
# topprocess = sorted(proc_list, key=lambda process: process[process_auto_by],
# reverse=True)

View File

@ -21,15 +21,16 @@ Main Glances script
"""
# Import system libs
import sys
import os
import argparse
import sys
# Import Glances libs
from glances.core.glances_globals import __appname__, __version__, __author__, __license__
from glances.core.glances_globals import *
# !!! Todo: rename class
from glances.core.glances_config import Config
from glances.core.glances_globals import (
__appname__,
__psutil_version__,
__version__
)
class GlancesMain(object):
@ -41,7 +42,7 @@ class GlancesMain(object):
refresh_time = 3
# Set the default cache lifetime to 1 second (only for server)
# !!! Todo: configuration from the command line
cached_time = 1
cached_time = 1
# Default network bitrate is display in bit per second
network_bytepersec_tag = False
# Display (or not) module
@ -51,7 +52,7 @@ class GlancesMain(object):
# network_tag = True
# sensors_tag = True
# process_tag = True
# Display property
# Display property
use_bold = True
percpu_tag = False
# Default configuration file
@ -62,7 +63,7 @@ class GlancesMain(object):
# By default, Glances is ran in standalone mode (no client/server)
client_tag = False
server_tag = False
# Server IP address (no default value)
# Server IP address (no default value)
server_ip = None
# Server TCP port number (default is 61209)
server_port = 61209
@ -76,7 +77,6 @@ class GlancesMain(object):
output_file = None
output_folder = None
def __init__(self):
# Init and manage command line arguments
self.init_arg()
@ -92,7 +92,6 @@ class GlancesMain(object):
# Load the configuration file
self.config.load()
def init_arg(self):
"""
Init all the command line arguments
@ -103,55 +102,55 @@ class GlancesMain(object):
description='Glances, an eye on your system.')
# Version
self.parser.add_argument('-v', '--version',
action='version',
version=_('%s v%s with PsUtil v%s')
% (__appname__.capitalize(), __version__, psutil_version))
self.parser.add_argument('-v', '--version',
action='version',
version=_('%s v%s with PsUtil v%s')
% (__appname__.capitalize(), __version__, __psutil_version__))
# Client mode: set the client IP/name
self.parser.add_argument('-C', '--config',
help=_('path to the configuration file'))
# Refresh time
self.parser.add_argument('-t', '--time',
help=_('set refresh time in seconds (default: %s sec)') % self.refresh_time,
help=_('set refresh time in seconds (default: %s sec)') % self.refresh_time,
type=int)
# Network bitrate in byte per second (default is bit per second)
self.parser.add_argument('-b', '--byte',
help=_('display network rate in byte per second (default is bit per second)'),
help=_('display network rate in byte per second (default is bit per second)'),
action='store_true')
# Disable DiskIO module
self.parser.add_argument('--disable_diskio',
help=_('disable disk I/O module'),
help=_('disable disk I/O module'),
action='store_true')
# Disable mount module
self.parser.add_argument('--disable_fs',
help=_('disable file system (mount) module'),
help=_('disable file system (mount) module'),
action='store_true')
# Disable network module
self.parser.add_argument('--disable_network',
help=_('disable network module'),
help=_('disable network module'),
action='store_true')
# Enable sensors module
self.parser.add_argument('--disable_sensors',
help=_('disable sensors module'),
help=_('disable sensors module'),
action='store_true')
# Disable process module
self.parser.add_argument('--disable_process',
help=_('disable process module'),
help=_('disable process module'),
action='store_true')
# Disable log module
self.parser.add_argument('--disable_log',
help=_('disable log module'),
help=_('disable log module'),
action='store_true')
# Bold attribute for Curse display (not supported by all terminal)
self.parser.add_argument('-z', '--no_bold',
help=_('disable bold mode in the terminal'),
help=_('disable bold mode in the terminal'),
action='store_false')
# Per CPU display tag
self.parser.add_argument('-1', '--percpu',
help=_('start Glances in per CPU mode)'),
help=_('start Glances in per CPU mode)'),
action='store_true')
# Client mode: set the client IP/name
@ -170,7 +169,7 @@ class GlancesMain(object):
help=_('bind server to the given IPv4/IPv6 address or hostname'))
# Server TCP port
self.parser.add_argument('-p', '--port',
help=_('define the server TCP port (default: %d)') % self.server_port,
help=_('define the server TCP port (default: %d)') % self.server_port,
type=int)
# Password as an argument
self.parser.add_argument('-P', '--password_arg',
@ -182,7 +181,7 @@ class GlancesMain(object):
# Output type
self.parser.add_argument('-o', '--output',
help=_('define additional output %s') % self.output_list,
help=_('define additional output %s') % self.output_list,
choices=self.output_list)
# Define output type flag to False (default is no output)
for o in self.output_list:
@ -191,7 +190,6 @@ class GlancesMain(object):
self.parser.add_argument('-f', '--file',
help=_('set the html output folder or csv file'))
def parse_arg(self):
"""
Parse command line argument
@ -202,13 +200,13 @@ class GlancesMain(object):
# Default refresh time:
# - is 3 seconds for CLI
# - is 5 seconds for Web (Bottle)
if (args.time is None):
if (args.time is None):
if (args.webserver):
args.time = 5
else:
args.time = 3
# !!! Usefull ? Default refresh time
if (args.time is not None): self.refresh_time = args.time
if (args.time is not None): self.refresh_time = args.time
# By default Help is hidden
args.help_tag = False
@ -218,9 +216,9 @@ class GlancesMain(object):
args.network_cumul = False
# Bind address/port
if (args.bind is None):
args.bind = self.bind_ip
if (args.port is None):
if (args.bind is None):
args.bind = self.bind_ip
if (args.port is None):
if (args.webserver):
args.port = self.web_server_port
else:
@ -231,17 +229,17 @@ class GlancesMain(object):
# Server or client login/password
args.username = self.username
if (args.password_arg is not None):
# Password is passed as an argument
# Password is passed as an argument
args.password = args.password_arg
elif (args.password):
# Interactive password
if (args.server):
if (args.server):
args.password = self.__get_password(
description=_("Define the password for the Glances server"),
description=_("Define the password for the Glances server"),
confirm=True)
elif (args.client):
args.password = self.__get_password(
description=_("Enter the Glances server password"),
description=_("Enter the Glances server password"),
confirm=False)
else:
# Default is no password
@ -266,7 +264,6 @@ class GlancesMain(object):
return args
def __get_password(self, description='', confirm=False):
"""
Read a password from the command line (with confirmation if confirm = True)
@ -288,21 +285,18 @@ class GlancesMain(object):
sys.stdout.write(_("[Warning] Passwords did not match, please try again...\n"))
return self.__get_password(description=description, confirm=confirm)
def is_standalone(self):
"""
Return True if Glances is running in standalone mode
"""
return not self.client_tag and not self.server_tag and not self.webserver_tag
def is_client(self):
"""
Return True if Glances is running in client mode
"""
return self.client_tag and not self.server_tag
def is_server(self):
"""
Return True if Glances is running in server mode
@ -325,4 +319,4 @@ class GlancesMain(object):
"""
Return the arguments
"""
return self.args
return self.args

View File

@ -50,7 +50,7 @@ class monitorList:
self.config = config
if ((self.config != None)
if ((self.config != None)
and self.config.has_section('monitor')):
# Process monitoring list
self.__setMonitorList('monitor', 'list')

View File

@ -17,8 +17,7 @@
# 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/>.
# Import system lib
from psutil import process_iter, AccessDenied, NoSuchProcess
import psutil
# Import Glances lib
from glances.core.glances_globals import is_BSD, is_Mac, is_Windows
@ -136,7 +135,7 @@ class glancesProcesses:
# Get the process IO counters
proc_io = proc.io_counters()
io_new = [proc_io.read_bytes, proc_io.write_bytes]
except AccessDenied:
except psutil.AccessDenied:
# Access denied to process IO (no root account)
# Put 0 in all values (for sort) and io_tag = 0 (for display)
procstat['io_counters'] = [0, 0] + [0, 0]
@ -174,7 +173,7 @@ class glancesProcesses:
time_since_update = getTimeSinceLastUpdate('process_disk')
# For each existing process...
for proc in process_iter():
for proc in psutil.process_iter():
try:
# Get stats using the PSUtil
procstat = self.__get_process_stats(proc)
@ -200,7 +199,7 @@ class glancesProcesses:
self.processcount['thread'] += proc.num_threads()
except:
pass
except (NoSuchProcess, AccessDenied):
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
else:
# Update processlist

View File

@ -18,34 +18,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import system libs
import sys
import socket
import json
from base64 import b64decode
from hashlib import md5
import json
import socket
import sys
try:
from xmlrpc.server import SimpleXMLRPCRequestHandler
from xmlrpc.server import SimpleXMLRPCServer
except ImportError: # Python 2
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
from SimpleXMLRPCServer import SimpleXMLRPCServer
# Import Glances libs
from glances.core.glances_globals import __version__
from glances.core.glances_stats import GlancesStatsServer
from glances.core.glances_timer import Timer
# Other imports
try:
# Python 2
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
from SimpleXMLRPCServer import SimpleXMLRPCServer
except ImportError:
# Python 3
from xmlrpc.server import SimpleXMLRPCRequestHandler
from xmlrpc.server import SimpleXMLRPCServer
try:
# Python 2
from xmlrpclib import ServerProxy, ProtocolError
except ImportError:
# Python 3
from xmlrpc.client import ServerProxy, ProtocolError
class GlancesXMLRPCHandler(SimpleXMLRPCRequestHandler):
"""

View File

@ -17,13 +17,9 @@
# 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/>.
# Import system libs
import collections
import os
import sys
import collections
# Import Glances libs
from glances.core.glances_globals import *
class GlancesStats(object):
@ -182,7 +178,7 @@ class GlancesStatsClient(GlancesStats):
This class store, update and give stats for the client
"""
def __init__(self):
def __init__(self):
# Init the plugin list dict
self._plugins = collections.defaultdict(dict)

View File

@ -17,19 +17,15 @@
# 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/>.
# Import system lib
import os
import sys
try:
from bottle import Bottle, template, static_file, TEMPLATE_PATH
except ImportError:
print('Bottle module not found. Glances cannot start in web server mode.')
sys.exit(1)
# Import Glances lib
from glances.core.glances_timer import Timer
from glances.core.glances_globals import glances_logs, glances_processes
class glancesBottle:
"""
@ -103,7 +99,7 @@ class glancesBottle:
# Update the stat
self.stats.update()
# Display
return self.display(self.stats, refresh_time=refresh_time)
@ -183,13 +179,13 @@ class glancesBottle:
if (m['splittable']):
tpl += '<span></span>'
continue
tpl += '<span class="cell" id="%s">%s</span>' % (self.__style_list[m['decoration']] ,
tpl += '<span class="cell" id="%s">%s</span>' % (self.__style_list[m['decoration']] ,
m['msg'].replace(' ', '&nbsp;'))
tpl += '</div>'
tpl += '</div>'
tpl += """ \
</article>
</article>
%#End Template for Bottle
"""
return template(tpl)
return template(tpl)

View File

@ -17,8 +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/>.
# Import system lib
import sys
import threading
import msvcrt
try:
import colorconsole
import colorconsole.terminal
@ -26,12 +28,10 @@ except ImportError:
print('Colorconsole module not found. Glances cannot start in standalone mode.')
sys.exit(1)
import msvcrt
import threading
try:
import Queue as queue
except ImportError:
import queue
except ImportError: # Python 2
import Queue as queue
class ListenGetch(threading.Thread):

View File

@ -21,11 +21,11 @@
import sys
# Import Glances lib
from glances.core.glances_timer import Timer
from glances.core.glances_globals import glances_logs, glances_processes, is_Windows
from glances.core.glances_timer import Timer
# Import curses lib for "normal" operating system and consolelog for Windows
if (not is_Windows):
if not is_Windows:
try:
import curses
import curses.panel

View File

@ -21,8 +21,8 @@
from datetime import datetime
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_globals import glances_logs
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):

View File

@ -20,8 +20,7 @@
Batinfo (batterie) plugin
"""
# Import system libs
# batinfo library (optional; Linux-only)
# Batinfo library (optional; Linux-only)
try:
import batinfo
except ImportError:

View File

@ -17,11 +17,8 @@
# 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/>.
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import cpu_count
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
@ -55,8 +52,8 @@ class Plugin(GlancesPlugin):
# Return None if undefine
core_stats = {}
try:
core_stats["phys"] = cpu_count(logical=False)
core_stats["log"] = cpu_count()
core_stats["phys"] = psutil.cpu_count(logical=False)
core_stats["log"] = psutil.cpu_count()
except NameError:
core_stats = None

View File

@ -20,11 +20,8 @@
Glances CPU plugin
"""
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import cpu_times_percent
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
@ -57,7 +54,7 @@ class Plugin(GlancesPlugin):
"""
# Grab CPU using the PSUtil cpu_times_percent method
cputimespercent = cpu_times_percent(interval=0.0, percpu=False)
cputimespercent = psutil.cpu_times_percent(interval=0.0, percpu=False)
# Get all possible value for CPU stats
# user

View File

@ -20,12 +20,11 @@
Glances CPU plugin
"""
# Import system lib
from psutil import disk_io_counters
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
@ -62,7 +61,7 @@ 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 = disk_io_counters(perdisk=True)
diskiocounters = psutil.disk_io_counters(perdisk=True)
# Previous disk IO stats are stored in the diskio_old variable
diskio = []

View File

@ -17,10 +17,8 @@
# 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/>.
# Import system lib
from psutil import disk_partitions, disk_usage
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
@ -46,16 +44,16 @@ class glancesGrabFs:
fs_list = []
# Grab the stats using the PsUtil disk_partitions
# If 'all'=False return physical devices only (e.g. hard disks, cd-rom drives, USB keys)
# 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)
fs_stat = disk_partitions(all=False)
fs_stat = psutil.disk_partitions(all=False)
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
fs_usage = disk_usage(fs_current['mnt_point'])
fs_usage = psutil.disk_usage(fs_current['mnt_point'])
fs_current['size'] = fs_usage.total
fs_current['used'] = fs_usage.used
fs_current['avail'] = fs_usage.free
@ -128,7 +126,7 @@ class Plugin(GlancesPlugin):
# New line
ret.append(self.curse_new_line())
if ((len(i['mnt_point']) + len(i['device_name'].split('/')[-1])) <= 6):
# If possible concatenate mode info... Glances touch inside :)
# If possible concatenate mode info... Glances touch inside :)
mnt_point = i['mnt_point'] + ' (' + i['device_name'].split('/')[-1] + ')'
elif (len(i['mnt_point']) > 9):
# Cut mount point name if it is too long

View File

@ -22,8 +22,12 @@ Just a stupid plugin to display the help screen
"""
# Import Glances libs
from glances.core.glances_globals import (
__appname__,
__psutil_version__,
__version__
)
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_globals import __appname__, __version__, __psutil_version__
class Plugin(GlancesPlugin):

View File

@ -21,11 +21,11 @@ Glances load plugin
"""
# Import system libs
from os import getloadavg
import os
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.plugins.glances_core import Plugin as CorePlugin
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
@ -60,7 +60,7 @@ class Plugin(GlancesPlugin):
# Get the load using the os standard lib
try:
load = getloadavg()
load = os.getloadavg()
except OSError:
self.stats = {}
else:

View File

@ -20,11 +20,8 @@
Glances virtual memory plugin
"""
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import virtual_memory
import psutil
# from ..plugins.glances_plugin import GlancesPlugin
from glances.plugins.glances_plugin import GlancesPlugin
@ -53,7 +50,7 @@ class Plugin(GlancesPlugin):
"""
# Grab MEM using the PSUtil virtual_memory method
vm_stats = virtual_memory()
vm_stats = psutil.virtual_memory()
# Get all the memory stats (copy/paste of the PsUtil documentation)
# total: total physical memory available.

View File

@ -20,11 +20,8 @@
Glances swap memory plugin
"""
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import swap_memory
import psutil
# from ..plugins.glances_plugin import GlancesPlugin
from glances.plugins.glances_plugin import GlancesPlugin
@ -53,7 +50,7 @@ class Plugin(GlancesPlugin):
"""
# Grab SWAP using the PSUtil swap_memory method
sm_stats = swap_memory()
sm_stats = psutil.swap_memory()
# Get all the swap stats (copy/paste of the PsUtil documentation)
# total: total swap memory in bytes
@ -105,7 +102,7 @@ class Plugin(GlancesPlugin):
ret.append(self.curse_add_line(msg))
msg = "{0:>6}".format(self.auto_unit(self.stats['used']))
ret.append(self.curse_add_line(
msg, self.get_alert_log(self.stats['used'],
msg, self.get_alert_log(self.stats['used'],
max=self.stats['total'])))
# New line
ret.append(self.curse_new_line())

View File

@ -18,8 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import Glances lib
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_monitor_list import monitorList as glancesMonitorList
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):

View File

@ -21,11 +21,11 @@ Glances Network interface plugin
"""
# Import system libs
from psutil import net_io_counters
import psutil
# Import Glances lib
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
@ -50,7 +50,6 @@ class Plugin(GlancesPlugin):
# Init stats
self.network_old = []
def update(self):
"""
Update network stats
@ -58,7 +57,7 @@ class Plugin(GlancesPlugin):
"""
# Grab network interface stat using the PsUtil net_io_counter method
netiocounters = net_io_counters(pernic=True)
netiocounters = psutil.net_io_counters(pernic=True)
# Previous network interface stats are stored in the network_old variable
network = []
@ -142,7 +141,7 @@ class Plugin(GlancesPlugin):
msg = "{0:>7}".format(_("Rx/s"))
ret.append(self.curse_add_line(msg))
msg = "{0:>7}".format(_("Tx/s"))
ret.append(self.curse_add_line(msg))
ret.append(self.curse_add_line(msg))
# Interface list (sorted by name)
for i in sorted(self.stats, key=lambda network: network['interface_name']):
# Do not display hidden interfaces
@ -154,22 +153,22 @@ 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'])
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'])
sx = self.auto_unit(int(i['rx'] // i['time_since_update'])
+ int(i['tx'] // i['time_since_update']))
else:
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)
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"
tx = self.auto_unit(int(i['tx'] // i['time_since_update'] * 8)) + "b"
sx = self.auto_unit(int(i['rx'] // i['time_since_update'] * 8) +
int(i['tx'] // i['time_since_update'] * 8)) + "b"
# New line

View File

@ -20,9 +20,8 @@
CPU stats (per cpu)
"""
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import cpu_times
# Check for psutil already done in the glances_core script
import psutil
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
@ -58,7 +57,7 @@ class Plugin(GlancesPlugin):
"""
# Grab CPU using the PSUtil cpu_times method
# Per-CPU
percputime = cpu_times(percpu=True)
percputime = psutil.cpu_times(percpu=True)
percputime_total = []
for i in range(len(percputime)):
percputime_total.append(percputime[i].user +

View File

@ -18,8 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_globals import glances_processes
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):

View File

@ -21,8 +21,8 @@
from datetime import timedelta
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin
from glances.core.glances_globals import glances_processes
from glances.plugins.glances_plugin import GlancesPlugin
class Plugin(GlancesPlugin):
@ -74,7 +74,7 @@ class Plugin(GlancesPlugin):
try:
args.process_sorted_by
except AttributeError:
args.process_sorted_by = glances_processes.getsortkey()
args.process_sorted_by = glances_processes.getsortkey()
if (args.process_sorted_by == 'auto'):
process_sort_key = glances_processes.getsortkey()
else:
@ -224,4 +224,4 @@ class Plugin(GlancesPlugin):
self.stats = listsorted
return self.stats
return self.stats

View File

@ -17,11 +17,8 @@
# 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/>.
# Import system libs
# Check for PSUtil already done in the glances_core script
from psutil import __version__ as __psutil_version__
# Import Glances libs
from glances.plugins.glances_plugin import GlancesPlugin

View File

@ -17,8 +17,7 @@
# 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/>.
# Import system libs
# sensors library (optional; Linux-only)
# Sensors library (optional; Linux-only)
try:
import sensors
except ImportError:
@ -28,7 +27,6 @@ except ImportError:
from glances.core.glances_globals import is_python3
from glances.plugins.glances_hddtemp import Plugin as HddTempPlugin
from glances.plugins.glances_plugin import GlancesPlugin
# from glances.core.glances_timer import getTimeSinceLastUpdate
class glancesGrabSensors: