diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | configure.in | 8 | ||||
-rw-r--r-- | plugins/check_load.c | 19 | ||||
-rw-r--r-- | plugins/common.h | 12 | ||||
-rw-r--r-- | plugins/t/check_load.t | 6 |
5 files changed, 43 insertions, 3 deletions
@@ -5,6 +5,7 @@ This file documents the major additions and syntax changes between releases. | |||
5 | New/improved -E/--skip-stderr and -S/--skip-stdout options for check_by_ssh | 5 | New/improved -E/--skip-stderr and -S/--skip-stdout options for check_by_ssh |
6 | check_snmp now support Counter64 | 6 | check_snmp now support Counter64 |
7 | Fix compilation of check_ldap, check_radius and check_pgsql | 7 | Fix compilation of check_ldap, check_radius and check_pgsql |
8 | check_load can optionally divide by number of cpus | ||
8 | 9 | ||
9 | 1.4.8 11th April 2007 | 10 | 1.4.8 11th April 2007 |
10 | Respects --without-world-permissions for setuid plugins | 11 | Respects --without-world-permissions for setuid plugins |
diff --git a/configure.in b/configure.in index 54040ac..891922e 100644 --- a/configure.in +++ b/configure.in | |||
@@ -1054,6 +1054,14 @@ if test -n "$ac_cv_nslookup_command"; then | |||
1054 | AC_DEFINE_UNQUOTED(NSLOOKUP_COMMAND,"$ac_cv_nslookup_command", [path and args for nslookup]) | 1054 | AC_DEFINE_UNQUOTED(NSLOOKUP_COMMAND,"$ac_cv_nslookup_command", [path and args for nslookup]) |
1055 | fi | 1055 | fi |
1056 | 1056 | ||
1057 | AC_MSG_CHECKING([for number of cpus]) | ||
1058 | AC_TRY_COMPILE([#include <unistd.h>], | ||
1059 | [sysconf(_SC_NPROCESSORS_CONF) > 0;], | ||
1060 | AC_DEFINE(HAVE_SYSCONF__SC_NPROCESSORS_CONF,1,[Define if sysconf returns number of cpus]) | ||
1061 | AC_MSG_RESULT([sysconf(_SC_NPROCESSORS_CONF)]), | ||
1062 | AC_MSG_RESULT([cannot calculate]) | ||
1063 | ) | ||
1064 | |||
1057 | AC_PATH_PROG(PATH_TO_UPTIME,uptime) | 1065 | AC_PATH_PROG(PATH_TO_UPTIME,uptime) |
1058 | AC_ARG_WITH(uptime_command, | 1066 | AC_ARG_WITH(uptime_command, |
1059 | ACX_HELP_STRING([--with-uptime-command=PATH], | 1067 | ACX_HELP_STRING([--with-uptime-command=PATH], |
diff --git a/plugins/check_load.c b/plugins/check_load.c index 3d00432..9de8ff7 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c | |||
@@ -71,6 +71,7 @@ double cload[3] = { 0.0, 0.0, 0.0 }; | |||
71 | #define la15 la[2] | 71 | #define la15 la[2] |
72 | 72 | ||
73 | char *status_line; | 73 | char *status_line; |
74 | int take_into_account_cpus = 0; | ||
74 | 75 | ||
75 | static void | 76 | static void |
76 | get_threshold(char *arg, double *th) | 77 | get_threshold(char *arg, double *th) |
@@ -103,6 +104,7 @@ main (int argc, char **argv) | |||
103 | { | 104 | { |
104 | int result; | 105 | int result; |
105 | int i; | 106 | int i; |
107 | long numcpus; | ||
106 | 108 | ||
107 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ | 109 | double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */ |
108 | #ifndef HAVE_GETLOADAVG | 110 | #ifndef HAVE_GETLOADAVG |
@@ -163,6 +165,13 @@ main (int argc, char **argv) | |||
163 | # endif | 165 | # endif |
164 | #endif | 166 | #endif |
165 | 167 | ||
168 | if (take_into_account_cpus == 1) { | ||
169 | if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) { | ||
170 | la[0] = la[0] / numcpus; | ||
171 | la[1] = la[1] / numcpus; | ||
172 | la[2] = la[2] / numcpus; | ||
173 | } | ||
174 | } | ||
166 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { | 175 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { |
167 | #ifdef HAVE_GETLOADAVG | 176 | #ifdef HAVE_GETLOADAVG |
168 | printf (_("Error in getloadavg()\n")); | 177 | printf (_("Error in getloadavg()\n")); |
@@ -208,6 +217,7 @@ process_arguments (int argc, char **argv) | |||
208 | static struct option longopts[] = { | 217 | static struct option longopts[] = { |
209 | {"warning", required_argument, 0, 'w'}, | 218 | {"warning", required_argument, 0, 'w'}, |
210 | {"critical", required_argument, 0, 'c'}, | 219 | {"critical", required_argument, 0, 'c'}, |
220 | {"percpu", no_argument, 0, 'r'}, | ||
211 | {"version", no_argument, 0, 'V'}, | 221 | {"version", no_argument, 0, 'V'}, |
212 | {"help", no_argument, 0, 'h'}, | 222 | {"help", no_argument, 0, 'h'}, |
213 | {0, 0, 0, 0} | 223 | {0, 0, 0, 0} |
@@ -217,7 +227,7 @@ process_arguments (int argc, char **argv) | |||
217 | return ERROR; | 227 | return ERROR; |
218 | 228 | ||
219 | while (1) { | 229 | while (1) { |
220 | c = getopt_long (argc, argv, "Vhc:w:", longopts, &option); | 230 | c = getopt_long (argc, argv, "Vhrc:w:", longopts, &option); |
221 | 231 | ||
222 | if (c == -1 || c == EOF) | 232 | if (c == -1 || c == EOF) |
223 | break; | 233 | break; |
@@ -229,6 +239,9 @@ process_arguments (int argc, char **argv) | |||
229 | case 'c': /* critical time threshold */ | 239 | case 'c': /* critical time threshold */ |
230 | get_threshold(optarg, cload); | 240 | get_threshold(optarg, cload); |
231 | break; | 241 | break; |
242 | case 'r': /* Divide load average by number of CPUs */ | ||
243 | take_into_account_cpus = 1; | ||
244 | break; | ||
232 | case 'V': /* version */ | 245 | case 'V': /* version */ |
233 | print_revision (progname, revision); | 246 | print_revision (progname, revision); |
234 | exit (STATE_OK); | 247 | exit (STATE_OK); |
@@ -301,6 +314,8 @@ print_help (void) | |||
301 | printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); | 314 | printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15"); |
302 | printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); | 315 | printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn")); |
303 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); | 316 | printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\"")); |
317 | printf (" %s\n", "-r, --percpu"); | ||
318 | printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)")); | ||
304 | 319 | ||
305 | printf (_(UT_SUPPORT)); | 320 | printf (_(UT_SUPPORT)); |
306 | } | 321 | } |
@@ -309,5 +324,5 @@ void | |||
309 | print_usage (void) | 324 | print_usage (void) |
310 | { | 325 | { |
311 | printf (_("Usage:")); | 326 | printf (_("Usage:")); |
312 | printf ("%s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname); | 327 | printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname); |
313 | } | 328 | } |
diff --git a/plugins/common.h b/plugins/common.h index dd9a056..752e21f 100644 --- a/plugins/common.h +++ b/plugins/common.h | |||
@@ -80,6 +80,18 @@ | |||
80 | #include <unistd.h> | 80 | #include <unistd.h> |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | /* GET_NUMBER_OF_CPUS is a macro to return | ||
84 | number of CPUs, if we can get that data. | ||
85 | Use configure.in to test for various OS ways of | ||
86 | getting that data | ||
87 | Will return -1 if cannot get data | ||
88 | */ | ||
89 | #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF | ||
90 | #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF) | ||
91 | #else | ||
92 | #define GET_NUMBER_OF_CPUS() -1 | ||
93 | #endif | ||
94 | |||
83 | #ifdef TIME_WITH_SYS_TIME | 95 | #ifdef TIME_WITH_SYS_TIME |
84 | # include <sys/time.h> | 96 | # include <sys/time.h> |
85 | # include <time.h> | 97 | # include <time.h> |
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 0804ac6..da87d16 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
@@ -14,7 +14,7 @@ my $res; | |||
14 | my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; | 14 | my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; |
15 | my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; | 15 | my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; |
16 | 16 | ||
17 | plan tests => 4; | 17 | plan tests => 6; |
18 | 18 | ||
19 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); | 19 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); |
20 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | 20 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); |
@@ -24,3 +24,7 @@ $res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" ); | |||
24 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0"); | 24 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0"); |
25 | like( $res->output, $failureOutput, "Output OK"); | 25 | like( $res->output, $failureOutput, "Output OK"); |
26 | 26 | ||
27 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); | ||
28 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); | ||
29 | like( $res->output, $failureOutput, "Output OK"); | ||
30 | |||