diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2022-09-19 10:23:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-19 10:23:49 +0200 |
commit | b90a5757f77cdc0434fa3f45cf59c63b9e695d90 (patch) | |
tree | c8e491f00d5d55707f07a51a3ffaccd27b41de79 /plugins | |
parent | 80872917294340a1e399b8a100c5a81c4f719220 (diff) | |
download | monitoring-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')
-rw-r--r-- | plugins/check_load.c | 56 | ||||
-rw-r--r-- | plugins/t/check_load.t | 15 |
2 files changed, 51 insertions, 20 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 @@ | |||
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | const char *progname = "check_load"; | 31 | const char *progname = "check_load"; |
32 | const char *copyright = "1999-2007"; | 32 | const char *copyright = "1999-2022"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "./common.h" | 35 | #include "./common.h" |
@@ -70,7 +70,7 @@ double cload[3] = { 0.0, 0.0, 0.0 }; | |||
70 | #define la15 la[2] | 70 | #define la15 la[2] |
71 | 71 | ||
72 | char *status_line; | 72 | char *status_line; |
73 | int take_into_account_cpus = 0; | 73 | bool take_into_account_cpus = false; |
74 | 74 | ||
75 | static void | 75 | static void |
76 | get_threshold(char *arg, double *th) | 76 | get_threshold(char *arg, double *th) |
@@ -178,13 +178,6 @@ main (int argc, char **argv) | |||
178 | # endif | 178 | # endif |
179 | #endif | 179 | #endif |
180 | 180 | ||
181 | if (take_into_account_cpus == 1) { | ||
182 | if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) { | ||
183 | la[0] = la[0] / numcpus; | ||
184 | la[1] = la[1] / numcpus; | ||
185 | la[2] = la[2] / numcpus; | ||
186 | } | ||
187 | } | ||
188 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { | 181 | if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) { |
189 | #ifdef HAVE_GETLOADAVG | 182 | #ifdef HAVE_GETLOADAVG |
190 | printf (_("Error in getloadavg()\n")); | 183 | printf (_("Error in getloadavg()\n")); |
@@ -202,18 +195,49 @@ main (int argc, char **argv) | |||
202 | result = STATE_OK; | 195 | result = STATE_OK; |
203 | 196 | ||
204 | xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); | 197 | xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15); |
198 | xasprintf(&status_line, ("total %s"), status_line); | ||
199 | |||
200 | |||
201 | double scaled_la[3] = { 0.0, 0.0, 0.0 }; | ||
202 | bool is_using_scaled_load_values = false; | ||
203 | |||
204 | if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) { | ||
205 | is_using_scaled_load_values = true; | ||
206 | |||
207 | scaled_la[0] = la[0] / numcpus; | ||
208 | scaled_la[1] = la[1] / numcpus; | ||
209 | scaled_la[2] = la[2] / numcpus; | ||
210 | |||
211 | char *tmp = NULL; | ||
212 | xasprintf(&tmp, _("load average: %.2f, %.2f, %.2f"), scaled_la[0], scaled_la[1], scaled_la[2]); | ||
213 | xasprintf(&status_line, "scaled %s - %s", tmp, status_line); | ||
214 | } | ||
205 | 215 | ||
206 | for(i = 0; i < 3; i++) { | 216 | for(i = 0; i < 3; i++) { |
207 | if(la[i] > cload[i]) { | 217 | if (is_using_scaled_load_values) { |
208 | result = STATE_CRITICAL; | 218 | if(scaled_la[i] > cload[i]) { |
209 | break; | 219 | result = STATE_CRITICAL; |
220 | break; | ||
221 | } | ||
222 | else if(scaled_la[i] > wload[i]) result = STATE_WARNING; | ||
223 | } else { | ||
224 | if(la[i] > cload[i]) { | ||
225 | result = STATE_CRITICAL; | ||
226 | break; | ||
227 | } | ||
228 | else if(la[i] > wload[i]) result = STATE_WARNING; | ||
210 | } | 229 | } |
211 | else if(la[i] > wload[i]) result = STATE_WARNING; | ||
212 | } | 230 | } |
213 | 231 | ||
214 | printf("LOAD %s - %s|", state_text(result), status_line); | 232 | printf("LOAD %s - %s|", state_text(result), status_line); |
215 | for(i = 0; i < 3; i++) | 233 | for(i = 0; i < 3; i++) { |
216 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | 234 | if (is_using_scaled_load_values) { |
235 | printf("load%d=%.3f;;;0; ", nums[i], la[i]); | ||
236 | printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]); | ||
237 | } else { | ||
238 | printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]); | ||
239 | } | ||
240 | } | ||
217 | 241 | ||
218 | putchar('\n'); | 242 | putchar('\n'); |
219 | if (n_procs_to_show > 0) { | 243 | if (n_procs_to_show > 0) { |
@@ -257,7 +281,7 @@ process_arguments (int argc, char **argv) | |||
257 | get_threshold(optarg, cload); | 281 | get_threshold(optarg, cload); |
258 | break; | 282 | break; |
259 | case 'r': /* Divide load average by number of CPUs */ | 283 | case 'r': /* Divide load average by number of CPUs */ |
260 | take_into_account_cpus = 1; | 284 | take_into_account_cpus = true; |
261 | break; | 285 | break; |
262 | case 'V': /* version */ | 286 | case 'V': /* version */ |
263 | print_revision (progname, NP_VERSION); | 287 | print_revision (progname, NP_VERSION); |
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index 60837ef6..bba8947c 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
@@ -11,10 +11,12 @@ use NPTest; | |||
11 | my $res; | 11 | my $res; |
12 | 12 | ||
13 | my $loadValue = "[0-9]+\.?[0-9]+"; | 13 | my $loadValue = "[0-9]+\.?[0-9]+"; |
14 | my $successOutput = "/^LOAD OK - load average: $loadValue, $loadValue, $loadValue/"; | 14 | my $successOutput = "/^LOAD OK - total load average: $loadValue, $loadValue, $loadValue/"; |
15 | my $failureOutput = "/^LOAD CRITICAL - load average: $loadValue, $loadValue, $loadValue/"; | 15 | my $successScaledOutput = "/^LOAD OK - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; |
16 | my $failureOutput = "/^LOAD CRITICAL - total load average: $loadValue, $loadValue, $loadValue/"; | ||
17 | my $failurScaledOutput = "/^LOAD CRITICAL - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; | ||
16 | 18 | ||
17 | plan tests => 11; | 19 | plan tests => 13; |
18 | 20 | ||
19 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); | 21 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); |
20 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | 22 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); |
@@ -26,7 +28,7 @@ like( $res->output, $failureOutput, "Output OK"); | |||
26 | 28 | ||
27 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); | 29 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); |
28 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); | 30 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); |
29 | like( $res->output, $failureOutput, "Output OK"); | 31 | like( $res->output, $failurScaledOutput, "Output OK"); |
30 | 32 | ||
31 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); | 33 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); |
32 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); | 34 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); |
@@ -34,3 +36,8 @@ like( $res->output, $successOutput, "Output OK"); | |||
34 | like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); | 36 | like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); |
35 | like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); | 37 | like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); |
36 | like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); | 38 | like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); |
39 | |||
40 | |||
41 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100 -r" ); | ||
42 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | ||
43 | like( $res->output, $successScaledOutput, "Output OK"); | ||