summaryrefslogtreecommitdiffstats
path: root/plugins/check_load.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-04-25 22:10:13 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2007-04-25 22:10:13 (GMT)
commitd47be7a9e48242a25e356e2509f6fb774ae0be10 (patch)
tree1ea8e0185eda27100a26f43a98523f63695f2dfa /plugins/check_load.c
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
Diffstat (limited to 'plugins/check_load.c')
-rw-r--r--plugins/check_load.c19
1 files changed, 17 insertions, 2 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}