diff options
Diffstat (limited to 'plugins/check_load.c')
| -rw-r--r-- | plugins/check_load.c | 56 |
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 @@ | |||
| 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); |
