diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-13 17:40:18 +0100 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-12-20 10:02:47 +0100 |
commit | 6011cdf5547a815e30a2c4d69e53cabac9fcd10d (patch) | |
tree | cc24369b4478e9445e4f32466a6f0f0ea1ca672c /plugins | |
parent | 8cdcb1a8ad5d7ba13ca19493f333605dcca33287 (diff) | |
download | monitoring-plugins-6011cdf5547a815e30a2c4d69e53cabac9fcd10d.tar.gz |
check_swap: hopefully fix SRV4 stuff
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_swap.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 4bad2100..921aaac5 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -610,10 +610,12 @@ swap_result getSwapFromSwapctl_BSD() { | |||
610 | #endif // CHECK_SWAP_SWAPCTL_BSD | 610 | #endif // CHECK_SWAP_SWAPCTL_BSD |
611 | 611 | ||
612 | #ifdef CHECK_SWAP_SWAPCTL_SVR4 | 612 | #ifdef CHECK_SWAP_SWAPCTL_SVR4 |
613 | swap_result getSwapFromSwap_SRV4() { | 613 | swap_result getSwapFromSwap_SRV4(swap_config config) { |
614 | int i = 0, nswaps = 0, swapctl_res = 0; | 614 | int i = 0, nswaps = 0, swapctl_res = 0; |
615 | swaptbl_t *tbl = NULL; | 615 | //swaptbl_t *tbl = NULL; |
616 | swapent_t *ent = NULL; | 616 | void*tbl = NULL; |
617 | //swapent_t *ent = NULL; | ||
618 | void*ent = NULL; | ||
617 | /* get the number of active swap devices */ | 619 | /* get the number of active swap devices */ |
618 | if ((nswaps = swapctl(SC_GETNSWP, NULL)) == -1) | 620 | if ((nswaps = swapctl(SC_GETNSWP, NULL)) == -1) |
619 | die(STATE_UNKNOWN, _("Error getting swap devices\n")); | 621 | die(STATE_UNKNOWN, _("Error getting swap devices\n")); |
@@ -621,7 +623,7 @@ swap_result getSwapFromSwap_SRV4() { | |||
621 | if (nswaps == 0) | 623 | if (nswaps == 0) |
622 | die(STATE_OK, _("SWAP OK: No swap devices defined\n")); | 624 | die(STATE_OK, _("SWAP OK: No swap devices defined\n")); |
623 | 625 | ||
624 | if (verbose >= 3) | 626 | if (config.verbose >= 3) |
625 | printf("Found %d swap device(s)\n", nswaps); | 627 | printf("Found %d swap device(s)\n", nswaps); |
626 | 628 | ||
627 | /* initialize swap table + entries */ | 629 | /* initialize swap table + entries */ |
@@ -645,21 +647,23 @@ swap_result getSwapFromSwap_SRV4() { | |||
645 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); | 647 | die(STATE_UNKNOWN, _("Error in swapctl call\n")); |
646 | } | 648 | } |
647 | 649 | ||
650 | double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0; | ||
651 | unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0; | ||
652 | |||
648 | for (i = 0; i < nswaps; i++) { | 653 | for (i = 0; i < nswaps; i++) { |
649 | dsktotal_mb = (float)tbl->swt_ent[i].ste_pages / SWAP_CONVERSION; | 654 | dsktotal_mb = (float)tbl->swt_ent[i].ste_pages / SWAP_CONVERSION; |
650 | dskfree_mb = (float)tbl->swt_ent[i].ste_free / SWAP_CONVERSION; | 655 | dskfree_mb = (float)tbl->swt_ent[i].ste_free / SWAP_CONVERSION; |
651 | dskused_mb = (dsktotal_mb - dskfree_mb); | 656 | dskused_mb = (dsktotal_mb - dskfree_mb); |
652 | 657 | ||
653 | if (verbose >= 3) | 658 | if (config.verbose >= 3) |
654 | printf("dsktotal_mb=%.0f dskfree_mb=%.0f dskused_mb=%.0f\n", | 659 | printf("dsktotal_mb=%.0f dskfree_mb=%.0f dskused_mb=%.0f\n", |
655 | dsktotal_mb, dskfree_mb, dskused_mb); | 660 | dsktotal_mb, dskfree_mb, dskused_mb); |
656 | 661 | ||
657 | if (allswaps && dsktotal_mb > 0) { | 662 | if (config.allswaps && dsktotal_mb > 0) { |
658 | percent = 100 * (((double)dskused_mb) / ((double)dsktotal_mb)); | 663 | double percent = 100 * (((double)dskused_mb) / ((double)dsktotal_mb)); |
659 | result = max_state(result, check_swap(dskfree_mb, dsktotal_mb)); | 664 | |
660 | if (verbose) { | 665 | if (config.verbose) { |
661 | xasprintf(&status, "%s [%.0f (%d%%)]", status, dskfree_mb, | 666 | printf("[%.0f (%g%%)]", dskfree_mb, 100 - percent); |
662 | 100 - percent); | ||
663 | } | 667 | } |
664 | } | 668 | } |
665 | 669 | ||
@@ -673,5 +677,13 @@ swap_result getSwapFromSwap_SRV4() { | |||
673 | free(tbl->swt_ent[i].ste_path); | 677 | free(tbl->swt_ent[i].ste_path); |
674 | } | 678 | } |
675 | free(tbl); | 679 | free(tbl); |
680 | |||
681 | swap_result result = {0}; | ||
682 | result.errorcode = OK; | ||
683 | result.metrics.total = total_swap_mb * 1024 * 1024; | ||
684 | result.metrics.free = free_swap_mb * 1024 * 1024; | ||
685 | result.metrics.used = used_swap_mb * 1024 * 1024; | ||
686 | |||
687 | return result; | ||
676 | } | 688 | } |
677 | #endif // CHECK_SWAP_SWAPCTL_SVR4 | 689 | #endif // CHECK_SWAP_SWAPCTL_SVR4 |