mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-03 23:26:01 +03:00
Refactor plugins as MVC (only M implement for the moment)
This commit is contained in:
parent
0d6a6eb92b
commit
3573c1a2df
@ -6,21 +6,14 @@ This is the Glances plugins folder.
|
||||
|
||||
A Glances plugin is a Python module hosted in a folder.
|
||||
|
||||
The name of the foo Glances plugin folder is foo (glances_foo).
|
||||
It should be based on thr MVC model.
|
||||
- model: datamodel
|
||||
- view: input for UI
|
||||
- controler: output from UI
|
||||
|
||||
The plugin is a Python class named Plugin inherits the GlancesPlugin object:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
"""Glances foo plugin."""
|
||||
|
||||
def __init__(self, args=None, config=None):
|
||||
super(Plugin, self).__init__(args=args,
|
||||
config=config,
|
||||
items_history_list=items_history_list,
|
||||
fields_description=fields_description)
|
||||
pass
|
||||
////
|
||||
TODO
|
||||
////
|
||||
|
||||
A plugin should define the following global variables:
|
||||
|
||||
|
@ -25,7 +25,7 @@ from glances.logger import logger
|
||||
from glances.events import glances_events
|
||||
from glances.thresholds import glances_thresholds
|
||||
# from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Static decision tree for the global alert message
|
||||
# - msg: Message to be displayed (result of the decision tree)
|
||||
@ -177,7 +177,7 @@ def global_message():
|
||||
return tree[0]['msg']
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances alert plugin.
|
||||
|
||||
Only for display.
|
@ -21,10 +21,10 @@
|
||||
|
||||
from glances.globals import iteritems
|
||||
from glances.amps_list import AmpsList as glancesAmpsList
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances AMPs plugin."""
|
||||
|
||||
def __init__(self, args=None, config=None):
|
||||
@ -45,8 +45,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'name'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the AMP list."""
|
||||
# Init new stats
|
@ -26,7 +26,7 @@ Supported Cloud API:
|
||||
import threading
|
||||
|
||||
from glances.globals import iteritems, to_ascii
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
|
||||
# Import plugin specific dependency
|
||||
@ -40,7 +40,7 @@ else:
|
||||
import_error_tag = False
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances' cloud plugin.
|
||||
|
||||
The goal of this plugin is to retreive additional information
|
||||
@ -73,8 +73,8 @@ class Plugin(GlancesPlugin):
|
||||
# Call the father class
|
||||
super(Plugin, self).exit()
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the cloud stats.
|
||||
|
@ -21,7 +21,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.globals import nativestr
|
||||
|
||||
import psutil
|
||||
@ -35,7 +35,7 @@ import psutil
|
||||
# 'y_unit': 'bit/s'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances connections plugin.
|
||||
|
||||
stats is a dict
|
||||
@ -69,8 +69,8 @@ class Plugin(GlancesPlugin):
|
||||
self.net_connections_enabled = True
|
||||
self.nf_conntrack_enabled = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update connections stats using the input method.
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""CPU core plugin."""
|
||||
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -35,7 +35,7 @@ physical cores multiplied by the number of threads that can run on each core.',
|
||||
'unit': 'number'},
|
||||
}
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances CPU core plugin.
|
||||
|
||||
Get stats about CPU core number.
|
||||
@ -54,8 +54,8 @@ class Plugin(GlancesPlugin):
|
||||
self.display_curse = False
|
||||
|
||||
# Do *NOT* uncomment the following line
|
||||
# @GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
# @GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update core stats.
|
||||
|
@ -23,8 +23,8 @@ from glances.logger import logger
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.globals import LINUX, iterkeys
|
||||
from glances.cpu_percent import cpu_percent
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.core.model import Plugin as CorePlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -96,7 +96,7 @@ items_history_list = [{'name': 'user',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances CPU plugin.
|
||||
|
||||
'stats' is a dictionary that contains the system-wide CPU utilization as a
|
||||
@ -119,8 +119,8 @@ class Plugin(GlancesPlugin):
|
||||
except Exception:
|
||||
self.nb_log_core = 1
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update CPU stats using the input method."""
|
||||
# Grab stats into self.stats
|
@ -22,7 +22,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from glances.globals import nativestr
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
|
||||
import psutil
|
||||
@ -37,7 +37,7 @@ items_history_list = [{'name': 'read_bytes',
|
||||
'y_unit': 'B/s'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances disks I/O plugin.
|
||||
|
||||
stats is a list
|
||||
@ -69,8 +69,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'disk_name'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update disk I/O stats using the input method."""
|
||||
# Init new stats
|
@ -24,11 +24,11 @@ import numbers
|
||||
|
||||
from glances.globals import nativestr
|
||||
from glances.folder_list import FolderList as glancesFolderList
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances folder plugin."""
|
||||
|
||||
def __init__(self, args=None, config=None):
|
||||
@ -49,8 +49,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'path'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the foldered list."""
|
||||
# Init new stats
|
@ -23,7 +23,7 @@ from __future__ import unicode_literals
|
||||
import operator
|
||||
|
||||
from glances.globals import u, nativestr, PermissionError
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -64,7 +64,7 @@ items_history_list = [{'name': 'percent',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances file system plugin.
|
||||
|
||||
stats is a list
|
||||
@ -84,8 +84,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'mnt_point'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the FS stats using the input method."""
|
||||
# Init new stats
|
@ -27,7 +27,7 @@ from copy import deepcopy
|
||||
from glances.logger import logger
|
||||
from glances.globals import iterkeys, itervalues, nativestr
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.processes import sort_stats as sort_stats_processes, weighted, glances_processes
|
||||
|
||||
# Docker-py library (optional and Linux-only)
|
||||
@ -71,7 +71,7 @@ items_history_list = [{'name': 'cpu_percent',
|
||||
export_exclude_list = ['cpu', 'io', 'memory', 'network']
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances Docker plugin.
|
||||
|
||||
stats is a dict: {'version': {...}, 'containers': [{}, {}]}
|
||||
@ -160,8 +160,8 @@ class Plugin(GlancesPlugin):
|
||||
else:
|
||||
return all_tag[0].lower() == 'true'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update Docker stats using the input method."""
|
||||
# Init new stats
|
@ -21,7 +21,7 @@
|
||||
|
||||
from glances.globals import nativestr, to_fahrenheit
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# In Glances 3.1.4 or higher, we use the py3nvml lib (see issue #1523)
|
||||
try:
|
||||
@ -43,7 +43,7 @@ items_history_list = [{'name': 'proc',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances GPU plugin (limited to NVIDIA chipsets).
|
||||
|
||||
stats is a list of dictionaries with one entry per GPU
|
||||
@ -80,8 +80,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'gpu_id'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the GPU stats."""
|
||||
# Init new stats
|
@ -24,10 +24,10 @@ Just a stupid plugin to display the help screen.
|
||||
"""
|
||||
|
||||
from glances import __version__, psutil_version
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances help plugin."""
|
||||
|
||||
def __init__(self, args=None, config=None):
|
@ -25,7 +25,7 @@ from json import loads
|
||||
from glances.globals import iterkeys, urlopen, queue
|
||||
from glances.logger import logger
|
||||
from glances.timer import Timer
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Import plugin specific dependency
|
||||
try:
|
||||
@ -47,7 +47,7 @@ urls = [('https://ip.42.pl/raw', False, None),
|
||||
('https://api.ipify.org/?format=json', True, 'ip')]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances IP Plugin.
|
||||
|
||||
stats is a dict
|
||||
@ -64,8 +64,8 @@ class Plugin(GlancesPlugin):
|
||||
if not import_error_tag:
|
||||
self.public_address = PublicIpAddress().get()
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update IP stats using the input method.
|
||||
|
@ -24,10 +24,10 @@ import operator
|
||||
|
||||
from glances.globals import LINUX
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances IRQ plugin.
|
||||
|
||||
stats is a list
|
||||
@ -49,8 +49,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return self.irq.get_key()
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the IRQ stats."""
|
||||
# Init new stats
|
@ -23,8 +23,8 @@ import os
|
||||
import psutil
|
||||
|
||||
from glances.globals import iteritems
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.core.model import Plugin as CorePlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
|
||||
# Fields description
|
||||
@ -63,7 +63,7 @@ items_history_list = [{'name': 'min1',
|
||||
'description': '15 minutes load'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances load plugin.
|
||||
|
||||
stats is a dict
|
||||
@ -97,8 +97,8 @@ class Plugin(GlancesPlugin):
|
||||
except (AttributeError, OSError):
|
||||
return None
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update load stats."""
|
||||
# Init new stats
|
@ -21,7 +21,7 @@
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.globals import iterkeys
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -95,7 +95,7 @@ items_history_list = [{'name': 'percent',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances' memory plugin.
|
||||
|
||||
stats is a dict
|
||||
@ -111,8 +111,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update RAM memory stats using the input method."""
|
||||
# Init new stats
|
@ -21,7 +21,7 @@
|
||||
|
||||
from glances.globals import iterkeys
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -65,7 +65,7 @@ items_history_list = [{'name': 'percent',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances swap memory plugin.
|
||||
|
||||
stats is a dict
|
||||
@ -81,8 +81,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update swap memory stats using the input method."""
|
||||
# Init new stats
|
@ -23,7 +23,7 @@ from __future__ import unicode_literals
|
||||
import base64
|
||||
|
||||
from glances.timer import getTimeSinceLastUpdate
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
|
||||
import psutil
|
||||
@ -74,7 +74,7 @@ items_history_list = [{'name': 'rx',
|
||||
'y_unit': 'bit/s'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances network plugin.
|
||||
|
||||
stats is a list
|
||||
@ -107,8 +107,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'interface_name'
|
||||
|
||||
# @GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
# @GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update network stats using the input method.
|
||||
|
@ -20,10 +20,10 @@
|
||||
"""Now (current date) plugin."""
|
||||
|
||||
from time import tzname, strftime
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Plugin to get the current date/time.
|
||||
|
||||
stats is (string)
|
@ -20,7 +20,7 @@
|
||||
"""Per-CPU plugin."""
|
||||
|
||||
from glances.cpu_percent import cpu_percent
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Define the history items list
|
||||
items_history_list = [{'name': 'user',
|
||||
@ -31,7 +31,7 @@ items_history_list = [{'name': 'user',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances per-CPU plugin.
|
||||
|
||||
'stats' is a list of dictionaries that contain the utilization percentages
|
||||
@ -52,8 +52,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'cpu_number'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update per-CPU stats using the input method."""
|
||||
# Init new stats
|
0
glances/plugins/plugin/__init__.py
Normal file
0
glances/plugins/plugin/__init__.py
Normal file
@ -57,8 +57,8 @@ fields_unit_type = {
|
||||
}
|
||||
|
||||
|
||||
class GlancesPlugin(object):
|
||||
"""Main class for Glances plugin."""
|
||||
class GlancesPluginModel(object):
|
||||
"""Main class for Glances plugin model."""
|
||||
|
||||
def __init__(self,
|
||||
args=None,
|
||||
@ -88,14 +88,10 @@ class GlancesPlugin(object):
|
||||
:items_history_list: list of items to store in the history
|
||||
:stats_init_value: Default value for a stats item
|
||||
"""
|
||||
# Plugin name (= module name without glances_)
|
||||
# pos = self.__class__.__module__.find('glances_') + len('glances') + 1
|
||||
# self.plugin_name = self.__class__.__module__[pos:]
|
||||
# TODO: For Glances 4 => 3 next line to be removed when all plugins are migrated
|
||||
if self.__class__.__module__.startswith('glances_'):
|
||||
self.plugin_name = self.__class__.__module__.split('glances_')[1]
|
||||
else:
|
||||
self.plugin_name = self.__class__.__module__
|
||||
# Build the plugin name
|
||||
self.plugin_name = self.__class__.__module__.split('.')[2]
|
||||
if self.plugin_name.startswith('glances_'):
|
||||
self.plugin_name = self.plugin_name.split('glances_')[1]
|
||||
logger.debug("Init {} plugin".format(self.plugin_name))
|
||||
|
||||
# Init the args
|
@ -31,7 +31,7 @@ from glances.ports_list import GlancesPortsList
|
||||
from glances.web_list import GlancesWebList
|
||||
from glances.timer import Timer, Counter
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
try:
|
||||
import requests
|
||||
@ -41,7 +41,7 @@ except ImportError as e:
|
||||
logger.warning("Missing Python Lib ({}), Ports plugin is limited to port scanning".format(e))
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances ports scanner plugin."""
|
||||
|
||||
def __init__(self, args=None, config=None):
|
||||
@ -69,8 +69,8 @@ class Plugin(GlancesPlugin):
|
||||
# Call the father class
|
||||
super(Plugin, self).exit()
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the ports list."""
|
||||
if self.input_method == 'local':
|
@ -20,7 +20,7 @@
|
||||
"""Process count plugin."""
|
||||
|
||||
from glances.processes import glances_processes
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Define the history items list
|
||||
items_history_list = [{'name': 'total',
|
||||
@ -37,7 +37,7 @@ items_history_list = [{'name': 'total',
|
||||
'y_unit': ''}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances process count plugin.
|
||||
|
||||
stats is a list
|
||||
@ -62,8 +62,8 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Note: 'glances_processes' is already init in the glances_processes.py script
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update processes stats using the input method."""
|
||||
# Init new stats
|
@ -25,8 +25,8 @@ import copy
|
||||
from glances.logger import logger
|
||||
from glances.globals import WINDOWS, key_exist_value_not_none_not_v
|
||||
from glances.processes import glances_processes, sort_stats
|
||||
from glances.plugins.core import Plugin as CorePlugin
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.core.model import Plugin as CorePlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
def seconds_to_hms(input_seconds):
|
||||
@ -48,7 +48,7 @@ def split_cmdline(cmdline):
|
||||
return path, cmd, arguments
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances' processes plugin.
|
||||
|
||||
stats is a list
|
@ -20,10 +20,10 @@
|
||||
"""psutil plugin."""
|
||||
|
||||
from glances import psutil_version_info
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Get the psutil version for client/server purposes.
|
||||
|
||||
stats is a tuple
|
||||
@ -39,8 +39,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Reset/init the stats."""
|
||||
self.stats = None
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the stats."""
|
||||
# Reset stats
|
@ -23,7 +23,7 @@ from glances.cpu_percent import cpu_percent
|
||||
from glances.logger import logger
|
||||
from glances.outputs.glances_bars import Bar
|
||||
from glances.outputs.glances_sparklines import Sparkline
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -44,7 +44,7 @@ items_history_list = [{'name': 'cpu',
|
||||
'y_unit': '%'}]
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances quicklook plugin.
|
||||
|
||||
'stats' is a dictionary.
|
||||
@ -58,8 +58,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update quicklook stats using the input method."""
|
||||
# Init new stats
|
@ -21,7 +21,7 @@
|
||||
|
||||
from glances.globals import iterkeys
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Import plugin specific dependency
|
||||
try:
|
||||
@ -33,7 +33,7 @@ else:
|
||||
import_error_tag = False
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances RAID plugin.
|
||||
|
||||
stats is a dict (see pymdstat documentation)
|
||||
@ -46,8 +46,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update RAID stats using the input method."""
|
||||
# Init new stats
|
@ -27,13 +27,13 @@ from glances.globals import iteritems, to_fahrenheit
|
||||
from glances.timer import Counter
|
||||
from glances.plugins.sensors.sensor.glances_batpercent import Plugin as BatPercentPlugin
|
||||
from glances.plugins.sensors.sensor.glances_hddtemp import Plugin as HddTempPlugin
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
SENSOR_TEMP_UNIT = 'C'
|
||||
SENSOR_FAN_UNIT = 'R'
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances sensors plugin.
|
||||
|
||||
The stats list includes both sensors and hard disks stats, if any.
|
||||
@ -78,8 +78,8 @@ class Plugin(GlancesPlugin):
|
||||
"""Return the key of the list."""
|
||||
return 'label'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update sensors stats using the input method."""
|
||||
# Init new stats
|
@ -22,7 +22,7 @@
|
||||
import psutil
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# Batinfo library (optional; Linux-only)
|
||||
batinfo_tag = True
|
||||
@ -43,7 +43,7 @@ except Exception as e:
|
||||
psutil_tag = False
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances battery capacity plugin.
|
||||
|
||||
stats is a list
|
||||
@ -69,8 +69,8 @@ class Plugin(GlancesPlugin):
|
||||
# The HDD temp is displayed within the sensors plugin
|
||||
self.display_curse = False
|
||||
|
||||
# @GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
# @GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update battery capacity stats using the input method."""
|
||||
# Init new stats
|
||||
|
@ -24,10 +24,10 @@ import socket
|
||||
|
||||
from glances.globals import nativestr
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances HDD temperature sensors plugin.
|
||||
|
||||
stats is a list
|
||||
@ -52,8 +52,8 @@ class Plugin(GlancesPlugin):
|
||||
# The HDD temp is displayed within the sensors plugin
|
||||
self.display_curse = False
|
||||
|
||||
# @GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
# @GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update HDD stats using the input method."""
|
||||
# Init new stats
|
||||
|
@ -44,7 +44,7 @@ Check for admin access. If no admin access, disable SMART plugin.
|
||||
If smartmontools is not installed, we should catch the error upstream in plugin initialization.
|
||||
"""
|
||||
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.logger import logger
|
||||
from glances.main import disable
|
||||
from glances.globals import is_admin
|
||||
@ -128,7 +128,7 @@ def get_smart_data():
|
||||
return stats
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""
|
||||
Glances' HDD SMART plugin.
|
||||
|
||||
@ -150,8 +150,8 @@ class Plugin(GlancesPlugin):
|
||||
# We want to display the stat in the curse interface
|
||||
self.display_curse = True
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update SMART stats using the input method."""
|
||||
# Init new stats
|
@ -26,7 +26,7 @@ from io import open
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.globals import iteritems
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
# SNMP OID
|
||||
snmp_oid = {'default': {'hostname': '1.3.6.1.2.1.1.5.0',
|
||||
@ -77,7 +77,7 @@ def _linux_os_release():
|
||||
return pretty_name
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
|
||||
"""Glances' host/system plugin.
|
||||
|
||||
@ -95,8 +95,8 @@ class Plugin(GlancesPlugin):
|
||||
if self.get_refresh():
|
||||
self.set_refresh(60)
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update the host/system info using the input method.
|
||||
|
||||
@ -171,6 +171,10 @@ class Plugin(GlancesPlugin):
|
||||
# Init the return message
|
||||
ret = []
|
||||
|
||||
# Only process if stats exist and plugin not disabled
|
||||
if not self.stats or self.is_disable():
|
||||
return ret
|
||||
|
||||
# Build the string message
|
||||
if args.client:
|
||||
# Client mode
|
@ -21,7 +21,7 @@
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
|
||||
@ -29,7 +29,7 @@ import psutil
|
||||
snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'}
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances uptime plugin.
|
||||
|
||||
stats is date (string)
|
||||
@ -57,8 +57,8 @@ class Plugin(GlancesPlugin):
|
||||
# Correct issue #1092 (thanks to @IanTAtWork)
|
||||
return {'seconds': int(self.uptime.total_seconds())}
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update uptime stat using the input method."""
|
||||
# Init new stats
|
||||
@ -86,4 +86,8 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the string to display in the curse interface."""
|
||||
return [self.curse_add_line('Uptime: {}'.format(self.stats))]
|
||||
# Only process if stats exist and plugin not disabled
|
||||
if not self.stats or self.is_disable():
|
||||
return []
|
||||
else:
|
||||
return [self.curse_add_line('Uptime: {}'.format(self.stats))]
|
@ -23,7 +23,7 @@ import operator
|
||||
|
||||
from glances.globals import nativestr
|
||||
from glances.logger import logger
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
|
||||
import psutil
|
||||
# Use the Wifi Python lib (https://pypi.python.org/pypi/wifi)
|
||||
@ -42,7 +42,7 @@ import_error_tag = True
|
||||
logger.warning("Wifi lib is not compliant with Python 3, Wifi plugin is disabled")
|
||||
|
||||
|
||||
class Plugin(GlancesPlugin):
|
||||
class Plugin(GlancesPluginModel):
|
||||
"""Glances Wifi plugin.
|
||||
|
||||
Get stats of the current Wifi hotspots.
|
||||
@ -64,8 +64,8 @@ class Plugin(GlancesPlugin):
|
||||
"""
|
||||
return 'ssid'
|
||||
|
||||
@GlancesPlugin._check_decorator
|
||||
@GlancesPlugin._log_result_decorator
|
||||
@GlancesPluginModel._check_decorator
|
||||
@GlancesPluginModel._log_result_decorator
|
||||
def update(self):
|
||||
"""Update Wifi stats using the input method.
|
||||
|
@ -105,9 +105,9 @@ class GlancesStats(object):
|
||||
|
||||
def _load_plugin(self, plugin_path, args=None, config=None):
|
||||
"""Load the plugin, init it and add to the _plugin dict."""
|
||||
# The key is the plugin name = plugin_path
|
||||
# for example, the path ./glances/plugins/xxx
|
||||
# generate self._plugins_list["xxx"] = ...
|
||||
# The key is the plugin_path
|
||||
# except when it starts with glances_xxx
|
||||
# generate self._plugins_list["xxx"] = <instance of xxx Plugin>
|
||||
if plugin_path.startswith('glances_'):
|
||||
# Avoid circular loop when Glances plugin uses lib with same name
|
||||
# Example: docker should be named to glances_docker
|
||||
@ -118,7 +118,7 @@ class GlancesStats(object):
|
||||
# Load the plugin class
|
||||
try:
|
||||
# Import the plugin
|
||||
plugin = import_module(plugin_path)
|
||||
plugin = import_module('glances.plugins.' + plugin_path + '.model')
|
||||
# Init and add the plugin to the dictionary
|
||||
self._plugins[name] = plugin.Plugin(args=args, config=config)
|
||||
except Exception as e:
|
||||
@ -144,7 +144,8 @@ class GlancesStats(object):
|
||||
|
||||
for item in os.listdir(plugins_path):
|
||||
if os.path.isdir(os.path.join(plugins_path, item)) and \
|
||||
not item.startswith('__'):
|
||||
not item.startswith('__') and \
|
||||
item != 'plugin':
|
||||
# Load the plugin
|
||||
start_duration.reset()
|
||||
self._load_plugin(os.path.basename(item),
|
||||
|
@ -39,7 +39,7 @@ from glances.thresholds import GlancesThresholdCareful
|
||||
from glances.thresholds import GlancesThresholdWarning
|
||||
from glances.thresholds import GlancesThresholdCritical
|
||||
from glances.thresholds import GlancesThresholds
|
||||
from glances.plugins.plugin import GlancesPlugin
|
||||
from glances.plugins.plugin.model import GlancesPluginModel
|
||||
from glances.secure import secure_popen
|
||||
|
||||
# Global variables
|
||||
|
Loading…
Reference in New Issue
Block a user