Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
check_load.c File Reference
#include "common.h"
#include "utils.h"
#include "popen.h"

Go to the source code of this file.

Defines

#define LOADAVG_1MIN   0
#define LOADAVG_5MIN   1
#define LOADAVG_15MIN   2
#define la1   la[0]
#define la5   la[1]
#define la15   la[2]

Functions

static int process_arguments (int argc, char **argv)
static int validate_arguments (void)
void print_help (void)
void print_usage (void)
static void get_threshold (char *arg, double *th)
int main (int argc, char **argv)

Variables

const char * progname = "check_load"
const char * copyright = "1999-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
static const int nums [3] = { 1, 5, 15 }
double wload [3] = { 0.0, 0.0, 0.0 }
double cload [3] = { 0.0, 0.0, 0.0 }
char * status_line
int take_into_account_cpus = 0

Define Documentation

#define la1   la[0]

Definition at line 62 of file check_load.c.

#define la15   la[2]

Definition at line 64 of file check_load.c.

#define la5   la[1]

Definition at line 63 of file check_load.c.

#define LOADAVG_15MIN   2

Definition at line 47 of file check_load.c.

#define LOADAVG_1MIN   0

Definition at line 45 of file check_load.c.

#define LOADAVG_5MIN   1

Definition at line 46 of file check_load.c.


Function Documentation

static void get_threshold ( char *  arg,
double *  th 
) [static]

Definition at line 70 of file check_load.c.

{
       size_t i, n;
       int valid = 0;
       char *str = arg, *p;

       n = strlen(arg);
       for(i = 0; i < 3; i++) {
              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 && !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
               * we got (most likely to NOT produce the least expected result) */
              for(n = i; n < 3; n++) th[n] = th[i];
       }
}

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 98 of file check_load.c.

{
       int result;
       int i;
       long numcpus;

       double la[3] = { 0.0, 0.0, 0.0 };  /* NetBSD complains about unitialized arrays */
#ifndef HAVE_GETLOADAVG
       char input_buffer[MAX_INPUT_BUFFER];
# ifdef HAVE_PROC_LOADAVG
       FILE *fp;
       char *str, *next;
# endif
#endif

       setlocale (LC_ALL, "");
       bindtextdomain (PACKAGE, LOCALEDIR);
       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"));

#ifdef HAVE_GETLOADAVG
       result = getloadavg (la, 3);
       if (result != 3)
              return STATE_UNKNOWN;
#else
# ifdef HAVE_PROC_LOADAVG
       fp = fopen (PROC_LOADAVG, "r");
       if (fp == NULL) {
              printf (_("Error opening %s\n"), PROC_LOADAVG);
              return STATE_UNKNOWN;
       }

       while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
              str = (char *)input_buffer;
              for(i = 0; i < 3; i++) {
                     la[i] = strtod(str, &next);
                     str = next;
              }
       }

       fclose (fp);
# else
       child_process = spopen (PATH_TO_UPTIME);
       if (child_process == NULL) {
              printf (_("Error opening %s\n"), PATH_TO_UPTIME);
              return STATE_UNKNOWN;
       }
       child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
       if (child_stderr == NULL) {
              printf (_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
       }
       fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
       sscanf (input_buffer, "%*[^l]load average: %lf, %lf, %lf", &la1, &la5, &la15);

       result = spclose (child_process);
       if (result) {
              printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
              return STATE_UNKNOWN;
       }
# 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"));
#else
# ifdef HAVE_PROC_LOADAVG
              printf (_("Error processing %s\n"), PROC_LOADAVG);
# else
              printf (_("Error processing %s\n"), PATH_TO_UPTIME);
# endif
#endif
              return STATE_UNKNOWN;
       }

       /* we got this far, so assume OK until we've measured */
       result = STATE_OK;

       asprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);

       for(i = 0; i < 3; i++) {
              if(la[i] > cload[i]) {
                     result = STATE_CRITICAL;
                     break;
              }
              else if(la[i] > wload[i]) result = STATE_WARNING;
       }

       printf("%s - %s|", state_text(result), status_line);
       for(i = 0; i < 3; i++)
              printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);

       putchar('\n');
       return result;
}

Here is the call graph for this function:

void print_help ( void  )
void print_usage ( void  )

Definition at line 389 of file check_cpqarray.c.

{
  printf("cpqarrayd [options]\n");
  printf("   -h         prints this text\n");
  printf("   -d         enables debugging\n");
}
static int process_arguments ( int  argc,
char **  argv 
) [static]
static int validate_arguments ( void  ) [static]

Variable Documentation

double cload[3] = { 0.0, 0.0, 0.0 }

Definition at line 61 of file check_load.c.

const char* copyright = "1999-2007"

Definition at line 32 of file check_load.c.

const char* email = "nagiosplug-devel@lists.sourceforge.net"

Definition at line 33 of file check_load.c.

const int nums[3] = { 1, 5, 15 } [static]

Definition at line 57 of file check_load.c.

const char* progname = "check_load"

Definition at line 31 of file check_load.c.

char* status_line

Definition at line 66 of file check_load.c.

Definition at line 67 of file check_load.c.

double wload[3] = { 0.0, 0.0, 0.0 }

Definition at line 60 of file check_load.c.