From 259dcd6d0e3be8b56d391020f61c15e97d144f4b Mon Sep 17 00:00:00 2001 From: nicolargo Date: Wed, 17 Jan 2018 08:31:43 +0100 Subject: Nice Process Priority Configuration #1218 --- NEWS | 15 +++++++++++++++ conf/glances.conf | 11 +++++++++++ docs/aoa/ps.rst | 6 ++++-- docs/man/glances.1 | 4 ++-- glances/plugins/glances_processlist.py | 27 ++++++++++++++++++++++----- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 9d9fc8df..78c88917 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ Enhancements and new features: * Add a code of conduct for Glances project's participants #1211 * Context switches bottleneck identification #1212 * Take advantage of the PSUtil issue #1025 (Add process_iter(attrs, ad_value)) #1105 + * Nice Process Priority Configuration #1218 Bugs corrected: @@ -56,6 +57,20 @@ News command line options: News configuration keys in the glances.conf file: +Processes list Nice value: + + [processlist] + # Nice priorities range from -20 to 19. + # Configure nice levels using a comma separated list. + # + # Nice: Example 1, non-zero is warning (default behavior) + nice_warning=-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 + # + # Nice: Example 2, low priority processes escalate from careful to critical + #nice_careful=1,2,3,4,5,6,7,8,9 + #nice_warning=10,11,12,13,14 + #nice_critical=15,16,17,18,19 + Docker plugin (related to #1152) [docker] diff --git a/conf/glances.conf b/conf/glances.conf index fc06547f..b2be5401 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -210,6 +210,17 @@ cpu_critical=90 mem_careful=50 mem_warning=70 mem_critical=90 +# +# Nice priorities range from -20 to 19. +# Configure nice levels using a comma separated list. +# +# Nice: Example 1, non-zero is warning (default behavior) +nice_warning=-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 +# +# Nice: Example 2, low priority processes escalate from careful to critical +#nice_careful=1,2,3,4,5,6,7,8,9 +#nice_warning=10,11,12,13,14 +#nice_critical=15,16,17,18,19 [ports] # Ports scanner plugin configuration diff --git a/docs/aoa/ps.rst b/docs/aoa/ps.rst index bf4c1945..c8a4ac0b 100644 --- a/docs/aoa/ps.rst +++ b/docs/aoa/ps.rst @@ -122,5 +122,7 @@ The extended stats feature can be enabled using the (curses interface). .. note:: - Limit values can be overwritten in the configuration file under - the ``[process]`` section. + Limit for CPU and MEM percent values can be overwritten in the + configuration file under the ``[processlist]`` section. It is also + possible to define limit for Nice values (comma separated list). + For example: nice_warning=-20,-19,-18 diff --git a/docs/man/glances.1 b/docs/man/glances.1 index f2bec9c7..7b052c20 100644 --- a/docs/man/glances.1 +++ b/docs/man/glances.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "GLANCES" "1" "Dec 29, 2017" "3.0_DEV" "Glances" +.TH "GLANCES" "1" "Jan 17, 2018" "3.0_DEV" "Glances" .SH NAME glances \- An eye on your system . @@ -847,6 +847,6 @@ $ glances \-\-browser .sp Nicolas Hennion aka Nicolargo <\fI\%contact@nicolargo.com\fP> .SH COPYRIGHT -2017, Nicolas Hennion +2018, Nicolas Hennion .\" Generated by docutils manpage writer. . diff --git a/glances/plugins/glances_processlist.py b/glances/plugins/glances_processlist.py index e27ab6dd..95d17c27 100644 --- a/glances/plugins/glances_processlist.py +++ b/glances/plugins/glances_processlist.py @@ -202,6 +202,26 @@ class Plugin(GlancesPlugin): return child_data + def get_nice_alert(self, value): + """Return the alert relative to the Nice configuration list""" + value = str(value) + try: + if value in self.get_limit('nice_critical'): + return 'CRITICAL' + except KeyError: + pass + try: + if value in self.get_limit('nice_warning'): + return 'WARNING' + except KeyError: + pass + try: + if value in self.get_limit('nice_careful'): + return 'CAREFUL' + except KeyError: + pass + return 'DEFAULT' + def get_process_curses_data(self, p, first, args): """Get curses data to display for a process. @@ -264,11 +284,8 @@ class Plugin(GlancesPlugin): if nice is None: nice = '?' msg = '{:>5}'.format(nice) - if isinstance(nice, int) and ((WINDOWS and nice != 32) or - (not WINDOWS and nice != 0)): - ret.append(self.curse_add_line(msg, decoration='NICE')) - else: - ret.append(self.curse_add_line(msg)) + ret.append(self.curse_add_line(msg, + decoration=self.get_nice_alert(nice))) else: msg = '{:>5}'.format('?') ret.append(self.curse_add_line(msg)) -- cgit v1.2.3