summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Sánchez <sanchezfauste@gmail.com>2017-09-07 11:55:19 (GMT)
committerMarc Sánchez <sanchezfauste@gmail.com>2017-09-07 11:55:19 (GMT)
commit0625fbb53db9401bdce95b1a403a20980a326ec4 (patch)
tree9aa32f7a1c23e421cb01ecd9488e2beb18ff7618
parent1410ffff281bc82d423459198cb4ea3f393b1e92 (diff)
downloadmonitoring-plugins-0625fbb53db9401bdce95b1a403a20980a326ec4.tar.gz
Making show top consuming processes option less complicated
-rw-r--r--plugins/check_load.c28
1 files 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);
55void print_usage (void); 55void print_usage (void);
56static int print_top_consuming_processes(); 56static int print_top_consuming_processes();
57 57
58static int n_procs_to_show = 5; 58static int n_procs_to_show = 0;
59static int print_top_procs_on_warning = 0;
60static int print_top_procs_on_critical = 0;
61 59
62/* strictly for pretty-print usage in loops */ 60/* strictly for pretty-print usage in loops */
63static const int nums[3] = { 1, 5, 15 }; 61static const int nums[3] = { 1, 5, 15 };
@@ -216,9 +214,7 @@ main (int argc, char **argv)
216 printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); 214 printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
217 215
218 putchar('\n'); 216 putchar('\n');
219 if (result == STATE_CRITICAL && print_top_procs_on_critical) { 217 if (n_procs_to_show > 0) {
220 print_top_consuming_processes();
221 } else if (result == STATE_WARNING && print_top_procs_on_warning) {
222 print_top_consuming_processes(); 218 print_top_consuming_processes();
223 } 219 }
224 return result; 220 return result;
@@ -238,8 +234,6 @@ process_arguments (int argc, char **argv)
238 {"percpu", no_argument, 0, 'r'}, 234 {"percpu", no_argument, 0, 'r'},
239 {"version", no_argument, 0, 'V'}, 235 {"version", no_argument, 0, 'V'},
240 {"help", no_argument, 0, 'h'}, 236 {"help", no_argument, 0, 'h'},
241 {"print-top-warning", no_argument, 0, 'W'},
242 {"print-top-critical", no_argument, 0, 'C'},
243 {"procs-to-show", required_argument, 0, 'n'}, 237 {"procs-to-show", required_argument, 0, 'n'},
244 {0, 0, 0, 0} 238 {0, 0, 0, 0}
245 }; 239 };
@@ -248,7 +242,7 @@ process_arguments (int argc, char **argv)
248 return ERROR; 242 return ERROR;
249 243
250 while (1) { 244 while (1) {
251 c = getopt_long (argc, argv, "Vhrc:w:WCn:", longopts, &option); 245 c = getopt_long (argc, argv, "Vhrc:w:n:", longopts, &option);
252 246
253 if (c == -1 || c == EOF) 247 if (c == -1 || c == EOF)
254 break; 248 break;
@@ -272,12 +266,6 @@ process_arguments (int argc, char **argv)
272 case 'n': 266 case 'n':
273 n_procs_to_show = atoi(optarg); 267 n_procs_to_show = atoi(optarg);
274 break; 268 break;
275 case 'W':
276 print_top_procs_on_warning = 1;
277 break;
278 case 'C':
279 print_top_procs_on_critical = 1;
280 break;
281 case '?': /* help */ 269 case '?': /* help */
282 usage5 (); 270 usage5 ();
283 } 271 }
@@ -347,13 +335,9 @@ print_help (void)
347 printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); 335 printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
348 printf (" %s\n", "-r, --percpu"); 336 printf (" %s\n", "-r, --percpu");
349 printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); 337 printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
350 printf (" %s\n", "-W, --print-top-warning");
351 printf (" %s\n", _("Print top consuming processes on WARNING status"));
352 printf (" %s\n", "-C, --print-top-critical");
353 printf (" %s\n", _("Print top consuming processes on CRITICAL status"));
354 printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS"); 338 printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS");
355 printf (" %s\n", _("Number of processes to show when printing top consuming")); 339 printf (" %s\n", _("Number of processes to show when printing the top consuming processes."));
356 printf (" %s\n", _("processes. Not useful without -W or -C. Default value is 5")); 340 printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0"));
357 341
358 printf (UT_SUPPORT); 342 printf (UT_SUPPORT);
359} 343}
@@ -362,7 +346,7 @@ void
362print_usage (void) 346print_usage (void)
363{ 347{
364 printf ("%s\n", _("Usage:")); 348 printf ("%s\n", _("Usage:"));
365 printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-W] [-C] [-n NUMBER_OF_PROCS]\n", progname); 349 printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname);
366} 350}
367 351
368static int print_top_consuming_processes() { 352static int print_top_consuming_processes() {