summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_load.c19
-rw-r--r--plugins/common.h12
-rw-r--r--plugins/t/check_load.t6
3 files changed, 34 insertions, 3 deletions
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
73char *status_line; 73char *status_line;
74int take_into_account_cpus = 0;
74 75
75static void 76static void
76get_threshold(char *arg, double *th) 77get_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
309print_usage (void) 324print_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;
14my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; 14my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
15my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/'; 15my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
16 16
17plan tests => 4; 17plan 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" );
20cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); 20cmp_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" );
24cmp_ok( $res->return_code, 'eq', 2, "Load over 0"); 24cmp_ok( $res->return_code, 'eq', 2, "Load over 0");
25like( $res->output, $failureOutput, "Output OK"); 25like( $res->output, $failureOutput, "Output OK");
26 26
27$res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" );
28cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division");
29like( $res->output, $failureOutput, "Output OK");
30