diff --git a/plugins/check_load.c b/plugins/check_load.c
index 3d00432f9fba1364d8433c34bb444269f0544b95..940d37ec9417cf54cc9b31c3acd6ceb93aef09ae 100644 (file)
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
-/******************************************************************************
-*
+/*****************************************************************************
+*
* Nagios check_load plugin
-*
+*
* License: GPL
-* Copyright (c) 1999-2006 nagios-plugins team
-*
-* Last Modified: $Date$
-*
+* Copyright (c) 1999-2007 Nagios Plugins Development Team
+*
* Description:
-*
+*
* This file contains the check_load plugin
-*
-* This plugin tests the current system load average.
-*
-*
-* License Information:
-*
-* This program is free software; you can redistribute it and/or modify
+*
+* This plugin tests the current system load average.
+*
+*
+* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
+* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-
-******************************************************************************/
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+*
+*****************************************************************************/
const char *progname = "check_load";
-const char *revision = "$Revision$";
-const char *copyright = "1999-2006";
+const char *copyright = "1999-2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#define la15 la[2]
char *status_line;
+int take_into_account_cpus = 0;
static void
get_threshold(char *arg, double *th)
{
size_t i, n;
+ int valid = 0;
char *str = arg, *p;
n = strlen(arg);
th[i] = strtod(str, &p);
if(p == str) break;
+ valid = 1;
str = p + 1;
if(n <= (size_t)(str - arg)) break;
}
/* empty argument or non-floatish, so warn about it and die */
- if(!i) usage (_("Warning threshold must be float or float triplet!\n"));
+ if(!i && !valid) usage (_("Warning threshold must be float or float triplet!\n"));
if(i != 2) {
/* one or more numbers were given, so fill array with last
{
int result;
int i;
+ long numcpus;
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
#ifndef HAVE_GETLOADAVG
textdomain (PACKAGE);
setlocale(LC_NUMERIC, "POSIX");
+ /* Parse extra opts if any */
+ argv = np_extra_opts (&argc, argv, progname);
+
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
# 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"));
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}
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;
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);
+ print_revision (progname, NP_VERSION);
exit (STATE_OK);
case 'h': /* help */
print_help ();
void
print_help (void)
{
- print_revision (progname, revision);
+ print_revision (progname, NP_VERSION);
printf ("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n");
printf (COPYRIGHT, copyright, email);
printf (_("This plugin tests the current system load average."));
printf ("\n\n");
-
+
print_usage ();
printf (_(UT_HELP_VRSN));
+ printf (_(UT_EXTRA_OPTS));
printf (" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15");
printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn"));
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)"));
+
+#ifdef NP_EXTRA_OPTS
+ printf ("\n");
+ printf ("%s\n", _("Notes:"));
+ printf (_(UT_EXTRA_OPTS_NOTES));
+#endif
printf (_(UT_SUPPORT));
}
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);
}