diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-13 17:45:13 +0100 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-20 10:02:47 +0100 |
commit | 2289d094ae00a52f96a038cb7ca8bb350aec483a (patch) | |
tree | a0a5f170bb26fa1df61548ee2a33d6c41011b2ae /plugins/check_swap.c | |
parent | 6011cdf5547a815e30a2c4d69e53cabac9fcd10d (diff) | |
download | monitoring-plugins-2289d094ae00a52f96a038cb7ca8bb350aec483a.tar.gz |
check_swap: Hopefully fix stuff on BSD
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 921aaac5..ac74931a 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -567,7 +567,7 @@ swap_result getSwapFromSwapCommand() { | |||
567 | #endif // HAVE_SWAP | 567 | #endif // HAVE_SWAP |
568 | 568 | ||
569 | #ifdef CHECK_SWAP_SWAPCTL_BSD | 569 | #ifdef CHECK_SWAP_SWAPCTL_BSD |
570 | swap_result getSwapFromSwapctl_BSD() { | 570 | swap_result getSwapFromSwapctl_BSD(swap_config config) { |
571 | int i = 0, nswaps = 0, swapctl_res = 0; | 571 | int i = 0, nswaps = 0, swapctl_res = 0; |
572 | struct swapent *ent; | 572 | struct swapent *ent; |
573 | int conv_factor = SWAP_CONVERSION; | 573 | int conv_factor = SWAP_CONVERSION; |
@@ -585,17 +585,20 @@ swap_result getSwapFromSwapctl_BSD() { | |||
585 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); | 585 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); |
586 | } | 586 | } |
587 | 587 | ||
588 | |||
589 | double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0; | ||
590 | unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0; | ||
591 | |||
588 | for (i = 0; i < nswaps; i++) { | 592 | for (i = 0; i < nswaps; i++) { |
589 | dsktotal_mb = (float)ent[i].se_nblks / conv_factor; | 593 | dsktotal_mb = (float)ent[i].se_nblks / conv_factor; |
590 | dskused_mb = (float)ent[i].se_inuse / conv_factor; | 594 | dskused_mb = (float)ent[i].se_inuse / conv_factor; |
591 | dskfree_mb = (dsktotal_mb - dskused_mb); | 595 | dskfree_mb = (dsktotal_mb - dskused_mb); |
592 | 596 | ||
593 | if (allswaps && dsktotal_mb > 0) { | 597 | if (config.allswaps && dsktotal_mb > 0) { |
594 | percent = 100 * (((double)dskused_mb) / ((double)dsktotal_mb)); | 598 | double percent = 100 * (((double)dskused_mb) / ((double)dsktotal_mb)); |
595 | result = max_state(result, check_swap(dskfree_mb, dsktotal_mb)); | 599 | |
596 | if (verbose) { | 600 | if (config.verbose) { |
597 | xasprintf(&status, "%s [%.0f (%d%%)]", status, dskfree_mb, | 601 | printf("[%.0f (%g%%)]", dskfree_mb, 100 - percent); |
598 | 100 - percent); | ||
599 | } | 602 | } |
600 | } | 603 | } |
601 | 604 | ||
@@ -606,6 +609,17 @@ swap_result getSwapFromSwapctl_BSD() { | |||
606 | 609 | ||
607 | /* and clean up after ourselves */ | 610 | /* and clean up after ourselves */ |
608 | free(ent); | 611 | free(ent); |
612 | |||
613 | swap_result result = {0}; | ||
614 | |||
615 | result.statusCode = OK; | ||
616 | result.errorcode = OK; | ||
617 | |||
618 | result.metrics.total = total_swap_mb * 1024 * 1024; | ||
619 | result.metrics.free = free_swap_mb * 1024 * 1024; | ||
620 | result.metrics.used = used_swap_mb * 1024 * 1024; | ||
621 | |||
622 | return result; | ||
609 | } | 623 | } |
610 | #endif // CHECK_SWAP_SWAPCTL_BSD | 624 | #endif // CHECK_SWAP_SWAPCTL_BSD |
611 | 625 | ||