diff options
| -rw-r--r-- | plugins/check_load.c | 135 |
1 files changed, 73 insertions, 62 deletions
diff --git a/plugins/check_load.c b/plugins/check_load.c index 06334450..4a38e6ce 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
| @@ -1,28 +1,20 @@ | |||
| 1 | /****************************************************************************** | 1 | /****************************************************************************** |
| 2 | * | 2 | |
| 3 | * CHECK_LOAD.C | 3 | This program is free software; you can redistribute it and/or modify |
| 4 | * | 4 | it under the terms of the GNU General Public License as published by |
| 5 | * Written by Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br> | 5 | the Free Software Foundation; either version 2 of the License, or |
| 6 | * License: GPL | 6 | (at your option) any later version. |
| 7 | * Command line: CHECK_LOAD <wload1> <cload1> <wload5> <cload5> <wload15> <cload15> | 7 | |
| 8 | * First Written: 04/17/99 | 8 | This program is distributed in the hope that it will be useful, |
| 9 | * | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * Modifications: | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * | 11 | GNU General Public License for more details. |
| 12 | * 05/18/1999 - Modified to work getloadavg where available, and use uptime | 12 | |
| 13 | * where neither proc or getloadavg are found. Also use autoconf. | 13 | You should have received a copy of the GNU General Public License |
| 14 | * mods by Karl DeBisschop (kdebiss@alum.mit.edu) | 14 | along with this program; if not, write to the Free Software |
| 15 | * 07/01/1999 - Added some #DEFINEs to allow compilation under NetBSD, as | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 16 | * suggested by Andy Doran. | 16 | |
| 17 | * mods by Ethan Galstad (nagios@nagios.org) | 17 | ******************************************************************************/ |
| 18 | * 07/17/1999 - Initialized la[] array to prevent NetBSD from complaining | ||
| 19 | * mods by Ethan Galstad (nagios@nagios.org) | ||
| 20 | * 08/18/1999 - Integrated some code with common plugin utilities | ||
| 21 | * mods by Ethan Galstad (nagios@nagios.org) | ||
| 22 | * $Date$ | ||
| 23 | * Note: The load format is the same used by "uptime" and "w" | ||
| 24 | * | ||
| 25 | *****************************************************************************/ | ||
| 26 | 18 | ||
| 27 | const char *progname = "check_load"; | 19 | const char *progname = "check_load"; |
| 28 | const char *revision = "$Revision$"; | 20 | const char *revision = "$Revision$"; |
| @@ -33,38 +25,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
| 33 | #include "utils.h" | 25 | #include "utils.h" |
| 34 | #include "popen.h" | 26 | #include "popen.h" |
| 35 | 27 | ||
| 36 | void | ||
| 37 | print_usage (void) | ||
| 38 | { | ||
| 39 | printf (_("Usage: %s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n"), | ||
| 40 | progname); | ||
| 41 | printf (_(UT_HLP_VRS), progname, progname); | ||
| 42 | } | ||
| 43 | |||
| 44 | void | ||
| 45 | print_help (void) | ||
| 46 | { | ||
| 47 | print_revision (progname, revision); | ||
| 48 | |||
| 49 | printf (_("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n")); | ||
| 50 | printf (_(COPYRIGHT), copyright, email); | ||
| 51 | |||
| 52 | printf (_("This plugin tests the current system load average.\n\n")); | ||
| 53 | |||
| 54 | print_usage (); | ||
| 55 | |||
| 56 | printf (_(UT_HELP_VRSN)); | ||
| 57 | |||
| 58 | printf (_("\ | ||
| 59 | -w, --warning=WLOAD1,WLOAD5,WLOAD15\n\ | ||
| 60 | Exit with WARNING status if load average exceeds WLOADn\n\ | ||
| 61 | -c, --critical=CLOAD1,CLOAD5,CLOAD15\n\ | ||
| 62 | Exit with CRITICAL status if load average exceed CLOADn\n\n\ | ||
| 63 | the load average format is the same used by \"uptime\" and \"w\"\n\n")); | ||
| 64 | |||
| 65 | printf (_(UT_SUPPORT)); | ||
| 66 | } | ||
| 67 | |||
| 68 | #ifdef HAVE_SYS_LOADAVG_H | 28 | #ifdef HAVE_SYS_LOADAVG_H |
| 69 | #include <sys/loadavg.h> | 29 | #include <sys/loadavg.h> |
| 70 | #endif | 30 | #endif |
| @@ -79,25 +39,34 @@ the load average format is the same used by \"uptime\" and \"w\"\n\n")); | |||
| 79 | 39 | ||
| 80 | int process_arguments (int argc, char **argv); | 40 | int process_arguments (int argc, char **argv); |
| 81 | int validate_arguments (void); | 41 | int validate_arguments (void); |
| 42 | void print_help (void); | ||
| 43 | void print_usage (void); | ||
| 82 | 44 | ||
| 83 | float wload1 = -1, wload5 = -1, wload15 = -1; | 45 | float wload1 = -1, wload5 = -1, wload15 = -1; |
| 84 | float cload1 = -1, cload5 = -1, cload15 = -1; | 46 | float cload1 = -1, cload5 = -1, cload15 = -1; |
| 85 | 47 | ||
| 86 | char *status_line = ""; | 48 | char *status_line = ""; |
| 87 | 49 | ||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | |||
| 88 | int | 55 | int |
| 89 | main (int argc, char **argv) | 56 | main (int argc, char **argv) |
| 90 | { | 57 | { |
| 91 | #if HAVE_GETLOADAVG==1 | 58 | #if HAVE_GETLOADAVG==1 |
| 92 | int result; | 59 | int result; |
| 93 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ | 60 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ |
| 94 | #elif HAVE_PROC_LOADAVG==1 | 61 | #else |
| 62 | # if HAVE_PROC_LOADAVG==1 | ||
| 95 | FILE *fp; | 63 | FILE *fp; |
| 96 | char input_buffer[MAX_INPUT_BUFFER]; | 64 | char input_buffer[MAX_INPUT_BUFFER]; |
| 97 | char *tmp_ptr; | 65 | char *tmp_ptr; |
| 98 | #else | 66 | # else |
| 99 | int result; | 67 | int result; |
| 100 | char input_buffer[MAX_INPUT_BUFFER]; | 68 | char input_buffer[MAX_INPUT_BUFFER]; |
| 69 | # endif | ||
| 101 | #endif | 70 | #endif |
| 102 | 71 | ||
| 103 | float la1, la5, la15; | 72 | float la1, la5, la15; |
| @@ -112,7 +81,8 @@ main (int argc, char **argv) | |||
| 112 | la1 = la[LOADAVG_1MIN]; | 81 | la1 = la[LOADAVG_1MIN]; |
| 113 | la5 = la[LOADAVG_5MIN]; | 82 | la5 = la[LOADAVG_5MIN]; |
| 114 | la15 = la[LOADAVG_15MIN]; | 83 | la15 = la[LOADAVG_15MIN]; |
| 115 | #elif HAVE_PROC_LOADAVG==1 | 84 | #else |
| 85 | # if HAVE_PROC_LOADAVG==1 | ||
| 116 | fp = fopen (PROC_LOADAVG, "r"); | 86 | fp = fopen (PROC_LOADAVG, "r"); |
| 117 | if (fp == NULL) { | 87 | if (fp == NULL) { |
| 118 | printf (_("Error opening %s\n"), PROC_LOADAVG); | 88 | printf (_("Error opening %s\n"), PROC_LOADAVG); |
| @@ -131,7 +101,7 @@ main (int argc, char **argv) | |||
| 131 | } | 101 | } |
| 132 | 102 | ||
| 133 | fclose (fp); | 103 | fclose (fp); |
| 134 | #else | 104 | # else |
| 135 | child_process = spopen (PATH_TO_UPTIME); | 105 | child_process = spopen (PATH_TO_UPTIME); |
| 136 | if (child_process == NULL) { | 106 | if (child_process == NULL) { |
| 137 | printf (_("Error opening %s\n"), PATH_TO_UPTIME); | 107 | printf (_("Error opening %s\n"), PATH_TO_UPTIME); |
| @@ -149,15 +119,18 @@ main (int argc, char **argv) | |||
| 149 | printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME); | 119 | printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME); |
| 150 | return STATE_UNKNOWN; | 120 | return STATE_UNKNOWN; |
| 151 | } | 121 | } |
| 122 | # endif | ||
| 152 | #endif | 123 | #endif |
| 153 | 124 | ||
| 154 | if ((la1 == -1) || (la5 == -1) || (la15 == -1)) { | 125 | if ((la1 == -1) || (la5 == -1) || (la15 == -1)) { |
| 155 | #if HAVE_GETLOADAVG==1 | 126 | #if HAVE_GETLOADAVG==1 |
| 156 | printf (_("Error in getloadavg()\n")); | 127 | printf (_("Error in getloadavg()\n")); |
| 157 | #elif HAVE_PROC_LOADAVG==1 | ||
| 158 | printf (_("Error processing %s\n"), PROC_LOADAVG); | ||
| 159 | #else | 128 | #else |
| 129 | # if HAVE_PROC_LOADAVG==1 | ||
| 130 | printf (_("Error processing %s\n"), PROC_LOADAVG); | ||
| 131 | # else | ||
| 160 | printf (_("Error processing %s\n"), PATH_TO_UPTIME); | 132 | printf (_("Error processing %s\n"), PATH_TO_UPTIME); |
| 133 | # endif | ||
| 161 | #endif | 134 | #endif |
| 162 | return STATE_UNKNOWN; | 135 | return STATE_UNKNOWN; |
| 163 | } | 136 | } |
| @@ -178,6 +151,7 @@ main (int argc, char **argv) | |||
| 178 | 151 | ||
| 179 | 152 | ||
| 180 | 153 | ||
| 154 | |||
| 181 | /* process command-line arguments */ | 155 | /* process command-line arguments */ |
| 182 | int | 156 | int |
| 183 | process_arguments (int argc, char **argv) | 157 | process_arguments (int argc, char **argv) |
| @@ -307,3 +281,40 @@ validate_arguments (void) | |||
| 307 | usage (_("Parameter inconsistency: 15-minute \"warning load\" greater than \"critical load\".\n")); | 281 | usage (_("Parameter inconsistency: 15-minute \"warning load\" greater than \"critical load\".\n")); |
| 308 | return OK; | 282 | return OK; |
| 309 | } | 283 | } |
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | void | ||
| 291 | print_help (void) | ||
| 292 | { | ||
| 293 | print_revision (progname, revision); | ||
| 294 | |||
| 295 | printf (_("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n")); | ||
| 296 | printf (_(COPYRIGHT), copyright, email); | ||
| 297 | |||
| 298 | printf (_("This plugin tests the current system load average.\n\n")); | ||
| 299 | |||
| 300 | print_usage (); | ||
| 301 | |||
| 302 | printf (_(UT_HELP_VRSN)); | ||
| 303 | |||
| 304 | printf (_("\ | ||
| 305 | -w, --warning=WLOAD1,WLOAD5,WLOAD15\n\ | ||
| 306 | Exit with WARNING status if load average exceeds WLOADn\n\ | ||
| 307 | -c, --critical=CLOAD1,CLOAD5,CLOAD15\n\ | ||
| 308 | Exit with CRITICAL status if load average exceed CLOADn\n\n\ | ||
| 309 | the load average format is the same used by \"uptime\" and \"w\"\n\n")); | ||
| 310 | |||
| 311 | printf (_(UT_SUPPORT)); | ||
| 312 | } | ||
| 313 | |||
| 314 | void | ||
| 315 | print_usage (void) | ||
| 316 | { | ||
| 317 | printf (_("Usage: %s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n"), | ||
| 318 | progname); | ||
| 319 | printf (_(UT_HLP_VRS), progname, progname); | ||
| 320 | } | ||
