summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-04-25 22:10:13 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-04-25 22:10:13 +0000
commitd47be7a9e48242a25e356e2509f6fb774ae0be10 (patch)
tree1ea8e0185eda27100a26f43a98523f63695f2dfa
parent27a624dd9f929af1330be508762057fa4fa8a0f5 (diff)
downloadmonitoring-plugins-d47be7a9e48242a25e356e2509f6fb774ae0be10.tar.gz
check_load can optionally divide by number of cpus
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1700 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--NEWS1
-rw-r--r--configure.in8
-rw-r--r--plugins/check_load.c19
-rw-r--r--plugins/common.h12
-rw-r--r--plugins/t/check_load.t6
5 files changed, 43 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 863d1a65..eb84e0fa 100644
--- a/NEWS
+++ b/NEWS
@@ -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
91.4.8 11th April 2007 101.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 54040ac9..891922ea 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])
1055fi 1055fi
1056 1056
1057AC_MSG_CHECKING([for number of cpus])
1058AC_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
1057AC_PATH_PROG(PATH_TO_UPTIME,uptime) 1065AC_PATH_PROG(PATH_TO_UPTIME,uptime)
1058AC_ARG_WITH(uptime_command, 1066AC_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 3d00432f..9de8ff78 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 dd9a0563..752e21ff 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 0804ac65..da87d168 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