aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_load.c
diff options
context:
space:
mode:
authorGravatar Lorenz <12514511+RincewindsHat@users.noreply.github.com> 2022-09-19 10:23:49 +0200
committerGravatar GitHub <noreply@github.com> 2022-09-19 10:23:49 +0200
commitb90a5757f77cdc0434fa3f45cf59c63b9e695d90 (patch)
treec8e491f00d5d55707f07a51a3ffaccd27b41de79 /plugins/check_load.c
parent80872917294340a1e399b8a100c5a81c4f719220 (diff)
downloadmonitoring-plugins-b90a5757f77cdc0434fa3f45cf59c63b9e695d90.tar.gz
Display total and scaled load values if check_load scales the values by number of CPUs (#1778)
* Renew copyright * Display more verbose output, if scaled load values are used * Actually use scaled value for determining status and print the fitting perfdata depending on input parameters * Add test cases for scaled mode
Diffstat (limited to 'plugins/check_load.c')
-rw-r--r--plugins/check_load.c56
1 files changed, 40 insertions, 16 deletions
diff --git a/plugins/check_load.c b/plugins/check_load.c
index d1bb30a4..00f7c877 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -29,7 +29,7 @@
*****************************************************************************/
const char *progname = "check_load";
-const char *copyright = "1999-2007";
+const char *copyright = "1999-2022";
const char *email = "devel@monitoring-plugins.org";
#include "./common.h"
@@ -70,7 +70,7 @@ double cload[3] = { 0.0, 0.0, 0.0 };
#define la15 la[2]
char *status_line;
-int take_into_account_cpus = 0;
+bool take_into_account_cpus = false;
static void
get_threshold(char *arg, double *th)
@@ -178,13 +178,6 @@ main (int argc, char **argv)
# 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"));
@@ -202,18 +195,49 @@ main (int argc, char **argv)
result = STATE_OK;
xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
+ xasprintf(&status_line, ("total %s"), status_line);
+
+
+ double scaled_la[3] = { 0.0, 0.0, 0.0 };
+ bool is_using_scaled_load_values = false;
+
+ if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) {
+ is_using_scaled_load_values = true;
+
+ scaled_la[0] = la[0] / numcpus;
+ scaled_la[1] = la[1] / numcpus;
+ scaled_la[2] = la[2] / numcpus;
+
+ char *tmp = NULL;
+ xasprintf(&tmp, _("load average: %.2f, %.2f, %.2f"), scaled_la[0], scaled_la[1], scaled_la[2]);
+ xasprintf(&status_line, "scaled %s - %s", tmp, status_line);
+ }
for(i = 0; i < 3; i++) {
- if(la[i] > cload[i]) {
- result = STATE_CRITICAL;
- break;
+ if (is_using_scaled_load_values) {
+ if(scaled_la[i] > cload[i]) {
+ result = STATE_CRITICAL;
+ break;
+ }
+ else if(scaled_la[i] > wload[i]) result = STATE_WARNING;
+ } else {
+ if(la[i] > cload[i]) {
+ result = STATE_CRITICAL;
+ break;
+ }
+ else if(la[i] > wload[i]) result = STATE_WARNING;
}
- else if(la[i] > wload[i]) result = STATE_WARNING;
}
printf("LOAD %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]);
+ for(i = 0; i < 3; i++) {
+ if (is_using_scaled_load_values) {
+ printf("load%d=%.3f;;;0; ", nums[i], la[i]);
+ printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]);
+ } else {
+ printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
+ }
+ }
putchar('\n');
if (n_procs_to_show > 0) {
@@ -257,7 +281,7 @@ process_arguments (int argc, char **argv)
get_threshold(optarg, cload);
break;
case 'r': /* Divide load average by number of CPUs */
- take_into_account_cpus = 1;
+ take_into_account_cpus = true;
break;
case 'V': /* version */
print_revision (progname, NP_VERSION);