[Nagiosplug-checkins] nagiosplug/plugins check_load.c, 1.33, 1.34 common.h, 1.28, 1.29

Ton Voon tonvoon at users.sourceforge.net
Thu Apr 26 00:10:15 CEST 2007


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs16:/tmp/cvs-serv31443/plugins

Modified Files:
	check_load.c common.h 
Log Message:
check_load can optionally divide by number of cpus


Index: check_load.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_load.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- check_load.c	28 Jan 2007 21:46:40 -0000	1.33
+++ check_load.c	25 Apr 2007 22:10:10 -0000	1.34
@@ -71,6 +71,7 @@
 #define la15 la[2]
 
 char *status_line;
+int take_into_account_cpus = 0;
 
 static void
 get_threshold(char *arg, double *th)
@@ -103,6 +104,7 @@
 {
 	int result;
 	int i;
+	long numcpus;
 
 	double la[3] = { 0.0, 0.0, 0.0 };	/* NetBSD complains about unitialized arrays */
 #ifndef HAVE_GETLOADAVG
@@ -163,6 +165,13 @@
 # endif
 #endif
 
+	if (take_into_account_cpus == 1) {
+		if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) {
+			la[0] = la[0] / numcpus;
+			la[1] = la[1] / numcpus;
+			la[2] = la[2] / numcpus;
+		}
+	}
 	if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) {
 #ifdef HAVE_GETLOADAVG
 		printf (_("Error in getloadavg()\n"));
@@ -208,6 +217,7 @@
 	static struct option longopts[] = {
 		{"warning", required_argument, 0, 'w'},
 		{"critical", required_argument, 0, 'c'},
+		{"percpu", no_argument, 0, 'r'},
 		{"version", no_argument, 0, 'V'},
 		{"help", no_argument, 0, 'h'},
 		{0, 0, 0, 0}
@@ -217,7 +227,7 @@
 		return ERROR;
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhc:w:", longopts, &option);
+		c = getopt_long (argc, argv, "Vhrc:w:", longopts, &option);
 
 		if (c == -1 || c == EOF)
 			break;
@@ -229,6 +239,9 @@
 		case 'c': /* critical time threshold */
 			get_threshold(optarg, cload);
 			break;
+		case 'r': /* Divide load average by number of CPUs */
+			take_into_account_cpus = 1;
+			break;
 		case 'V':									/* version */
 			print_revision (progname, revision);
 			exit (STATE_OK);
@@ -301,6 +314,8 @@
   printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15");
   printf ("    %s\n", _("Exit with CRITICAL status if load average exceed CLOADn"));
   printf ("    %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
+  printf (" %s\n", "-r, --percpu");
+  printf ("    %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
 
 	printf (_(UT_SUPPORT));
 }
@@ -309,5 +324,5 @@
 print_usage (void)
 {
   printf (_("Usage:"));
-	printf ("%s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
+	printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
 }

Index: common.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/common.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- common.h	22 Mar 2007 17:54:16 -0000	1.28
+++ common.h	25 Apr 2007 22:10:11 -0000	1.29
@@ -80,6 +80,18 @@
 #include <unistd.h>
 #endif
 
+/* GET_NUMBER_OF_CPUS is a macro to return 
+   number of CPUs, if we can get that data.
+   Use configure.in to test for various OS ways of
+   getting that data
+   Will return -1 if cannot get data
+*/
+#ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF 
+#define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
+#else
+#define GET_NUMBER_OF_CPUS() -1
+#endif
+
 #ifdef TIME_WITH_SYS_TIME
 # include <sys/time.h>
 # include <time.h>





More information about the Commits mailing list