summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2019-04-11 13:24:35 +0200
committernicolargo <nicolas@nicolargo.com>2019-04-11 13:24:35 +0200
commit57e07faf0253d00df7f83ebc2e02aeaaa60e2a8a (patch)
tree21a36f649903bd53fa5c13ae8411212e214209bd
parentd31805232b7f114ed33b99d399b3690eeafef599 (diff)
parentb7f684e81f3237f1b05b8265ce2562bd1bca25b0 (diff)
Merge branch 'issue344' into develop
-rw-r--r--NEWS1
-rw-r--r--docs/aoa/load.rst8
-rw-r--r--glances/plugins/glances_load.py18
3 files changed, 21 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index cafe7d21..aa6296b1 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Version 3.1.1
Enhancements and new features:
* Please add some sparklines! #1446
+ * Add Load Average (similar to Linux) on Windows #344
* Add authprovider for cassandra export (thanks to @EmilienMottet) #1395
* Curses's browser server list sorting added (thanks to @limfreee) #1396
* ElasticSearch: add date to index, unbreak object push (thanks to @genevera) # 1438
diff --git a/docs/aoa/load.rst b/docs/aoa/load.rst
index 7765ca63..30eb2e38 100644
--- a/docs/aoa/load.rst
+++ b/docs/aoa/load.rst
@@ -3,7 +3,7 @@
Load
====
-*Availability: Unix*
+*Availability: Unix and Windows with a PsUtil version >= 5.6.2*
.. image:: ../_static/load.png
@@ -14,8 +14,9 @@ on GNU/Linux operating system:
waiting in the run-queue plus the number currently executing
over 1, 5, and 15 minutes time periods."
-Be aware that Load on Linux and BSD are different things, high
-`load on BSD`_ does not means high CPU load.
+Be aware that Load on Linux, BSD and Windows are different things, high
+`load on BSD`_ does not means high CPU load. The Windows load is emulated
+by the PsUtil lib (see `load on Windows`_)
Glances gets the number of CPU core to adapt the alerts.
Alerts on load average are only set on 15 minutes time period.
@@ -38,3 +39,4 @@ Load avg Status
.. _load average: http://nosheep.net/story/defining-unix-load-average/
.. _load on BSD: http://undeadly.org/cgi?action=article&sid=20090715034920
+.. _load on Windows: https://psutil.readthedocs.io/en/latest/#psutil.getloadavg
diff --git a/glances/plugins/glances_load.py b/glances/plugins/glances_load.py
index 06922010..9fae1f44 100644
--- a/glances/plugins/glances_load.py
+++ b/glances/plugins/glances_load.py
@@ -20,6 +20,7 @@
"""Load plugin."""
import os
+import psutil
from glances.compat import iteritems
from glances.plugins.glances_core import Plugin as CorePlugin
@@ -63,6 +64,17 @@ class Plugin(GlancesPlugin):
except Exception:
self.nb_log_core = 1
+ def _getloadavg(self):
+ """Get load average. On both Linux and Windows thanks to PsUtil"""
+ try:
+ return psutil.getloadavg()
+ except AttributeError:
+ pass
+ try:
+ return os.getloadavg()
+ except OSError:
+ return None
+
@GlancesPlugin._check_decorator
@GlancesPlugin._log_result_decorator
def update(self):
@@ -74,15 +86,15 @@ class Plugin(GlancesPlugin):
# Update stats using the standard system lib
# Get the load using the os standard lib
- try:
- load = os.getloadavg()
- except (OSError, AttributeError):
+ load = self._getloadavg()
+ if load is None:
stats = self.get_init_value()
else:
stats = {'min1': load[0],
'min5': load[1],
'min15': load[2],
'cpucore': self.nb_log_core}
+
elif self.input_method == 'snmp':
# Update stats using SNMP
stats = self.get_stats_snmp(snmp_oid=snmp_oid)