diff --git a/glances/plugins/glances_alert.py b/glances/plugins/glances_alert.py index 1bafda9e13e822ecade5732170f82b00808731f1..a6a59238e017c3a66a1ca7b4cd19234c44d082a4 100644 --- a/glances/plugins/glances_alert.py +++ b/glances/plugins/glances_alert.py @@ -23,7 +23,7 @@ from datetime import datetime from glances.logs import glances_logs from glances.thresholds import glances_thresholds -from glances.logger import logger +# from glances.logger import logger from glances.plugins.glances_plugin import GlancesPlugin # Static decision tree for the global alert message @@ -61,8 +61,10 @@ tree = [{'msg': 'No warning or critical alert detected', def global_message(): - """Parse the decision tree and return the message - corresponding to the current threasholds values""" + """Parse the decision tree and return the message. + + Note: message corresponding to the current threasholds values + """ # Compute the weight for each item in the tree current_thresholds = glances_thresholds.get() for i in tree: @@ -76,7 +78,6 @@ def global_message(): class Plugin(GlancesPlugin): - """Glances alert plugin. Only for display. diff --git a/glances/plugins/glances_amps.py b/glances/plugins/glances_amps.py index afa218c1b554d604d3a360803d21405ab6eb7ae9..6270864e2686bff3288dc8f79382beb9968d9e7a 100644 --- a/glances/plugins/glances_amps.py +++ b/glances/plugins/glances_amps.py @@ -25,7 +25,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances AMPs plugin.""" def __init__(self, args=None, config=None): diff --git a/glances/plugins/glances_batpercent.py b/glances/plugins/glances_batpercent.py index 0891e8a6cde23250443530f43c9cf31547c2669b..161958be4cc8a8a750cd1d1dc0fe267bf05fd51d 100644 --- a/glances/plugins/glances_batpercent.py +++ b/glances/plugins/glances_batpercent.py @@ -42,7 +42,6 @@ except AttributeError: class Plugin(GlancesPlugin): - """Glances battery capacity plugin. stats is a list @@ -87,7 +86,6 @@ class Plugin(GlancesPlugin): class GlancesGrabBat(object): - """Get batteries stats using the batinfo library.""" def __init__(self): diff --git a/glances/plugins/glances_cloud.py b/glances/plugins/glances_cloud.py index 5a59764fe6a993e8fca62ed2e05f1e8913c37d20..430fd01eaf036ae35c8e497a614e09b8079140c0 100644 --- a/glances/plugins/glances_cloud.py +++ b/glances/plugins/glances_cloud.py @@ -38,7 +38,6 @@ from glances.logger import logger class Plugin(GlancesPlugin): - """Glances' cloud plugin. The goal of this plugin is to retreive additional information @@ -70,7 +69,7 @@ class Plugin(GlancesPlugin): self.stats = {} def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" self.aws_ec2.stop() # Call the father class super(Plugin, self).exit() @@ -137,7 +136,7 @@ class ThreadAwsEc2Grabber(threading.Thread): 'region': 'placement/availability-zone'} def __init__(self): - """Init the class""" + """Init the class.""" logger.debug("cloud plugin - Create thread for AWS EC2") super(ThreadAwsEc2Grabber, self).__init__() # Event needed to stop properly the thread @@ -146,9 +145,10 @@ class ThreadAwsEc2Grabber(threading.Thread): self._stats = {} def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab plugin's stats. + Infinite loop, should be stopped by calling the stop() method + """ if not cloud_tag: logger.debug("cloud plugin - Requests lib is not installed") self.stop() @@ -170,19 +170,19 @@ class ThreadAwsEc2Grabber(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("cloud plugin - Close thread for AWS EC2") self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() diff --git a/glances/plugins/glances_core.py b/glances/plugins/glances_core.py index 7fefd3bf9cb571170ea68b49453283bc5cc5be67..98ec138394893447d57c9f2e517fe192edfe53c0 100644 --- a/glances/plugins/glances_core.py +++ b/glances/plugins/glances_core.py @@ -25,7 +25,6 @@ import psutil class Plugin(GlancesPlugin): - """Glances CPU core plugin. Get stats about CPU core number. diff --git a/glances/plugins/glances_cpu.py b/glances/plugins/glances_cpu.py index 5bdbb6d101526f613d415a424c960cd401775460..705e650d2a6c7dcff38355262477d8d0e2329332 100644 --- a/glances/plugins/glances_cpu.py +++ b/glances/plugins/glances_cpu.py @@ -57,7 +57,6 @@ items_history_list = [{'name': 'user', class Plugin(GlancesPlugin): - """Glances CPU plugin. 'stats' is a dictionary that contains the system-wide CPU utilization as a @@ -88,7 +87,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update CPU stats using the input method.""" - # Reset stats self.reset() diff --git a/glances/plugins/glances_diskio.py b/glances/plugins/glances_diskio.py index 308d610dd45d71810e94e7d7b9a103c02bd4c916..f6ce21b2c50311145884cf0199e95d1c4698e621 100644 --- a/glances/plugins/glances_diskio.py +++ b/glances/plugins/glances_diskio.py @@ -41,7 +41,6 @@ items_history_list = [{'name': 'read_bytes', class Plugin(GlancesPlugin): - """Glances disks I/O plugin. stats is a list diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py index 0e178b356d41b638609a8be6e1e9889e55b27836..b88f4cd367da9523e19c2315eea390057bb93bc1 100644 --- a/glances/plugins/glances_docker.py +++ b/glances/plugins/glances_docker.py @@ -40,7 +40,6 @@ else: class Plugin(GlancesPlugin): - """Glances Docker plugin. stats is a dict: {'version': {...}, 'containers': [{}, {}]} @@ -68,7 +67,7 @@ class Plugin(GlancesPlugin): self.reset() def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" for t in itervalues(self.thread_list): t.stop() # Call the father class @@ -105,7 +104,7 @@ class Plugin(GlancesPlugin): self.stats = {} 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 # Set the following key to True to display all containers @@ -121,7 +120,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update Docker stats using the input method.""" - # Reset stats self.reset() @@ -410,8 +408,10 @@ class Plugin(GlancesPlugin): return os.sysconf(os.sysconf_names['SC_CLK_TCK']) def get_stats_action(self): - """Return stats for the action - Docker will return self.stats['containers']""" + """Return stats for the action. + + Docker will return self.stats['containers'] + """ return self.stats['containers'] def update_views(self): @@ -587,7 +587,8 @@ class ThreadDockerGrabber(threading.Thread): """ def __init__(self, container): - """Init the class: + """Init the class. + container: instance of Docker-py Container """ super(ThreadDockerGrabber, self).__init__() @@ -601,9 +602,10 @@ class ThreadDockerGrabber(threading.Thread): logger.debug("docker plugin - Create thread for container {}".format(self._container.name)) def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab the stats. + Infinite loop, should be stopped by calling the stop() method + """ for i in self._stats_stream: self._stats = i time.sleep(0.1) @@ -612,19 +614,19 @@ class ThreadDockerGrabber(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("docker plugin - Close thread for container {}".format(self._container.name)) self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() diff --git a/glances/plugins/glances_folders.py b/glances/plugins/glances_folders.py index 3b17a227a84d6572bd06f6e3ec6c7df13dae91d7..2704a74cecb37ab3141c6b0c230dad9ae5beff9d 100644 --- a/glances/plugins/glances_folders.py +++ b/glances/plugins/glances_folders.py @@ -26,7 +26,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances folder plugin.""" def __init__(self, args=None): @@ -76,8 +75,7 @@ class Plugin(GlancesPlugin): return self.stats def get_alert(self, stat): - """Manage limits of the folder list""" - + """Manage limits of the folder list.""" if not isinstance(stat['size'], numbers.Number): return 'DEFAULT' else: diff --git a/glances/plugins/glances_fs.py b/glances/plugins/glances_fs.py index ce86d9bb135f4c9742a5708bd813b58a13aaec42..cb3d7459ab8b8f264484ce78313f4699703a6ca5 100644 --- a/glances/plugins/glances_fs.py +++ b/glances/plugins/glances_fs.py @@ -66,7 +66,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances file system plugin. stats is a list diff --git a/glances/plugins/glances_gpu.py b/glances/plugins/glances_gpu.py index 24a3c9897330a37dbdea018e063c701c3bf825cd..33518f28bf976d0a8e204996a36a43253ea538b3 100644 --- a/glances/plugins/glances_gpu.py +++ b/glances/plugins/glances_gpu.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -"""GPU plugin (limited to NVIDIA chipsets)""" +"""GPU plugin (limited to NVIDIA chipsets).""" from glances.compat import nativestr from glances.logger import logger @@ -34,14 +34,13 @@ else: class Plugin(GlancesPlugin): - """Glances GPU plugin (limited to NVIDIA chipsets). stats is a list of dictionaries with one entry per GPU """ def __init__(self, args=None): - """Init the plugin""" + """Init the plugin.""" super(Plugin, self).__init__(args=args) # Init the NVidia API @@ -58,7 +57,7 @@ class Plugin(GlancesPlugin): self.stats = [] def init_nvidia(self): - """Init the NVIDIA API""" + """Init the NVIDIA API.""" if not gpu_nvidia_tag: self.nvml_ready = False @@ -79,8 +78,7 @@ class Plugin(GlancesPlugin): @GlancesPlugin._check_decorator @GlancesPlugin._log_result_decorator def update(self): - """Update the GPU stats""" - + """Update the GPU stats.""" self.reset() # !!! JUST FOR TEST @@ -212,7 +210,7 @@ class Plugin(GlancesPlugin): return ret def get_device_stats(self): - """Get GPU stats""" + """Get GPU stats.""" stats = [] for index, device_handle in enumerate(self.device_handles): @@ -232,7 +230,7 @@ class Plugin(GlancesPlugin): return stats 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: try: pynvml.nvmlShutdown() @@ -244,14 +242,15 @@ class Plugin(GlancesPlugin): def get_device_handles(): - """ - Returns a list of NVML device handles, one per device. Can throw NVMLError. + """Get a list of NVML device handles, one per device. + + Can throw NVMLError. """ return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())] def get_device_name(device_handle): - """Get GPU device name""" + """Get GPU device name.""" try: return nativestr(pynvml.nvmlDeviceGetName(device_handle)) except pynvml.NVMlError: @@ -259,7 +258,7 @@ def get_device_name(device_handle): def get_mem(device_handle): - """Get GPU device memory consumption in percent""" + """Get GPU device memory consumption in percent.""" try: memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle) return memory_info.used * 100.0 / memory_info.total @@ -268,7 +267,7 @@ def get_mem(device_handle): def get_proc(device_handle): - """Get GPU device CPU consumption in percent""" + """Get GPU device CPU consumption in percent.""" try: return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu except pynvml.NVMLError: diff --git a/glances/plugins/glances_hddtemp.py b/glances/plugins/glances_hddtemp.py index eabe5af63d7cbad59c07f3fbd7379dcdb1d84436..dccf67b42d9a7500216d01ec10c0b8c270b34237 100644 --- a/glances/plugins/glances_hddtemp.py +++ b/glances/plugins/glances_hddtemp.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances HDD temperature sensors plugin. stats is a list @@ -72,7 +71,6 @@ class Plugin(GlancesPlugin): class GlancesGrabHDDTemp(object): - """Get hddtemp stats using a socket connection.""" def __init__(self, host='127.0.0.1', port=7634, args=None): diff --git a/glances/plugins/glances_help.py b/glances/plugins/glances_help.py index 9103251258cdbd04fe0a73949c3663d6cfa75c0a..c7701445bd8b3547eb894e8f097d8583d25efb6b 100644 --- a/glances/plugins/glances_help.py +++ b/glances/plugins/glances_help.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances help plugin.""" def __init__(self, args=None, config=None): @@ -54,6 +53,7 @@ class Plugin(GlancesPlugin): pass def generate_view_data(self): + """Generate the views.""" self.view_data['version'] = '{} {}'.format('Glances', __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' def get_view_data(self, args=None): + """Return the view.""" return self.view_data def msg_curse(self, args=None): diff --git a/glances/plugins/glances_ip.py b/glances/plugins/glances_ip.py index 160baa578ea3caa16142e5f917dcc8f707797e00..12657c810d57fc1b4e360797deb5837c5c096316 100644 --- a/glances/plugins/glances_ip.py +++ b/glances/plugins/glances_ip.py @@ -52,7 +52,6 @@ urls = [('http://ip.42.pl/raw', False, None), class Plugin(GlancesPlugin): - """Glances IP Plugin. stats is a dict @@ -159,13 +158,14 @@ class Plugin(GlancesPlugin): class PublicIpAddress(object): - """Get public IP address from online services""" + """Get public IP address from online services.""" def __init__(self, timeout=2): + """Init the class.""" self.timeout = timeout 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() for u, j, k in urls: @@ -182,7 +182,7 @@ class PublicIpAddress(object): return ip 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: response = urlopen(url, timeout=self.timeout).read().decode('utf-8') except Exception as e: diff --git a/glances/plugins/glances_irq.py b/glances/plugins/glances_irq.py index 606c7a1a5e7099dd19b88d7b2360bb231cd18dfb..1ade5b35c5b88fd9710954fbf4b688bc01ecb7a5 100644 --- a/glances/plugins/glances_irq.py +++ b/glances/plugins/glances_irq.py @@ -28,7 +28,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances IRQ plugin. stats is a list @@ -56,8 +55,7 @@ class Plugin(GlancesPlugin): @GlancesPlugin._check_decorator @GlancesPlugin._log_result_decorator def update(self): - """Update the IRQ stats""" - + """Update the IRQ stats.""" # Reset the list self.reset() @@ -117,27 +115,25 @@ class Plugin(GlancesPlugin): class GlancesIRQ(object): - """ - This class manages the IRQ file - """ + """This class manages the IRQ file.""" IRQ_FILE = '/proc/interrupts' def __init__(self): - """ - Init the class + """Init the class. + The stat are stored in a internal list of dict """ self.lasts = {} self.reset() def reset(self): - """Reset the stats""" + """Reset the stats.""" self.stats = [] self.cpu_number = 0 def get(self): - """Return the current IRQ stats""" + """Return the current IRQ stats.""" return self.__update() def get_key(self): @@ -145,7 +141,7 @@ class GlancesIRQ(object): return 'irq_line' def __header(self, line): - """The header contain the number of CPU + """Build the header (contain the number of CPU). CPU0 CPU1 CPU2 CPU3 0: 21 0 0 0 IO-APIC 2-edge timer @@ -154,8 +150,7 @@ class GlancesIRQ(object): return self.cpu_number 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: 1: 44487 341 44 72 IO-APIC 1-edge i8042 @@ -169,8 +164,7 @@ class GlancesIRQ(object): return irq_line def __sum(self, line): - """Get a line and - Return the IRQ sum number + """Return the IRQ sum number. IRQ line samples: 1: 44487 341 44 72 IO-APIC 1-edge i8042 @@ -186,10 +180,7 @@ class GlancesIRQ(object): return ret def __update(self): - """ - Load the IRQ file and update the internal dict - """ - + """Load the IRQ file and update the internal dict.""" self.reset() if not os.path.exists(self.IRQ_FILE): diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py index b1e0d0ea4bc412de52353db1f5ec9c9ac6294f1c..9246894c91b6d1233a1a63fe50f49c90816a530a 100644 --- a/glances/plugins/glances_load.py +++ b/glances/plugins/glances_load.py @@ -48,7 +48,6 @@ items_history_list = [{'name': 'min1', class Plugin(GlancesPlugin): - """Glances load plugin. stats is a dict diff --git a/glances/plugins/glances_mem.py b/glances/plugins/glances_mem.py index eaebfa97f984bd9e3f7d55299e3f998c2704ff48..d6bf6a4c8b4979fcb3d6e814725827017dbe8de3 100644 --- a/glances/plugins/glances_mem.py +++ b/glances/plugins/glances_mem.py @@ -56,7 +56,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances' memory plugin. stats is a dict diff --git a/glances/plugins/glances_memswap.py b/glances/plugins/glances_memswap.py index ec8f7bee2c09d5d86303f6913d55f01d4c5bb197..4ba1849d66e750f74f17d86e14c4318aed407fc0 100644 --- a/glances/plugins/glances_memswap.py +++ b/glances/plugins/glances_memswap.py @@ -44,7 +44,6 @@ items_history_list = [{'name': 'percent', class Plugin(GlancesPlugin): - """Glances swap memory plugin. stats is a dict diff --git a/glances/plugins/glances_network.py b/glances/plugins/glances_network.py index d6fef25d0695c4493ed31761feb0368544858102..d05f54e189a5c129ad760ecdccf9f000df2be8e0 100644 --- a/glances/plugins/glances_network.py +++ b/glances/plugins/glances_network.py @@ -48,7 +48,6 @@ items_history_list = [{'name': 'rx', class Plugin(GlancesPlugin): - """Glances network plugin. stats is a list diff --git a/glances/plugins/glances_now.py b/glances/plugins/glances_now.py index 52c6b3626ddc4ee1cd5936be012e1afec015fa8f..9818247cb5b4697b0077d170aa88953722d68d8c 100644 --- a/glances/plugins/glances_now.py +++ b/glances/plugins/glances_now.py @@ -17,13 +17,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +"""Now (current date) plugin.""" + from datetime import datetime from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Plugin to get the current date/time. stats is (string) diff --git a/glances/plugins/glances_percpu.py b/glances/plugins/glances_percpu.py index 3bc4e558743ea6da6d84451ee15941ef9f510153..c9c4f3301b8c7882ad8c6513e73613dc6c4c45ef 100644 --- a/glances/plugins/glances_percpu.py +++ b/glances/plugins/glances_percpu.py @@ -24,7 +24,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances per-CPU plugin. 'stats' is a list of dictionaries that contain the utilization percentages diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index ffeb7a17f3bd1124ce49e3e70aacfdd9371f7170..5dbf28ec85727d6fa1fdd1cf16c2baa1b2d6fe82 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -36,7 +36,6 @@ from glances.thresholds import glances_thresholds class GlancesPlugin(object): - """Main class for Glances plugin.""" def __init__(self, args=None, items_history_list=None): @@ -61,7 +60,6 @@ class GlancesPlugin(object): :args: args parameters :items_history_list: list of items to store in the history """ - # Plugin name (= module name without glances_) self.plugin_name = self.__class__.__module__[len('glances_'):] # logger.debug("Init plugin %s" % self.plugin_name) @@ -103,11 +101,13 @@ class GlancesPlugin(object): def reset(self): """Reset the stats. - This method should be overwrited by childs' classes""" + + This method should be overwrited by childs' classes. + """ self.stats = None 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)) def get_key(self): @@ -115,7 +115,7 @@ class GlancesPlugin(object): return None def is_enable(self): - """Return true if plugin is enabled""" + """Return true if plugin is enabled.""" try: d = getattr(self.args, 'disable_' + self.plugin_name) except AttributeError: @@ -124,12 +124,14 @@ class GlancesPlugin(object): return d is False def is_disable(self): - """Return true if plugin is disabled""" + """Return true if plugin is disabled.""" return not self.is_enable() def _json_dumps(self, d): - """Return the object 'd' in a JSON format - Manage the issue #815 for Windows OS""" + """Return the object 'd' in a JSON format. + + Manage the issue #815 for Windows OS + """ try: return json.dumps(d) except UnicodeDecodeError: @@ -185,11 +187,13 @@ class GlancesPlugin(object): return self.items_history_list 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 for the given item (list) instead - 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) if item is None: return s @@ -200,11 +204,13 @@ class GlancesPlugin(object): return None 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 for the given item (list) instead - 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) if item is None: return s @@ -216,12 +222,16 @@ class GlancesPlugin(object): def get_export_history(self, item=None): """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) def get_stats_history(self, item=None, nb=0): - """Return the stats history as a JSON object (dict or None). - Limit to lasts nb items (all if nb=0)""" + """Return the stats history (JSON format). + + Limit to lasts nb items (all if nb=0) + """ s = self.get_json_history(nb=nb) if item is None: @@ -245,7 +255,8 @@ class GlancesPlugin(object): return None 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 and the current one. """ @@ -391,7 +402,7 @@ class GlancesPlugin(object): return None def update_views(self): - """Default builder fo the stats views. + """Update the stats views. The V of MVC A dict of dict with the needed information to display the stats. @@ -458,12 +469,11 @@ class GlancesPlugin(object): return 'DEFAULT' 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)) def load_limits(self, config): """Load limits from the configuration file, if it exists.""" - # By default set the history length to 3 points per second during one day self._limits['history_size'] = 28800 @@ -499,10 +509,12 @@ class GlancesPlugin(object): self._limits = input_limits def get_stats_action(self): - """Return stats for the action + """Return stats for the action. + By default return all the stats. 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 def get_alert(self, @@ -589,7 +601,7 @@ class GlancesPlugin(object): def manage_threshold(self, stat_name, trigger): - """Manage the threshold for the current stat""" + """Manage the threshold for the current stat.""" glances_thresholds.add(stat_name, trigger) # logger.info(glances_thresholds.get()) @@ -598,7 +610,7 @@ class GlancesPlugin(object): trigger, header, 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 ? try: 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=""): """Return the tuple (action, repeat) for the alert. + - action is a command line - - repeat is a bool""" + - repeat is a bool + """ # Get the action for stat + header # Exemple: network_wlan0_rx_careful_action # Action key available ? @@ -714,8 +728,8 @@ class GlancesPlugin(object): return [] 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. It is a comma separed list of regexp. Example for diskio: @@ -818,8 +832,6 @@ class GlancesPlugin(object): """Make a nice human-readable string out of number. Number of decimal places increases as quantity approaches 1. - - examples: CASE: 613421788 RESULT: 585M low_precision: 585M CASE: 5307033647 RESULT: 4.94G low_precision: 4.9G CASE: 44968414685 RESULT: 41.9G low_precision: 41.9G @@ -866,8 +878,10 @@ class GlancesPlugin(object): return '{!s}'.format(number) def trend_msg(self, trend, significant=1): - """Return the trend message - Do not take into account if trend < significant""" + """Return the trend message. + + Do not take into account if trend < significant + """ ret = '-' if trend is None: ret = ' ' diff --git a/glances/plugins/glances_ports.py b/glances/plugins/glances_ports.py index 2e3202af11d657b1d5e707f50154404794e3f486..c14951652c1a676618122c12c63f231e9417e434 100644 --- a/glances/plugins/glances_ports.py +++ b/glances/plugins/glances_ports.py @@ -42,7 +42,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances ports scanner plugin.""" def __init__(self, args=None, config=None): @@ -64,7 +63,7 @@ class Plugin(GlancesPlugin): self._thread = None def exit(self): - """Overwrite the exit method to close threads""" + """Overwrite the exit method to close threads.""" if self._thread is not None: self._thread.stop() # Call the father class @@ -77,7 +76,6 @@ class Plugin(GlancesPlugin): @GlancesPlugin._log_result_decorator def update(self): """Update the ports list.""" - if self.input_method == 'local': # Only refresh: # * if there is not other scanning thread @@ -103,7 +101,6 @@ class Plugin(GlancesPlugin): def get_ports_alert(self, port, header="", log=False): """Return the alert status relative to the port scan return value.""" - if port['status'] is None: return 'CAREFUL' elif port['status'] == 0: @@ -117,7 +114,6 @@ class Plugin(GlancesPlugin): def get_web_alert(self, web, header="", log=False): """Return the alert status relative to the web/url scan return value.""" - if web['status'] is None: return 'CAREFUL' elif web['status'] not in [200, 301, 302]: @@ -186,7 +182,7 @@ class ThreadScanner(threading.Thread): """ def __init__(self, stats): - """Init the class""" + """Init the class.""" logger.debug("ports plugin - Create thread for scan list {}".format(stats)) super(ThreadScanner, self).__init__() # Event needed to stop properly the thread @@ -197,9 +193,10 @@ class ThreadScanner(threading.Thread): self.plugin_name = "ports" def run(self): - """Function called to grab stats. - Infinite loop, should be stopped by calling the stop() method""" + """Grab the stats. + Infinite loop, should be stopped by calling the stop() method. + """ for p in self._stats: # End of the thread has been asked if self.stopped(): @@ -216,25 +213,25 @@ class ThreadScanner(threading.Thread): @property def stats(self): - """Stats getter""" + """Stats getter.""" return self._stats @stats.setter def stats(self, value): - """Stats setter""" + """Stats setter.""" self._stats = value def stop(self, timeout=None): - """Stop the thread""" + """Stop the thread.""" logger.debug("ports plugin - Close thread for scan list {}".format(self._stats)) self._stopper.set() def stopped(self): - """Return True is the thread is stopped""" + """Return True is the thread is stopped.""" return self._stopper.isSet() 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: req = requests.head(web['url'], allow_redirects=True, @@ -249,14 +246,14 @@ class ThreadScanner(threading.Thread): return web 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: return self._port_scan_icmp(port) else: return self._port_scan_tcp(port) def _resolv_name(self, hostname): - """Convert hostname to IP address""" + """Convert hostname to IP address.""" ip = hostname try: ip = socket.gethostbyname(hostname) @@ -265,7 +262,7 @@ class ThreadScanner(threading.Thread): return ip 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 # Create the ping command @@ -305,7 +302,7 @@ class ThreadScanner(threading.Thread): return ret 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 # Create and configure the scanning socket diff --git a/glances/plugins/glances_processcount.py b/glances/plugins/glances_processcount.py index 2ffd18b7e595edc9e2b5712f7566166e92eed792..03620c82dda3393f3eb33350e3b05c16ef51a298 100644 --- a/glances/plugins/glances_processcount.py +++ b/glances/plugins/glances_processcount.py @@ -27,7 +27,6 @@ from glances.plugins.glances_plugin import GlancesPlugin class Plugin(GlancesPlugin): - """Glances process count plugin. stats is a list diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index f10b513033ba3137c47b4964100c6f88f6500c9d..c059e57a5e56ab3754c83f4fc52e6d55744b8fd8 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -57,7 +57,6 @@ def split_cmdline(cmdline): class Plugin(GlancesPlugin): - """Glances' processes plugin. stats is a list @@ -202,6 +201,7 @@ class Plugin(GlancesPlugin): def get_process_curses_data(self, p, first, args): """Get curses data to display for a process. + - p is the process to display - first is a tag=True if the process is the first on the list """ @@ -466,9 +466,7 @@ class Plugin(GlancesPlugin): return ret 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' 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): """ - 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 * sep_char: define the line separation char * 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)) 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: return 'DEFAULT' else: return 'FILTER' def __mmm_reset(self): - """ - Reset the MMM stats - """ + """Reset the MMM stats.""" self.mmm_min = {} self.mmm_max = {} 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] * mmm: display min, max, mean or current (if mmm=None) """ @@ -647,13 +642,13 @@ class Plugin(GlancesPlugin): return ret 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, tree=glances_processes.is_tree_enabled(), reverse=glances_processes.sort_reverse) 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: return len(str(self.pid_max)) else: diff --git a/glances/plugins/glances_psutilversion.py b/glances/plugins/glances_psutilversion.py index 7945ac26b500136ec0bef51d96b98d5f7b65ffc7..bffa4808a0a3d517b4f16abcb40c35783a77ab6d 100644 --- a/glances/plugins/glances_psutilversion.py +++ b/glances/plugins/glances_psutilversion.py @@ -17,6 +17,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +"""PsUtil plugin.""" + from glances import psutil_version_info from glances.plugins.glances_plugin import GlancesPlugin diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index eca3c7a616ebe0fabdfc5046ba075571261c4a85..2a1b5b63607f7099fff88ff58942c222f856fbca 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -37,7 +37,6 @@ else: class Plugin(GlancesPlugin): - """Glances quicklook plugin. 'stats' is a dictionary. @@ -143,7 +142,7 @@ class Plugin(GlancesPlugin): return ret def _msg_create_line(self, msg, bar, key): - """Create a new line to the Quickview""" + """Create a new line to the Quickview.""" ret = [] ret.append(self.curse_add_line(msg)) @@ -155,5 +154,5 @@ class Plugin(GlancesPlugin): return ret def _hz_to_ghz(self, hz): - """Convert Hz to Ghz""" + """Convert Hz to Ghz.""" return hz / 1000000000.0 diff --git a/glances/plugins/glances_raid.py b/glances/plugins/glances_raid.py index 910dc23e45e3eb392134f321a74f49f26f45a5d6..3579232a6e3c93bd8af9b271cf92445878b5dbee 100644 --- a/glances/plugins/glances_raid.py +++ b/glances/plugins/glances_raid.py @@ -31,7 +31,6 @@ except ImportError: class Plugin(GlancesPlugin): - """Glances RAID plugin. stats is a dict (see pymdstat documentation) diff --git a/glances/plugins/glances_sensors.py b/glances/plugins/glances_sensors.py index 4db1ada57fc53a17feb2bfa41f6b370681f6d262..37f8dbba839624110b65af3b7c13d8e1b3b7b28d 100644 --- a/glances/plugins/glances_sensors.py +++ b/glances/plugins/glances_sensors.py @@ -37,7 +37,6 @@ def to_fahrenheit(celsius): class Plugin(GlancesPlugin): - """Glances sensors plugin. The stats list includes both sensors and hard disks stats, if any. @@ -218,7 +217,6 @@ class Plugin(GlancesPlugin): class GlancesGrabSensors(object): - """Get sensors stats.""" def __init__(self): @@ -282,7 +280,8 @@ class GlancesGrabSensors(object): type: SENSOR_TEMP_UNIT or SENSOR_FAN_UNIT - output: a list""" + output: a list + """ ret = [] if type == SENSOR_TEMP_UNIT and self.init_temp: input_list = self.stemps diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py index e57818da9ed9b14659885dfc889cc5ed35c80f68..6639fc3307aa7c662e7384eccea79d0f169f32f7 100644 --- a/glances/plugins/glances_uptime.py +++ b/glances/plugins/glances_uptime.py @@ -30,7 +30,6 @@ snmp_oid = {'_uptime': '1.3.6.1.2.1.1.3.0'} class Plugin(GlancesPlugin): - """Glances uptime plugin. stats is date (string) diff --git a/glances/plugins/glances_wifi.py b/glances/plugins/glances_wifi.py index 2138af81cf0e63171240f08a5a72d6727c178aa6..8504ec26500cc68958318125208d20e25bcb82a1 100644 --- a/glances/plugins/glances_wifi.py +++ b/glances/plugins/glances_wifi.py @@ -38,8 +38,8 @@ else: class Plugin(GlancesPlugin): - """Glances Wifi plugin. + Get stats of the current Wifi hotspots. """ @@ -130,11 +130,11 @@ class Plugin(GlancesPlugin): def get_alert(self, value): """Overwrite the default get_alert method. + Alert is on signal quality where lower is better... :returns: string -- Signal alert """ - ret = 'OK' try: if value <= self.get_limit('critical', stat_name=self.plugin_name):