[monitoring-plugins] Making show top consuming processes option less ...

Marc Sánchez git at monitoring-plugins.org
Thu Apr 4 13:10:16 CEST 2019


 Module: monitoring-plugins
 Branch: feature_check_curl
 Commit: 0625fbb53db9401bdce95b1a403a20980a326ec4
 Author: Marc Sánchez <sanchezfauste at gmail.com>
   Date: Thu Sep  7 13:55:19 2017 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=0625fbb

Making show top consuming processes option less complicated

---

 plugins/check_load.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/plugins/check_load.c b/plugins/check_load.c
index b6cfc65..5d5c115 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -55,9 +55,7 @@ void print_help (void);
 void print_usage (void);
 static int print_top_consuming_processes();
 
-static int n_procs_to_show = 5;
-static int print_top_procs_on_warning = 0;
-static int print_top_procs_on_critical = 0;
+static int n_procs_to_show = 0;
 
 /* strictly for pretty-print usage in loops */
 static const int nums[3] = { 1, 5, 15 };
@@ -216,9 +214,7 @@ main (int argc, char **argv)
 		printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
 
 	putchar('\n');
-	if (result == STATE_CRITICAL && print_top_procs_on_critical) {
-		print_top_consuming_processes();
-	} else if (result == STATE_WARNING && print_top_procs_on_warning) {
+	if (n_procs_to_show > 0) {
 		print_top_consuming_processes();
 	}
 	return result;
@@ -238,8 +234,6 @@ process_arguments (int argc, char **argv)
 		{"percpu", no_argument, 0, 'r'},
 		{"version", no_argument, 0, 'V'},
 		{"help", no_argument, 0, 'h'},
-		{"print-top-warning", no_argument, 0, 'W'},
-		{"print-top-critical", no_argument, 0, 'C'},
 		{"procs-to-show", required_argument, 0, 'n'},
 		{0, 0, 0, 0}
 	};
@@ -248,7 +242,7 @@ process_arguments (int argc, char **argv)
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhrc:w:WCn:", longopts, &option);
+		c = getopt_long (argc, argv, "Vhrc:w:n:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -272,12 +266,6 @@ process_arguments (int argc, char **argv)
 		case 'n':
 			n_procs_to_show = atoi(optarg);
 			break;
-		case 'W':
-			print_top_procs_on_warning = 1;
-			break;
-		case 'C':
-			print_top_procs_on_critical = 1;
-			break;
 		case '?':									/* help */
 			usage5 ();
 		}
@@ -347,13 +335,9 @@ print_help (void)
   printf ("    %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
   printf (" %s\n", "-r, --percpu");
   printf ("    %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
-  printf (" %s\n", "-W, --print-top-warning");
-  printf ("    %s\n", _("Print top consuming processes on WARNING status"));
-  printf (" %s\n", "-C, --print-top-critical");
-  printf ("    %s\n", _("Print top consuming processes on CRITICAL status"));
   printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS");
-  printf ("    %s\n", _("Number of processes to show when printing top consuming"));
-  printf ("    %s\n", _("processes. Not useful without -W or -C. Default value is 5"));
+  printf ("    %s\n", _("Number of processes to show when printing the top consuming processes."));
+  printf ("    %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0"));
 
 	printf (UT_SUPPORT);
 }
@@ -362,7 +346,7 @@ void
 print_usage (void)
 {
   printf ("%s\n", _("Usage:"));
-  printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-W] [-C] [-n NUMBER_OF_PROCS]\n", progname);
+  printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname);
 }
 
 static int print_top_consuming_processes() {



More information about the Commits mailing list