summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-04-04 11:09:15 (GMT)
committerAndreas Baumann <mail@andreasbaumann.cc>2019-04-04 11:09:15 (GMT)
commit2f4d6764d78cf085601b34ac92486405bd11095d (patch)
tree550601dc79e74fd4c184dc96a95687d1d1238b43 /plugins/check_swap.c
parentfaea5899ba3264581bf75649e4b399d0b69bd125 (diff)
parent5f16ba81c4af1a05e67806ca989a1dd46248a5fd (diff)
downloadmonitoring-plugins-2f4d6764d78cf085601b34ac92486405bd11095d.tar.gz
Merge branch 'master' into feature_check_curl
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 4d5a407..0ff0c77 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -51,7 +51,7 @@ const char *email = "devel@monitoring-plugins.org";
51# define SWAP_CONVERSION 1 51# define SWAP_CONVERSION 1
52#endif 52#endif
53 53
54int check_swap (int usp, float free_swap_mb); 54int check_swap (int usp, float free_swap_mb, float total_swap_mb);
55int process_arguments (int argc, char **argv); 55int process_arguments (int argc, char **argv);
56int validate_arguments (void); 56int validate_arguments (void);
57void print_usage (void); 57void print_usage (void);
@@ -128,7 +128,7 @@ main (int argc, char **argv)
128 percent=100.0; 128 percent=100.0;
129 else 129 else
130 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 130 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
131 result = max_state (result, check_swap (percent, dskfree_mb)); 131 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
132 if (verbose) 132 if (verbose)
133 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 133 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
134 } 134 }
@@ -227,7 +227,7 @@ main (int argc, char **argv)
227 free_swap_mb += dskfree_mb; 227 free_swap_mb += dskfree_mb;
228 if (allswaps) { 228 if (allswaps) {
229 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 229 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
230 result = max_state (result, check_swap (percent, dskfree_mb)); 230 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
231 if (verbose) 231 if (verbose)
232 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 232 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
233 } 233 }
@@ -289,7 +289,7 @@ main (int argc, char **argv)
289 289
290 if(allswaps && dsktotal_mb > 0){ 290 if(allswaps && dsktotal_mb > 0){
291 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 291 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
292 result = max_state (result, check_swap (percent, dskfree_mb)); 292 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
293 if (verbose) { 293 if (verbose) {
294 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 294 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
295 } 295 }
@@ -328,7 +328,7 @@ main (int argc, char **argv)
328 328
329 if(allswaps && dsktotal_mb > 0){ 329 if(allswaps && dsktotal_mb > 0){
330 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 330 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
331 result = max_state (result, check_swap (percent, dskfree_mb)); 331 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
332 if (verbose) { 332 if (verbose) {
333 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 333 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
334 } 334 }
@@ -355,7 +355,7 @@ main (int argc, char **argv)
355 status = "- Swap is either disabled, not present, or of zero size. "; 355 status = "- Swap is either disabled, not present, or of zero size. ";
356 } 356 }
357 357
358 result = max_state (result, check_swap (percent_used, free_swap_mb)); 358 result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb));
359 printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), 359 printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"),
360 state_text (result), 360 state_text (result),
361 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); 361 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status);
@@ -372,10 +372,10 @@ main (int argc, char **argv)
372 372
373 373
374int 374int
375check_swap (int usp, float free_swap_mb) 375check_swap (int usp, float free_swap_mb, float total_swap_mb)
376{ 376{
377 377
378 if (!free_swap_mb) return no_swap_state; 378 if (!total_swap_mb) return no_swap_state;
379 379
380 int result = STATE_UNKNOWN; 380 int result = STATE_UNKNOWN;
381 float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ 381 float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */