mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6651 from Icinga/feature/check-swap-show-used
Add 'used' feature to check_swap
This commit is contained in:
commit
b2957bb812
|
@ -1633,12 +1633,12 @@ The data collection is instant.
|
||||||
|
|
||||||
Custom attributes:
|
Custom attributes:
|
||||||
|
|
||||||
Name | Description
|
Name | Description
|
||||||
:---------------|:------------
|
:--------------- | :------------
|
||||||
swap\_win\_warn | **Optional**. The warning threshold. Defaults to "10%".
|
swap\_win\_warn | **Optional**. The warning threshold. Defaults to "10%".
|
||||||
swap\_win\_crit | **Optional**. The critical threshold. Defaults to "5%".
|
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\_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 <a id="windows-plugins-update-windows"></a>
|
### update-windows <a id="windows-plugins-update-windows"></a>
|
||||||
|
|
||||||
|
|
|
@ -262,6 +262,10 @@ object CheckCommand "swap-windows" {
|
||||||
value = "$swap_win_unit$"
|
value = "$swap_win_unit$"
|
||||||
description = "Unit to display swap in"
|
description = "Unit to display swap in"
|
||||||
}
|
}
|
||||||
|
"-U" = {
|
||||||
|
set_if = "$swap_win_show_used$"
|
||||||
|
description = "Show used swap instead of the free swap"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default
|
// Default
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct printInfoStruct
|
||||||
double aSwap;
|
double aSwap;
|
||||||
double percentFree;
|
double percentFree;
|
||||||
Bunit unit = BunitMB;
|
Bunit unit = BunitMB;
|
||||||
|
bool showUsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pageFileInfo
|
struct pageFileInfo
|
||||||
|
@ -73,6 +74,7 @@ static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoSt
|
||||||
("warning,w", po::wvalue<std::wstring>(), "Warning threshold")
|
("warning,w", po::wvalue<std::wstring>(), "Warning threshold")
|
||||||
("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
|
("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
|
||||||
("unit,u", po::wvalue<std::wstring>(), "The unit to use for display (default MB)")
|
("unit,u", po::wvalue<std::wstring>(), "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);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,30 +185,35 @@ static int printOutput(printInfoStruct& printInfo)
|
||||||
|
|
||||||
state state = OK;
|
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;
|
state = WARNING;
|
||||||
|
std::wcout << L"WARNING - ";
|
||||||
if (printInfo.crit.rend(printInfo.aSwap, printInfo.tSwap))
|
} else if (printInfo.crit.rend(currentValue, printInfo.tSwap)) {
|
||||||
state = CRITICAL;
|
state = CRITICAL;
|
||||||
|
std::wcout << L"CRITICAL - ";
|
||||||
switch (state) {
|
} else {
|
||||||
case OK:
|
state = OK;
|
||||||
std::wcout << L"SWAP OK - " << printInfo.percentFree << L"% free | 'swap'=" << printInfo.aSwap << BunitStr(printInfo.unit) << L";"
|
std::wcout << L"OK - ";
|
||||||
<< 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue