mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-05 08:39:15 +03:00
Docstings of plugins are now PEP 257 compliant
This commit is contained in:
parent
1114e1289c
commit
00386aa164
@ -23,7 +23,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from glances.logs import glances_logs
|
from glances.logs import glances_logs
|
||||||
from glances.thresholds import glances_thresholds
|
from glances.thresholds import glances_thresholds
|
||||||
from glances.logger import logger
|
# from glances.logger import logger
|
||||||
from glances.plugins.glances_plugin import GlancesPlugin
|
from glances.plugins.glances_plugin import GlancesPlugin
|
||||||
|
|
||||||
# Static decision tree for the global alert message
|
# Static decision tree for the global alert message
|
||||||
@ -61,8 +61,10 @@ tree = [{'msg': 'No warning or critical alert detected',
|
|||||||
|
|
||||||
|
|
||||||
def global_message():
|
def global_message():
|
||||||
"""Parse the decision tree and return the message
|
"""Parse the decision tree and return the message.
|
||||||
corresponding to the current threasholds values"""
|
|
||||||
|
Note: message corresponding to the current threasholds values
|
||||||
|
"""
|
||||||
# Compute the weight for each item in the tree
|
# Compute the weight for each item in the tree
|
||||||
current_thresholds = glances_thresholds.get()
|
current_thresholds = glances_thresholds.get()
|
||||||
for i in tree:
|
for i in tree:
|
||||||
@ -76,7 +78,6 @@ def global_message():
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances alert plugin.
|
"""Glances alert plugin.
|
||||||
|
|
||||||
Only for display.
|
Only for display.
|
||||||
|
@ -25,7 +25,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances AMPs plugin."""
|
"""Glances AMPs plugin."""
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
|
@ -42,7 +42,6 @@ except AttributeError:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances battery capacity plugin.
|
"""Glances battery capacity plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
@ -87,7 +86,6 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class GlancesGrabBat(object):
|
class GlancesGrabBat(object):
|
||||||
|
|
||||||
"""Get batteries stats using the batinfo library."""
|
"""Get batteries stats using the batinfo library."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -38,7 +38,6 @@ from glances.logger import logger
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances' cloud plugin.
|
"""Glances' cloud plugin.
|
||||||
|
|
||||||
The goal of this plugin is to retreive additional information
|
The goal of this plugin is to retreive additional information
|
||||||
@ -70,7 +69,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self.stats = {}
|
self.stats = {}
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
"""Overwrite the exit method to close threads"""
|
"""Overwrite the exit method to close threads."""
|
||||||
self.aws_ec2.stop()
|
self.aws_ec2.stop()
|
||||||
# Call the father class
|
# Call the father class
|
||||||
super(Plugin, self).exit()
|
super(Plugin, self).exit()
|
||||||
@ -137,7 +136,7 @@ class ThreadAwsEc2Grabber(threading.Thread):
|
|||||||
'region': 'placement/availability-zone'}
|
'region': 'placement/availability-zone'}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Init the class"""
|
"""Init the class."""
|
||||||
logger.debug("cloud plugin - Create thread for AWS EC2")
|
logger.debug("cloud plugin - Create thread for AWS EC2")
|
||||||
super(ThreadAwsEc2Grabber, self).__init__()
|
super(ThreadAwsEc2Grabber, self).__init__()
|
||||||
# Event needed to stop properly the thread
|
# Event needed to stop properly the thread
|
||||||
@ -146,9 +145,10 @@ class ThreadAwsEc2Grabber(threading.Thread):
|
|||||||
self._stats = {}
|
self._stats = {}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Function called to grab stats.
|
"""Grab plugin's stats.
|
||||||
Infinite loop, should be stopped by calling the stop() method"""
|
|
||||||
|
|
||||||
|
Infinite loop, should be stopped by calling the stop() method
|
||||||
|
"""
|
||||||
if not cloud_tag:
|
if not cloud_tag:
|
||||||
logger.debug("cloud plugin - Requests lib is not installed")
|
logger.debug("cloud plugin - Requests lib is not installed")
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -170,19 +170,19 @@ class ThreadAwsEc2Grabber(threading.Thread):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def stats(self):
|
def stats(self):
|
||||||
"""Stats getter"""
|
"""Stats getter."""
|
||||||
return self._stats
|
return self._stats
|
||||||
|
|
||||||
@stats.setter
|
@stats.setter
|
||||||
def stats(self, value):
|
def stats(self, value):
|
||||||
"""Stats setter"""
|
"""Stats setter."""
|
||||||
self._stats = value
|
self._stats = value
|
||||||
|
|
||||||
def stop(self, timeout=None):
|
def stop(self, timeout=None):
|
||||||
"""Stop the thread"""
|
"""Stop the thread."""
|
||||||
logger.debug("cloud plugin - Close thread for AWS EC2")
|
logger.debug("cloud plugin - Close thread for AWS EC2")
|
||||||
self._stopper.set()
|
self._stopper.set()
|
||||||
|
|
||||||
def stopped(self):
|
def stopped(self):
|
||||||
"""Return True is the thread is stopped"""
|
"""Return True is the thread is stopped."""
|
||||||
return self._stopper.isSet()
|
return self._stopper.isSet()
|
||||||
|
@ -25,7 +25,6 @@ import psutil
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances CPU core plugin.
|
"""Glances CPU core plugin.
|
||||||
|
|
||||||
Get stats about CPU core number.
|
Get stats about CPU core number.
|
||||||
|
@ -57,7 +57,6 @@ items_history_list = [{'name': 'user',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances CPU plugin.
|
"""Glances CPU plugin.
|
||||||
|
|
||||||
'stats' is a dictionary that contains the system-wide CPU utilization as a
|
'stats' is a dictionary that contains the system-wide CPU utilization as a
|
||||||
@ -88,7 +87,6 @@ class Plugin(GlancesPlugin):
|
|||||||
@GlancesPlugin._log_result_decorator
|
@GlancesPlugin._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update CPU stats using the input method."""
|
"""Update CPU stats using the input method."""
|
||||||
|
|
||||||
# Reset stats
|
# Reset stats
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ items_history_list = [{'name': 'read_bytes',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances disks I/O plugin.
|
"""Glances disks I/O plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
|
@ -40,7 +40,6 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances Docker plugin.
|
"""Glances Docker plugin.
|
||||||
|
|
||||||
stats is a dict: {'version': {...}, 'containers': [{}, {}]}
|
stats is a dict: {'version': {...}, 'containers': [{}, {}]}
|
||||||
@ -68,7 +67,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
"""Overwrite the exit method to close threads"""
|
"""Overwrite the exit method to close threads."""
|
||||||
for t in itervalues(self.thread_list):
|
for t in itervalues(self.thread_list):
|
||||||
t.stop()
|
t.stop()
|
||||||
# Call the father class
|
# Call the father class
|
||||||
@ -105,7 +104,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self.stats = {}
|
self.stats = {}
|
||||||
|
|
||||||
def _all_tag(self):
|
def _all_tag(self):
|
||||||
"""Return the all tag of the Glances/Docker configuration file
|
"""Return the all tag of the Glances/Docker configuration file.
|
||||||
|
|
||||||
# By default, Glances only display running containers
|
# By default, Glances only display running containers
|
||||||
# Set the following key to True to display all containers
|
# Set the following key to True to display all containers
|
||||||
@ -121,7 +120,6 @@ class Plugin(GlancesPlugin):
|
|||||||
@GlancesPlugin._log_result_decorator
|
@GlancesPlugin._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update Docker stats using the input method."""
|
"""Update Docker stats using the input method."""
|
||||||
|
|
||||||
# Reset stats
|
# Reset stats
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
@ -410,8 +408,10 @@ class Plugin(GlancesPlugin):
|
|||||||
return os.sysconf(os.sysconf_names['SC_CLK_TCK'])
|
return os.sysconf(os.sysconf_names['SC_CLK_TCK'])
|
||||||
|
|
||||||
def get_stats_action(self):
|
def get_stats_action(self):
|
||||||
"""Return stats for the action
|
"""Return stats for the action.
|
||||||
Docker will return self.stats['containers']"""
|
|
||||||
|
Docker will return self.stats['containers']
|
||||||
|
"""
|
||||||
return self.stats['containers']
|
return self.stats['containers']
|
||||||
|
|
||||||
def update_views(self):
|
def update_views(self):
|
||||||
@ -587,7 +587,8 @@ class ThreadDockerGrabber(threading.Thread):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, container):
|
def __init__(self, container):
|
||||||
"""Init the class:
|
"""Init the class.
|
||||||
|
|
||||||
container: instance of Docker-py Container
|
container: instance of Docker-py Container
|
||||||
"""
|
"""
|
||||||
super(ThreadDockerGrabber, self).__init__()
|
super(ThreadDockerGrabber, self).__init__()
|
||||||
@ -601,9 +602,10 @@ class ThreadDockerGrabber(threading.Thread):
|
|||||||
logger.debug("docker plugin - Create thread for container {}".format(self._container.name))
|
logger.debug("docker plugin - Create thread for container {}".format(self._container.name))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Function called to grab stats.
|
"""Grab the stats.
|
||||||
Infinite loop, should be stopped by calling the stop() method"""
|
|
||||||
|
|
||||||
|
Infinite loop, should be stopped by calling the stop() method
|
||||||
|
"""
|
||||||
for i in self._stats_stream:
|
for i in self._stats_stream:
|
||||||
self._stats = i
|
self._stats = i
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@ -612,19 +614,19 @@ class ThreadDockerGrabber(threading.Thread):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def stats(self):
|
def stats(self):
|
||||||
"""Stats getter"""
|
"""Stats getter."""
|
||||||
return self._stats
|
return self._stats
|
||||||
|
|
||||||
@stats.setter
|
@stats.setter
|
||||||
def stats(self, value):
|
def stats(self, value):
|
||||||
"""Stats setter"""
|
"""Stats setter."""
|
||||||
self._stats = value
|
self._stats = value
|
||||||
|
|
||||||
def stop(self, timeout=None):
|
def stop(self, timeout=None):
|
||||||
"""Stop the thread"""
|
"""Stop the thread."""
|
||||||
logger.debug("docker plugin - Close thread for container {}".format(self._container.name))
|
logger.debug("docker plugin - Close thread for container {}".format(self._container.name))
|
||||||
self._stopper.set()
|
self._stopper.set()
|
||||||
|
|
||||||
def stopped(self):
|
def stopped(self):
|
||||||
"""Return True is the thread is stopped"""
|
"""Return True is the thread is stopped."""
|
||||||
return self._stopper.isSet()
|
return self._stopper.isSet()
|
||||||
|
@ -26,7 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances folder plugin."""
|
"""Glances folder plugin."""
|
||||||
|
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
@ -76,8 +75,7 @@ class Plugin(GlancesPlugin):
|
|||||||
return self.stats
|
return self.stats
|
||||||
|
|
||||||
def get_alert(self, stat):
|
def get_alert(self, stat):
|
||||||
"""Manage limits of the folder list"""
|
"""Manage limits of the folder list."""
|
||||||
|
|
||||||
if not isinstance(stat['size'], numbers.Number):
|
if not isinstance(stat['size'], numbers.Number):
|
||||||
return 'DEFAULT'
|
return 'DEFAULT'
|
||||||
else:
|
else:
|
||||||
|
@ -66,7 +66,6 @@ items_history_list = [{'name': 'percent',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances file system plugin.
|
"""Glances file system plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""GPU plugin (limited to NVIDIA chipsets)"""
|
"""GPU plugin (limited to NVIDIA chipsets)."""
|
||||||
|
|
||||||
from glances.compat import nativestr
|
from glances.compat import nativestr
|
||||||
from glances.logger import logger
|
from glances.logger import logger
|
||||||
@ -34,14 +34,13 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances GPU plugin (limited to NVIDIA chipsets).
|
"""Glances GPU plugin (limited to NVIDIA chipsets).
|
||||||
|
|
||||||
stats is a list of dictionaries with one entry per GPU
|
stats is a list of dictionaries with one entry per GPU
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
"""Init the plugin"""
|
"""Init the plugin."""
|
||||||
super(Plugin, self).__init__(args=args)
|
super(Plugin, self).__init__(args=args)
|
||||||
|
|
||||||
# Init the NVidia API
|
# Init the NVidia API
|
||||||
@ -58,7 +57,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self.stats = []
|
self.stats = []
|
||||||
|
|
||||||
def init_nvidia(self):
|
def init_nvidia(self):
|
||||||
"""Init the NVIDIA API"""
|
"""Init the NVIDIA API."""
|
||||||
if not gpu_nvidia_tag:
|
if not gpu_nvidia_tag:
|
||||||
self.nvml_ready = False
|
self.nvml_ready = False
|
||||||
|
|
||||||
@ -79,8 +78,7 @@ class Plugin(GlancesPlugin):
|
|||||||
@GlancesPlugin._check_decorator
|
@GlancesPlugin._check_decorator
|
||||||
@GlancesPlugin._log_result_decorator
|
@GlancesPlugin._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the GPU stats"""
|
"""Update the GPU stats."""
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
# !!! JUST FOR TEST
|
# !!! JUST FOR TEST
|
||||||
@ -212,7 +210,7 @@ class Plugin(GlancesPlugin):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_device_stats(self):
|
def get_device_stats(self):
|
||||||
"""Get GPU stats"""
|
"""Get GPU stats."""
|
||||||
stats = []
|
stats = []
|
||||||
|
|
||||||
for index, device_handle in enumerate(self.device_handles):
|
for index, device_handle in enumerate(self.device_handles):
|
||||||
@ -232,7 +230,7 @@ class Plugin(GlancesPlugin):
|
|||||||
return stats
|
return stats
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
"""Overwrite the exit method to close the GPU API"""
|
"""Overwrite the exit method to close the GPU API."""
|
||||||
if self.nvml_ready:
|
if self.nvml_ready:
|
||||||
try:
|
try:
|
||||||
pynvml.nvmlShutdown()
|
pynvml.nvmlShutdown()
|
||||||
@ -244,14 +242,15 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
def get_device_handles():
|
def get_device_handles():
|
||||||
"""
|
"""Get a list of NVML device handles, one per device.
|
||||||
Returns a list of NVML device handles, one per device. Can throw NVMLError.
|
|
||||||
|
Can throw NVMLError.
|
||||||
"""
|
"""
|
||||||
return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())]
|
return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())]
|
||||||
|
|
||||||
|
|
||||||
def get_device_name(device_handle):
|
def get_device_name(device_handle):
|
||||||
"""Get GPU device name"""
|
"""Get GPU device name."""
|
||||||
try:
|
try:
|
||||||
return nativestr(pynvml.nvmlDeviceGetName(device_handle))
|
return nativestr(pynvml.nvmlDeviceGetName(device_handle))
|
||||||
except pynvml.NVMlError:
|
except pynvml.NVMlError:
|
||||||
@ -259,7 +258,7 @@ def get_device_name(device_handle):
|
|||||||
|
|
||||||
|
|
||||||
def get_mem(device_handle):
|
def get_mem(device_handle):
|
||||||
"""Get GPU device memory consumption in percent"""
|
"""Get GPU device memory consumption in percent."""
|
||||||
try:
|
try:
|
||||||
memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle)
|
memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle)
|
||||||
return memory_info.used * 100.0 / memory_info.total
|
return memory_info.used * 100.0 / memory_info.total
|
||||||
@ -268,7 +267,7 @@ def get_mem(device_handle):
|
|||||||
|
|
||||||
|
|
||||||
def get_proc(device_handle):
|
def get_proc(device_handle):
|
||||||
"""Get GPU device CPU consumption in percent"""
|
"""Get GPU device CPU consumption in percent."""
|
||||||
try:
|
try:
|
||||||
return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu
|
return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu
|
||||||
except pynvml.NVMLError:
|
except pynvml.NVMLError:
|
||||||
|
@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances HDD temperature sensors plugin.
|
"""Glances HDD temperature sensors plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
@ -72,7 +71,6 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class GlancesGrabHDDTemp(object):
|
class GlancesGrabHDDTemp(object):
|
||||||
|
|
||||||
"""Get hddtemp stats using a socket connection."""
|
"""Get hddtemp stats using a socket connection."""
|
||||||
|
|
||||||
def __init__(self, host='127.0.0.1', port=7634, args=None):
|
def __init__(self, host='127.0.0.1', port=7634, args=None):
|
||||||
|
@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances help plugin."""
|
"""Glances help plugin."""
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
@ -54,6 +53,7 @@ class Plugin(GlancesPlugin):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def generate_view_data(self):
|
def generate_view_data(self):
|
||||||
|
"""Generate the views."""
|
||||||
self.view_data['version'] = '{} {}'.format('Glances', __version__)
|
self.view_data['version'] = '{} {}'.format('Glances', __version__)
|
||||||
self.view_data['psutil_version'] = ' with PSutil {}'.format(psutil_version)
|
self.view_data['psutil_version'] = ' with PSutil {}'.format(psutil_version)
|
||||||
|
|
||||||
@ -103,6 +103,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern'
|
self.view_data['edit_pattern_filter'] = 'ENTER: Edit the process filter pattern'
|
||||||
|
|
||||||
def get_view_data(self, args=None):
|
def get_view_data(self, args=None):
|
||||||
|
"""Return the view."""
|
||||||
return self.view_data
|
return self.view_data
|
||||||
|
|
||||||
def msg_curse(self, args=None):
|
def msg_curse(self, args=None):
|
||||||
|
@ -52,7 +52,6 @@ urls = [('http://ip.42.pl/raw', False, None),
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances IP Plugin.
|
"""Glances IP Plugin.
|
||||||
|
|
||||||
stats is a dict
|
stats is a dict
|
||||||
@ -159,13 +158,14 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class PublicIpAddress(object):
|
class PublicIpAddress(object):
|
||||||
"""Get public IP address from online services"""
|
"""Get public IP address from online services."""
|
||||||
|
|
||||||
def __init__(self, timeout=2):
|
def __init__(self, timeout=2):
|
||||||
|
"""Init the class."""
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Get the first public IP address returned by one of the online services"""
|
"""Get the first public IP address returned by one of the online services."""
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
|
|
||||||
for u, j, k in urls:
|
for u, j, k in urls:
|
||||||
@ -182,7 +182,7 @@ class PublicIpAddress(object):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def _get_ip_public(self, queue_target, url, json=False, key=None):
|
def _get_ip_public(self, queue_target, url, json=False, key=None):
|
||||||
"""Request the url service and put the result in the queue_target"""
|
"""Request the url service and put the result in the queue_target."""
|
||||||
try:
|
try:
|
||||||
response = urlopen(url, timeout=self.timeout).read().decode('utf-8')
|
response = urlopen(url, timeout=self.timeout).read().decode('utf-8')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances IRQ plugin.
|
"""Glances IRQ plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
@ -56,8 +55,7 @@ class Plugin(GlancesPlugin):
|
|||||||
@GlancesPlugin._check_decorator
|
@GlancesPlugin._check_decorator
|
||||||
@GlancesPlugin._log_result_decorator
|
@GlancesPlugin._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the IRQ stats"""
|
"""Update the IRQ stats."""
|
||||||
|
|
||||||
# Reset the list
|
# Reset the list
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
@ -117,27 +115,25 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class GlancesIRQ(object):
|
class GlancesIRQ(object):
|
||||||
"""
|
"""This class manages the IRQ file."""
|
||||||
This class manages the IRQ file
|
|
||||||
"""
|
|
||||||
|
|
||||||
IRQ_FILE = '/proc/interrupts'
|
IRQ_FILE = '/proc/interrupts'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""Init the class.
|
||||||
Init the class
|
|
||||||
The stat are stored in a internal list of dict
|
The stat are stored in a internal list of dict
|
||||||
"""
|
"""
|
||||||
self.lasts = {}
|
self.lasts = {}
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Reset the stats"""
|
"""Reset the stats."""
|
||||||
self.stats = []
|
self.stats = []
|
||||||
self.cpu_number = 0
|
self.cpu_number = 0
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
"""Return the current IRQ stats"""
|
"""Return the current IRQ stats."""
|
||||||
return self.__update()
|
return self.__update()
|
||||||
|
|
||||||
def get_key(self):
|
def get_key(self):
|
||||||
@ -145,7 +141,7 @@ class GlancesIRQ(object):
|
|||||||
return 'irq_line'
|
return 'irq_line'
|
||||||
|
|
||||||
def __header(self, line):
|
def __header(self, line):
|
||||||
"""The header contain the number of CPU
|
"""Build the header (contain the number of CPU).
|
||||||
|
|
||||||
CPU0 CPU1 CPU2 CPU3
|
CPU0 CPU1 CPU2 CPU3
|
||||||
0: 21 0 0 0 IO-APIC 2-edge timer
|
0: 21 0 0 0 IO-APIC 2-edge timer
|
||||||
@ -154,8 +150,7 @@ class GlancesIRQ(object):
|
|||||||
return self.cpu_number
|
return self.cpu_number
|
||||||
|
|
||||||
def __humanname(self, line):
|
def __humanname(self, line):
|
||||||
"""Get a line and
|
"""Return the IRQ name, alias or number (choose the best for human).
|
||||||
Return the IRQ name, alias or number (choose the best for human)
|
|
||||||
|
|
||||||
IRQ line samples:
|
IRQ line samples:
|
||||||
1: 44487 341 44 72 IO-APIC 1-edge i8042
|
1: 44487 341 44 72 IO-APIC 1-edge i8042
|
||||||
@ -169,8 +164,7 @@ class GlancesIRQ(object):
|
|||||||
return irq_line
|
return irq_line
|
||||||
|
|
||||||
def __sum(self, line):
|
def __sum(self, line):
|
||||||
"""Get a line and
|
"""Return the IRQ sum number.
|
||||||
Return the IRQ sum number
|
|
||||||
|
|
||||||
IRQ line samples:
|
IRQ line samples:
|
||||||
1: 44487 341 44 72 IO-APIC 1-edge i8042
|
1: 44487 341 44 72 IO-APIC 1-edge i8042
|
||||||
@ -186,10 +180,7 @@ class GlancesIRQ(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __update(self):
|
def __update(self):
|
||||||
"""
|
"""Load the IRQ file and update the internal dict."""
|
||||||
Load the IRQ file and update the internal dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
if not os.path.exists(self.IRQ_FILE):
|
if not os.path.exists(self.IRQ_FILE):
|
||||||
|
@ -48,7 +48,6 @@ items_history_list = [{'name': 'min1',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances load plugin.
|
"""Glances load plugin.
|
||||||
|
|
||||||
stats is a dict
|
stats is a dict
|
||||||
|
@ -56,7 +56,6 @@ items_history_list = [{'name': 'percent',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances' memory plugin.
|
"""Glances' memory plugin.
|
||||||
|
|
||||||
stats is a dict
|
stats is a dict
|
||||||
|
@ -44,7 +44,6 @@ items_history_list = [{'name': 'percent',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances swap memory plugin.
|
"""Glances swap memory plugin.
|
||||||
|
|
||||||
stats is a dict
|
stats is a dict
|
||||||
|
@ -48,7 +48,6 @@ items_history_list = [{'name': 'rx',
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances network plugin.
|
"""Glances network plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""Now (current date) plugin."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from glances.plugins.glances_plugin import GlancesPlugin
|
from glances.plugins.glances_plugin import GlancesPlugin
|
||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Plugin to get the current date/time.
|
"""Plugin to get the current date/time.
|
||||||
|
|
||||||
stats is (string)
|
stats is (string)
|
||||||
|
@ -24,7 +24,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances per-CPU plugin.
|
"""Glances per-CPU plugin.
|
||||||
|
|
||||||
'stats' is a list of dictionaries that contain the utilization percentages
|
'stats' is a list of dictionaries that contain the utilization percentages
|
||||||
|
@ -36,7 +36,6 @@ from glances.thresholds import glances_thresholds
|
|||||||
|
|
||||||
|
|
||||||
class GlancesPlugin(object):
|
class GlancesPlugin(object):
|
||||||
|
|
||||||
"""Main class for Glances plugin."""
|
"""Main class for Glances plugin."""
|
||||||
|
|
||||||
def __init__(self, args=None, items_history_list=None):
|
def __init__(self, args=None, items_history_list=None):
|
||||||
@ -61,7 +60,6 @@ class GlancesPlugin(object):
|
|||||||
:args: args parameters
|
:args: args parameters
|
||||||
:items_history_list: list of items to store in the history
|
:items_history_list: list of items to store in the history
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Plugin name (= module name without glances_)
|
# Plugin name (= module name without glances_)
|
||||||
self.plugin_name = self.__class__.__module__[len('glances_'):]
|
self.plugin_name = self.__class__.__module__[len('glances_'):]
|
||||||
# logger.debug("Init plugin %s" % self.plugin_name)
|
# logger.debug("Init plugin %s" % self.plugin_name)
|
||||||
@ -103,11 +101,13 @@ class GlancesPlugin(object):
|
|||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Reset the stats.
|
"""Reset the stats.
|
||||||
This method should be overwrited by childs' classes"""
|
|
||||||
|
This method should be overwrited by childs' classes.
|
||||||
|
"""
|
||||||
self.stats = None
|
self.stats = None
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
"""Method to be called when Glances exit"""
|
"""Just log an event when Glances exit."""
|
||||||
logger.debug("Stop the {} plugin".format(self.plugin_name))
|
logger.debug("Stop the {} plugin".format(self.plugin_name))
|
||||||
|
|
||||||
def get_key(self):
|
def get_key(self):
|
||||||
@ -115,7 +115,7 @@ class GlancesPlugin(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def is_enable(self):
|
def is_enable(self):
|
||||||
"""Return true if plugin is enabled"""
|
"""Return true if plugin is enabled."""
|
||||||
try:
|
try:
|
||||||
d = getattr(self.args, 'disable_' + self.plugin_name)
|
d = getattr(self.args, 'disable_' + self.plugin_name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -124,12 +124,14 @@ class GlancesPlugin(object):
|
|||||||
return d is False
|
return d is False
|
||||||
|
|
||||||
def is_disable(self):
|
def is_disable(self):
|
||||||
"""Return true if plugin is disabled"""
|
"""Return true if plugin is disabled."""
|
||||||
return not self.is_enable()
|
return not self.is_enable()
|
||||||
|
|
||||||
def _json_dumps(self, d):
|
def _json_dumps(self, d):
|
||||||
"""Return the object 'd' in a JSON format
|
"""Return the object 'd' in a JSON format.
|
||||||
Manage the issue #815 for Windows OS"""
|
|
||||||
|
Manage the issue #815 for Windows OS
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return json.dumps(d)
|
return json.dumps(d)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
@ -185,11 +187,13 @@ class GlancesPlugin(object):
|
|||||||
return self.items_history_list
|
return self.items_history_list
|
||||||
|
|
||||||
def get_raw_history(self, item=None, nb=0):
|
def get_raw_history(self, item=None, nb=0):
|
||||||
"""Return
|
"""Return the history (RAW format).
|
||||||
|
|
||||||
- the stats history (dict of list) if item is None
|
- the stats history (dict of list) if item is None
|
||||||
- the stats history for the given item (list) instead
|
- the stats history for the given item (list) instead
|
||||||
- None if item did not exist in the history
|
- None if item did not exist in the history
|
||||||
Limit to lasts nb items (all if nb=0)"""
|
Limit to lasts nb items (all if nb=0)
|
||||||
|
"""
|
||||||
s = self.stats_history.get(nb=nb)
|
s = self.stats_history.get(nb=nb)
|
||||||
if item is None:
|
if item is None:
|
||||||
return s
|
return s
|
||||||
@ -200,11 +204,13 @@ class GlancesPlugin(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_json_history(self, item=None, nb=0):
|
def get_json_history(self, item=None, nb=0):
|
||||||
"""Return:
|
"""Return the history (JSON format).
|
||||||
|
|
||||||
- the stats history (dict of list) if item is None
|
- the stats history (dict of list) if item is None
|
||||||
- the stats history for the given item (list) instead
|
- the stats history for the given item (list) instead
|
||||||
- None if item did not exist in the history
|
- None if item did not exist in the history
|
||||||
Limit to lasts nb items (all if nb=0)"""
|
Limit to lasts nb items (all if nb=0)
|
||||||
|
"""
|
||||||
s = self.stats_history.get_json(nb=nb)
|
s = self.stats_history.get_json(nb=nb)
|
||||||
if item is None:
|
if item is None:
|
||||||
return s
|
return s
|
||||||
@ -216,12 +222,16 @@ class GlancesPlugin(object):
|
|||||||
|
|
||||||
def get_export_history(self, item=None):
|
def get_export_history(self, item=None):
|
||||||
"""Return the stats history object to export.
|
"""Return the stats history object to export.
|
||||||
See get_raw_history for a full description"""
|
|
||||||
|
See get_raw_history for a full description
|
||||||
|
"""
|
||||||
return self.get_raw_history(item=item)
|
return self.get_raw_history(item=item)
|
||||||
|
|
||||||
def get_stats_history(self, item=None, nb=0):
|
def get_stats_history(self, item=None, nb=0):
|
||||||
"""Return the stats history as a JSON object (dict or None).
|
"""Return the stats history (JSON format).
|
||||||
Limit to lasts nb items (all if nb=0)"""
|
|
||||||
|
Limit to lasts nb items (all if nb=0)
|
||||||
|
"""
|
||||||
s = self.get_json_history(nb=nb)
|
s = self.get_json_history(nb=nb)
|
||||||
|
|
||||||
if item is None:
|
if item is None:
|
||||||
@ -245,7 +255,8 @@ class GlancesPlugin(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_trend(self, item, nb=6):
|
def get_trend(self, item, nb=6):
|
||||||
"""Get the trend regarding to the last nb values
|
"""Get the trend regarding to the last nb values.
|
||||||
|
|
||||||
The trend is the diff between the mean of the last nb values
|
The trend is the diff between the mean of the last nb values
|
||||||
and the current one.
|
and the current one.
|
||||||
"""
|
"""
|
||||||
@ -391,7 +402,7 @@ class GlancesPlugin(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def update_views(self):
|
def update_views(self):
|
||||||
"""Default builder fo the stats views.
|
"""Update the stats views.
|
||||||
|
|
||||||
The V of MVC
|
The V of MVC
|
||||||
A dict of dict with the needed information to display the stats.
|
A dict of dict with the needed information to display the stats.
|
||||||
@ -458,12 +469,11 @@ class GlancesPlugin(object):
|
|||||||
return 'DEFAULT'
|
return 'DEFAULT'
|
||||||
|
|
||||||
def get_json_views(self, item=None, key=None, option=None):
|
def get_json_views(self, item=None, key=None, option=None):
|
||||||
"""Return views in JSON"""
|
"""Return the views (in JSON)."""
|
||||||
return self._json_dumps(self.get_views(item, key, option))
|
return self._json_dumps(self.get_views(item, key, option))
|
||||||
|
|
||||||
def load_limits(self, config):
|
def load_limits(self, config):
|
||||||
"""Load limits from the configuration file, if it exists."""
|
"""Load limits from the configuration file, if it exists."""
|
||||||
|
|
||||||
# By default set the history length to 3 points per second during one day
|
# By default set the history length to 3 points per second during one day
|
||||||
self._limits['history_size'] = 28800
|
self._limits['history_size'] = 28800
|
||||||
|
|
||||||
@ -499,10 +509,12 @@ class GlancesPlugin(object):
|
|||||||
self._limits = input_limits
|
self._limits = input_limits
|
||||||
|
|
||||||
def get_stats_action(self):
|
def get_stats_action(self):
|
||||||
"""Return stats for the action
|
"""Return stats for the action.
|
||||||
|
|
||||||
By default return all the stats.
|
By default return all the stats.
|
||||||
Can be overwrite by plugins implementation.
|
Can be overwrite by plugins implementation.
|
||||||
For example, Docker will return self.stats['containers']"""
|
For example, Docker will return self.stats['containers']
|
||||||
|
"""
|
||||||
return self.stats
|
return self.stats
|
||||||
|
|
||||||
def get_alert(self,
|
def get_alert(self,
|
||||||
@ -589,7 +601,7 @@ class GlancesPlugin(object):
|
|||||||
def manage_threshold(self,
|
def manage_threshold(self,
|
||||||
stat_name,
|
stat_name,
|
||||||
trigger):
|
trigger):
|
||||||
"""Manage the threshold for the current stat"""
|
"""Manage the threshold for the current stat."""
|
||||||
glances_thresholds.add(stat_name, trigger)
|
glances_thresholds.add(stat_name, trigger)
|
||||||
# logger.info(glances_thresholds.get())
|
# logger.info(glances_thresholds.get())
|
||||||
|
|
||||||
@ -598,7 +610,7 @@ class GlancesPlugin(object):
|
|||||||
trigger,
|
trigger,
|
||||||
header,
|
header,
|
||||||
action_key):
|
action_key):
|
||||||
"""Manage the action for the current stat"""
|
"""Manage the action for the current stat."""
|
||||||
# Here is a command line for the current trigger ?
|
# Here is a command line for the current trigger ?
|
||||||
try:
|
try:
|
||||||
command, repeat = self.get_limit_action(trigger, stat_name=stat_name)
|
command, repeat = self.get_limit_action(trigger, stat_name=stat_name)
|
||||||
@ -661,8 +673,10 @@ class GlancesPlugin(object):
|
|||||||
|
|
||||||
def get_limit_action(self, criticity, stat_name=""):
|
def get_limit_action(self, criticity, stat_name=""):
|
||||||
"""Return the tuple (action, repeat) for the alert.
|
"""Return the tuple (action, repeat) for the alert.
|
||||||
|
|
||||||
- action is a command line
|
- action is a command line
|
||||||
- repeat is a bool"""
|
- repeat is a bool
|
||||||
|
"""
|
||||||
# Get the action for stat + header
|
# Get the action for stat + header
|
||||||
# Exemple: network_wlan0_rx_careful_action
|
# Exemple: network_wlan0_rx_careful_action
|
||||||
# Action key available ?
|
# Action key available ?
|
||||||
@ -714,8 +728,8 @@ class GlancesPlugin(object):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def is_hide(self, value, header=""):
|
def is_hide(self, value, header=""):
|
||||||
"""
|
"""Return True if the value is in the hide configuration list.
|
||||||
Return True if the value is in the hide configuration list.
|
|
||||||
The hide configuration list is defined in the glances.conf file.
|
The hide configuration list is defined in the glances.conf file.
|
||||||
It is a comma separed list of regexp.
|
It is a comma separed list of regexp.
|
||||||
Example for diskio:
|
Example for diskio:
|
||||||
@ -818,8 +832,6 @@ class GlancesPlugin(object):
|
|||||||
"""Make a nice human-readable string out of number.
|
"""Make a nice human-readable string out of number.
|
||||||
|
|
||||||
Number of decimal places increases as quantity approaches 1.
|
Number of decimal places increases as quantity approaches 1.
|
||||||
|
|
||||||
examples:
|
|
||||||
CASE: 613421788 RESULT: 585M low_precision: 585M
|
CASE: 613421788 RESULT: 585M low_precision: 585M
|
||||||
CASE: 5307033647 RESULT: 4.94G low_precision: 4.9G
|
CASE: 5307033647 RESULT: 4.94G low_precision: 4.9G
|
||||||
CASE: 44968414685 RESULT: 41.9G low_precision: 41.9G
|
CASE: 44968414685 RESULT: 41.9G low_precision: 41.9G
|
||||||
@ -866,8 +878,10 @@ class GlancesPlugin(object):
|
|||||||
return '{!s}'.format(number)
|
return '{!s}'.format(number)
|
||||||
|
|
||||||
def trend_msg(self, trend, significant=1):
|
def trend_msg(self, trend, significant=1):
|
||||||
"""Return the trend message
|
"""Return the trend message.
|
||||||
Do not take into account if trend < significant"""
|
|
||||||
|
Do not take into account if trend < significant
|
||||||
|
"""
|
||||||
ret = '-'
|
ret = '-'
|
||||||
if trend is None:
|
if trend is None:
|
||||||
ret = ' '
|
ret = ' '
|
||||||
|
@ -42,7 +42,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances ports scanner plugin."""
|
"""Glances ports scanner plugin."""
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
@ -64,7 +63,7 @@ class Plugin(GlancesPlugin):
|
|||||||
self._thread = None
|
self._thread = None
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
"""Overwrite the exit method to close threads"""
|
"""Overwrite the exit method to close threads."""
|
||||||
if self._thread is not None:
|
if self._thread is not None:
|
||||||
self._thread.stop()
|
self._thread.stop()
|
||||||
# Call the father class
|
# Call the father class
|
||||||
@ -77,7 +76,6 @@ class Plugin(GlancesPlugin):
|
|||||||
@GlancesPlugin._log_result_decorator
|
@GlancesPlugin._log_result_decorator
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the ports list."""
|
"""Update the ports list."""
|
||||||
|
|
||||||
if self.input_method == 'local':
|
if self.input_method == 'local':
|
||||||
# Only refresh:
|
# Only refresh:
|
||||||
# * if there is not other scanning thread
|
# * if there is not other scanning thread
|
||||||
@ -103,7 +101,6 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
def get_ports_alert(self, port, header="", log=False):
|
def get_ports_alert(self, port, header="", log=False):
|
||||||
"""Return the alert status relative to the port scan return value."""
|
"""Return the alert status relative to the port scan return value."""
|
||||||
|
|
||||||
if port['status'] is None:
|
if port['status'] is None:
|
||||||
return 'CAREFUL'
|
return 'CAREFUL'
|
||||||
elif port['status'] == 0:
|
elif port['status'] == 0:
|
||||||
@ -117,7 +114,6 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
def get_web_alert(self, web, header="", log=False):
|
def get_web_alert(self, web, header="", log=False):
|
||||||
"""Return the alert status relative to the web/url scan return value."""
|
"""Return the alert status relative to the web/url scan return value."""
|
||||||
|
|
||||||
if web['status'] is None:
|
if web['status'] is None:
|
||||||
return 'CAREFUL'
|
return 'CAREFUL'
|
||||||
elif web['status'] not in [200, 301, 302]:
|
elif web['status'] not in [200, 301, 302]:
|
||||||
@ -186,7 +182,7 @@ class ThreadScanner(threading.Thread):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, stats):
|
def __init__(self, stats):
|
||||||
"""Init the class"""
|
"""Init the class."""
|
||||||
logger.debug("ports plugin - Create thread for scan list {}".format(stats))
|
logger.debug("ports plugin - Create thread for scan list {}".format(stats))
|
||||||
super(ThreadScanner, self).__init__()
|
super(ThreadScanner, self).__init__()
|
||||||
# Event needed to stop properly the thread
|
# Event needed to stop properly the thread
|
||||||
@ -197,9 +193,10 @@ class ThreadScanner(threading.Thread):
|
|||||||
self.plugin_name = "ports"
|
self.plugin_name = "ports"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Function called to grab stats.
|
"""Grab the stats.
|
||||||
Infinite loop, should be stopped by calling the stop() method"""
|
|
||||||
|
|
||||||
|
Infinite loop, should be stopped by calling the stop() method.
|
||||||
|
"""
|
||||||
for p in self._stats:
|
for p in self._stats:
|
||||||
# End of the thread has been asked
|
# End of the thread has been asked
|
||||||
if self.stopped():
|
if self.stopped():
|
||||||
@ -216,25 +213,25 @@ class ThreadScanner(threading.Thread):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def stats(self):
|
def stats(self):
|
||||||
"""Stats getter"""
|
"""Stats getter."""
|
||||||
return self._stats
|
return self._stats
|
||||||
|
|
||||||
@stats.setter
|
@stats.setter
|
||||||
def stats(self, value):
|
def stats(self, value):
|
||||||
"""Stats setter"""
|
"""Stats setter."""
|
||||||
self._stats = value
|
self._stats = value
|
||||||
|
|
||||||
def stop(self, timeout=None):
|
def stop(self, timeout=None):
|
||||||
"""Stop the thread"""
|
"""Stop the thread."""
|
||||||
logger.debug("ports plugin - Close thread for scan list {}".format(self._stats))
|
logger.debug("ports plugin - Close thread for scan list {}".format(self._stats))
|
||||||
self._stopper.set()
|
self._stopper.set()
|
||||||
|
|
||||||
def stopped(self):
|
def stopped(self):
|
||||||
"""Return True is the thread is stopped"""
|
"""Return True is the thread is stopped."""
|
||||||
return self._stopper.isSet()
|
return self._stopper.isSet()
|
||||||
|
|
||||||
def _web_scan(self, web):
|
def _web_scan(self, web):
|
||||||
"""Scan the Web/URL (dict) and update the status key"""
|
"""Scan the Web/URL (dict) and update the status key."""
|
||||||
try:
|
try:
|
||||||
req = requests.head(web['url'],
|
req = requests.head(web['url'],
|
||||||
allow_redirects=True,
|
allow_redirects=True,
|
||||||
@ -249,14 +246,14 @@ class ThreadScanner(threading.Thread):
|
|||||||
return web
|
return web
|
||||||
|
|
||||||
def _port_scan(self, port):
|
def _port_scan(self, port):
|
||||||
"""Scan the port structure (dict) and update the status key"""
|
"""Scan the port structure (dict) and update the status key."""
|
||||||
if int(port['port']) == 0:
|
if int(port['port']) == 0:
|
||||||
return self._port_scan_icmp(port)
|
return self._port_scan_icmp(port)
|
||||||
else:
|
else:
|
||||||
return self._port_scan_tcp(port)
|
return self._port_scan_tcp(port)
|
||||||
|
|
||||||
def _resolv_name(self, hostname):
|
def _resolv_name(self, hostname):
|
||||||
"""Convert hostname to IP address"""
|
"""Convert hostname to IP address."""
|
||||||
ip = hostname
|
ip = hostname
|
||||||
try:
|
try:
|
||||||
ip = socket.gethostbyname(hostname)
|
ip = socket.gethostbyname(hostname)
|
||||||
@ -265,7 +262,7 @@ class ThreadScanner(threading.Thread):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def _port_scan_icmp(self, port):
|
def _port_scan_icmp(self, port):
|
||||||
"""Scan the (ICMP) port structure (dict) and update the status key"""
|
"""Scan the (ICMP) port structure (dict) and update the status key."""
|
||||||
ret = None
|
ret = None
|
||||||
|
|
||||||
# Create the ping command
|
# Create the ping command
|
||||||
@ -305,7 +302,7 @@ class ThreadScanner(threading.Thread):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _port_scan_tcp(self, port):
|
def _port_scan_tcp(self, port):
|
||||||
"""Scan the (TCP) port structure (dict) and update the status key"""
|
"""Scan the (TCP) port structure (dict) and update the status key."""
|
||||||
ret = None
|
ret = None
|
||||||
|
|
||||||
# Create and configure the scanning socket
|
# Create and configure the scanning socket
|
||||||
|
@ -27,7 +27,6 @@ from glances.plugins.glances_plugin import GlancesPlugin
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances process count plugin.
|
"""Glances process count plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
|
@ -57,7 +57,6 @@ def split_cmdline(cmdline):
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances' processes plugin.
|
"""Glances' processes plugin.
|
||||||
|
|
||||||
stats is a list
|
stats is a list
|
||||||
@ -202,6 +201,7 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
def get_process_curses_data(self, p, first, args):
|
def get_process_curses_data(self, p, first, args):
|
||||||
"""Get curses data to display for a process.
|
"""Get curses data to display for a process.
|
||||||
|
|
||||||
- p is the process to display
|
- p is the process to display
|
||||||
- first is a tag=True if the process is the first on the list
|
- first is a tag=True if the process is the first on the list
|
||||||
"""
|
"""
|
||||||
@ -466,9 +466,7 @@ class Plugin(GlancesPlugin):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __msg_curse_header(self, ret, process_sort_key, args=None):
|
def __msg_curse_header(self, ret, process_sort_key, args=None):
|
||||||
"""
|
"""Build the header and add it to the ret dict."""
|
||||||
Build the header and add it to the ret dict
|
|
||||||
"""
|
|
||||||
sort_style = 'SORT'
|
sort_style = 'SORT'
|
||||||
|
|
||||||
if args.disable_irix and 0 < self.nb_log_core < 10:
|
if args.disable_irix and 0 < self.nb_log_core < 10:
|
||||||
@ -503,7 +501,8 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
def __msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None):
|
def __msg_curse_sum(self, ret, sep_char='_', mmm=None, args=None):
|
||||||
"""
|
"""
|
||||||
Build the sum message (only when filter is on) and add it to the ret dict
|
Build the sum message (only when filter is on) and add it to the ret dict.
|
||||||
|
|
||||||
* ret: list of string where the message is added
|
* ret: list of string where the message is added
|
||||||
* sep_char: define the line separation char
|
* sep_char: define the line separation char
|
||||||
* mmm: display min, max, mean or current (if mmm=None)
|
* mmm: display min, max, mean or current (if mmm=None)
|
||||||
@ -586,24 +585,20 @@ class Plugin(GlancesPlugin):
|
|||||||
ret.append(self.curse_add_line(msg, optional=True))
|
ret.append(self.curse_add_line(msg, optional=True))
|
||||||
|
|
||||||
def __mmm_deco(self, mmm):
|
def __mmm_deco(self, mmm):
|
||||||
"""
|
"""Return the decoration string for the current mmm status."""
|
||||||
Return the decoration string for the current mmm status
|
|
||||||
"""
|
|
||||||
if mmm is not None:
|
if mmm is not None:
|
||||||
return 'DEFAULT'
|
return 'DEFAULT'
|
||||||
else:
|
else:
|
||||||
return 'FILTER'
|
return 'FILTER'
|
||||||
|
|
||||||
def __mmm_reset(self):
|
def __mmm_reset(self):
|
||||||
"""
|
"""Reset the MMM stats."""
|
||||||
Reset the MMM stats
|
|
||||||
"""
|
|
||||||
self.mmm_min = {}
|
self.mmm_min = {}
|
||||||
self.mmm_max = {}
|
self.mmm_max = {}
|
||||||
|
|
||||||
def __sum_stats(self, key, indice=None, mmm=None):
|
def __sum_stats(self, key, indice=None, mmm=None):
|
||||||
"""
|
"""Return the sum of the stats value for the given key.
|
||||||
Return the sum of the stats value for the given key
|
|
||||||
* indice: If indice is set, get the p[key][indice]
|
* indice: If indice is set, get the p[key][indice]
|
||||||
* mmm: display min, max, mean or current (if mmm=None)
|
* mmm: display min, max, mean or current (if mmm=None)
|
||||||
"""
|
"""
|
||||||
@ -647,13 +642,13 @@ class Plugin(GlancesPlugin):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __sort_stats(self, sortedby=None):
|
def __sort_stats(self, sortedby=None):
|
||||||
"""Return the stats (dict) sorted by (sortedby)"""
|
"""Return the stats (dict) sorted by (sortedby)."""
|
||||||
return sort_stats(self.stats, sortedby,
|
return sort_stats(self.stats, sortedby,
|
||||||
tree=glances_processes.is_tree_enabled(),
|
tree=glances_processes.is_tree_enabled(),
|
||||||
reverse=glances_processes.sort_reverse)
|
reverse=glances_processes.sort_reverse)
|
||||||
|
|
||||||
def __max_pid_size(self):
|
def __max_pid_size(self):
|
||||||
"""Return the maximum PID size in number of char"""
|
"""Return the maximum PID size in number of char."""
|
||||||
if self.pid_max is not None:
|
if self.pid_max is not None:
|
||||||
return len(str(self.pid_max))
|
return len(str(self.pid_max))
|
||||||
else:
|
else:
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""PsUtil plugin."""
|
||||||
|
|
||||||
from glances import psutil_version_info
|
from glances import psutil_version_info
|
||||||
from glances.plugins.glances_plugin import GlancesPlugin
|
from glances.plugins.glances_plugin import GlancesPlugin
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances quicklook plugin.
|
"""Glances quicklook plugin.
|
||||||
|
|
||||||
'stats' is a dictionary.
|
'stats' is a dictionary.
|
||||||
@ -143,7 +142,7 @@ class Plugin(GlancesPlugin):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _msg_create_line(self, msg, bar, key):
|
def _msg_create_line(self, msg, bar, key):
|
||||||
"""Create a new line to the Quickview"""
|
"""Create a new line to the Quickview."""
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
@ -155,5 +154,5 @@ class Plugin(GlancesPlugin):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _hz_to_ghz(self, hz):
|
def _hz_to_ghz(self, hz):
|
||||||
"""Convert Hz to Ghz"""
|
"""Convert Hz to Ghz."""
|
||||||
return hz / 1000000000.0
|
return hz / 1000000000.0
|
||||||
|
@ -31,7 +31,6 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances RAID plugin.
|
"""Glances RAID plugin.
|
||||||
|
|
||||||
stats is a dict (see pymdstat documentation)
|
stats is a dict (see pymdstat documentation)
|
||||||
|
@ -37,7 +37,6 @@ def to_fahrenheit(celsius):
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances sensors plugin.
|
"""Glances sensors plugin.
|
||||||
|
|
||||||
The stats list includes both sensors and hard disks stats, if any.
|
The stats list includes both sensors and hard disks stats, if any.
|
||||||
@ -218,7 +217,6 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
|
|
||||||
class GlancesGrabSensors(object):
|
class GlancesGrabSensors(object):
|
||||||
|
|
||||||
"""Get sensors stats."""
|
"""Get sensors stats."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -282,7 +280,8 @@ class GlancesGrabSensors(object):
|
|||||||
|
|
||||||
type: SENSOR_TEMP_UNIT or SENSOR_FAN_UNIT
|
type: SENSOR_TEMP_UNIT or SENSOR_FAN_UNIT
|
||||||
|
|
||||||
output: a list"""
|
output: a list
|
||||||
|
"""
|
||||||
ret = []
|
ret = []
|
||||||
if type == SENSOR_TEMP_UNIT and self.init_temp:
|
if type == SENSOR_TEMP_UNIT and self.init_temp:
|
||||||
input_list = self.stemps
|
input_list = self.stemps
|
||||||
|
@ -30,7 +30,6 @@ snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'}
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances uptime plugin.
|
"""Glances uptime plugin.
|
||||||
|
|
||||||
stats is date (string)
|
stats is date (string)
|
||||||
|
@ -38,8 +38,8 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class Plugin(GlancesPlugin):
|
class Plugin(GlancesPlugin):
|
||||||
|
|
||||||
"""Glances Wifi plugin.
|
"""Glances Wifi plugin.
|
||||||
|
|
||||||
Get stats of the current Wifi hotspots.
|
Get stats of the current Wifi hotspots.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -130,11 +130,11 @@ class Plugin(GlancesPlugin):
|
|||||||
|
|
||||||
def get_alert(self, value):
|
def get_alert(self, value):
|
||||||
"""Overwrite the default get_alert method.
|
"""Overwrite the default get_alert method.
|
||||||
|
|
||||||
Alert is on signal quality where lower is better...
|
Alert is on signal quality where lower is better...
|
||||||
|
|
||||||
:returns: string -- Signal alert
|
:returns: string -- Signal alert
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ret = 'OK'
|
ret = 'OK'
|
||||||
try:
|
try:
|
||||||
if value <= self.get_limit('critical', stat_name=self.plugin_name):
|
if value <= self.get_limit('critical', stat_name=self.plugin_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user