From 9390d7e453d67b43df92936aac28080431423ba0 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Thu, 4 Oct 2018 10:55:21 +0200 Subject: [PATCH 1/2] Add 'used' feature to check_swap This implements the _used_ feature to check_swap to print the used swap instead of the default available swap. --- plugins/check_swap.cpp | 53 ++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/plugins/check_swap.cpp b/plugins/check_swap.cpp index 51f8bde22..4c3a1deb0 100644 --- a/plugins/check_swap.cpp +++ b/plugins/check_swap.cpp @@ -36,6 +36,7 @@ struct printInfoStruct double aSwap; double percentFree; Bunit unit = BunitMB; + bool showUsed; }; struct pageFileInfo @@ -73,6 +74,7 @@ static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoSt ("warning,w", po::wvalue(), "Warning threshold") ("critical,c", po::wvalue(), "Critical threshold") ("unit,u", po::wvalue(), "The unit to use for display (default MB)") + ("show-used,U", "Show used swap instead of the free swap") ; po::wcommand_line_parser parser(ac, av); @@ -167,6 +169,12 @@ static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoSt } } + if (vm.count("show-used")) { + printInfo.showUsed = true; + printInfo.warn.legal = true; + printInfo.crit.legal = true; + } + return -1; } @@ -177,30 +185,35 @@ static int printOutput(printInfoStruct& printInfo) state state = OK; - if (printInfo.warn.rend(printInfo.aSwap, printInfo.tSwap)) + std::wcout << L"SWAP "; + + double currentValue; + + if (!printInfo.showUsed) + currentValue = printInfo.aSwap; + else + currentValue = printInfo.tSwap - printInfo.aSwap; + + if (printInfo.warn.rend(currentValue, printInfo.tSwap)) { state = WARNING; - - if (printInfo.crit.rend(printInfo.aSwap, printInfo.tSwap)) + std::wcout << L"WARNING - "; + } else if (printInfo.crit.rend(currentValue, printInfo.tSwap)) { state = CRITICAL; - - switch (state) { - case OK: - std::wcout << L"SWAP OK - " << printInfo.percentFree << L"% free | 'swap'=" << printInfo.aSwap << BunitStr(printInfo.unit) << L";" - << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap) - << L";0;" << printInfo.tSwap << '\n'; - break; - case WARNING: - std::wcout << L"SWAP WARNING - " << printInfo.percentFree << L"% free | 'swap'=" << printInfo.aSwap << BunitStr(printInfo.unit) << L";" - << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap) - << L";0;" << printInfo.tSwap << '\n'; - break; - case CRITICAL: - std::wcout << L"SWAP CRITICAL - " << printInfo.percentFree << L"% free | 'swap'=" << printInfo.aSwap << BunitStr(printInfo.unit) << L";" - << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap) - << L";0;" << printInfo.tSwap << '\n'; - break; + std::wcout << L"CRITICAL - "; + } else { + state = OK; + std::wcout << L"OK - "; } + if (!printInfo.showUsed) + std::wcout << printInfo.percentFree << L"% free "; + else + std::wcout << 100 - printInfo.percentFree << L"% used "; + + std::wcout << "| 'swap'=" << currentValue << BunitStr(printInfo.unit) << L";" + << printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap) + << L";0;" << printInfo.tSwap << '\n'; + return state; } From ad1ab4239349deef3f566de71a372aab9e44461f Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Sat, 6 Oct 2018 20:26:15 +0200 Subject: [PATCH 2/2] Update ITL for windows check_swap 'used' feature --- doc/10-icinga-template-library.md | 12 ++++++------ itl/command-plugins-windows.conf | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/10-icinga-template-library.md b/doc/10-icinga-template-library.md index fb36af490..f6ebe4ac4 100644 --- a/doc/10-icinga-template-library.md +++ b/doc/10-icinga-template-library.md @@ -1632,12 +1632,12 @@ The data collection is instant. Custom attributes: -Name | Description -:---------------|:------------ -swap\_win\_warn | **Optional**. The warning threshold. Defaults to "10%". -swap\_win\_crit | **Optional**. The critical threshold. Defaults to "5%". -swap\_win\_unit | **Optional**. The unit to display the received value in, thresholds are interpreted in this unit. Defaults to "mb" (megabyte). - +Name | Description +:--------------- | :------------ +swap\_win\_warn | **Optional**. The warning threshold. Defaults to "10%". +swap\_win\_crit | **Optional**. The critical threshold. Defaults to "5%". +swap\_win\_unit | **Optional**. The unit to display the received value in, thresholds are interpreted in this unit. Defaults to "mb" (megabyte). +swap\_win\_show\_used | **Optional**. Show used swap instead of the free swap. ### update-windows diff --git a/itl/command-plugins-windows.conf b/itl/command-plugins-windows.conf index 1e48dc6b0..3ba7c98f7 100644 --- a/itl/command-plugins-windows.conf +++ b/itl/command-plugins-windows.conf @@ -258,6 +258,10 @@ object CheckCommand "swap-windows" { value = "$swap_win_unit$" description = "Unit to display swap in" } + "-U" = { + set_if = "$swap_win_show_used$" + description = "Show used swap instead of the free swap" + } } // Default