mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
Change how check_swap works and a debug line in check_disk
check_swap should now be faster and more accurate, it also checks against free space instead of taken swap. The output and CMakeLists have been updated accordingly. fixes #8287 refs #8060
This commit is contained in:
parent
8d551fa99f
commit
4771f79f35
@ -47,7 +47,6 @@ if (WIN32)
|
|||||||
target_link_libraries( check_network Pdh.lib )
|
target_link_libraries( check_network Pdh.lib )
|
||||||
target_link_libraries( check_ping Ntdll.lib iphlpapi.lib Ws2_32.lib )
|
target_link_libraries( check_ping Ntdll.lib iphlpapi.lib Ws2_32.lib )
|
||||||
target_link_libraries( check_procs Pdh.lib )
|
target_link_libraries( check_procs Pdh.lib )
|
||||||
target_link_libraries(check_swap Pdh.lib)
|
|
||||||
target_link_libraries( check_uptime ${Boost_SYSTEM_LIBRARY} )
|
target_link_libraries( check_uptime ${Boost_SYSTEM_LIBRARY} )
|
||||||
target_link_libraries( check_users wtsapi32.lib )
|
target_link_libraries( check_users wtsapi32.lib )
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ int check_drives(vector<drive>& vDrives)
|
|||||||
FindNextVolume(hVolume, szVolumeName, MAX_PATH);
|
FindNextVolume(hVolume, szVolumeName, MAX_PATH);
|
||||||
}
|
}
|
||||||
if (debug)
|
if (debug)
|
||||||
wcout << L"Creating vector from found volumes, removing cd drives etc.:" << endl;
|
wcout << L"Creating vector from found volumes, ignoring cd drives etc.:" << endl;
|
||||||
for (set<wstring>::iterator it = sDrives.begin(); it != sDrives.end(); ++it) {
|
for (set<wstring>::iterator it = sDrives.begin(); it != sDrives.end(); ++it) {
|
||||||
UINT type = GetDriveType(it->c_str());
|
UINT type = GetDriveType(it->c_str());
|
||||||
if (type == DRIVE_FIXED || type == DRIVE_REMOTE) {
|
if (type == DRIVE_FIXED || type == DRIVE_REMOTE) {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#include <Shlwapi.h>
|
#include <Shlwapi.h>
|
||||||
#include <Pdh.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <WinBase.h>
|
||||||
|
|
||||||
#include "thresholds.h"
|
#include "thresholds.h"
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ static BOOL debug = FALSE;
|
|||||||
struct printInfoStruct
|
struct printInfoStruct
|
||||||
{
|
{
|
||||||
threshold warn, crit;
|
threshold warn, crit;
|
||||||
double swap;
|
DWORD tSwap, aSwap;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
static int parseArguments(int, wchar_t **, po::variables_map&, printInfoStruct&);
|
||||||
@ -100,7 +100,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||||||
cout << desc;
|
cout << desc;
|
||||||
wprintf(
|
wprintf(
|
||||||
L"\nIt will then output a string looking something like this:\n\n"
|
L"\nIt will then output a string looking something like this:\n\n"
|
||||||
L"\tSWAP WARNING 23.8304%%|swap=23.8304%%;19.5;30;0;100\n\n"
|
L"\tSWAP WARNING - 20%% free | swap=2000B;3000;500;0;10000\n\n"
|
||||||
L"\"SWAP\" being the type of the check, \"WARNING\" the returned status\n"
|
L"\"SWAP\" being the type of the check, \"WARNING\" the returned status\n"
|
||||||
L"and \"23.8304%%\" is the returned value.\n"
|
L"and \"23.8304%%\" is the returned value.\n"
|
||||||
L"The performance data is found behind the \"|\", in order:\n"
|
L"The performance data is found behind the \"|\", in order:\n"
|
||||||
@ -166,25 +166,29 @@ int printOutput(printInfoStruct& printInfo)
|
|||||||
wcout << L"Constructing output string" << endl;
|
wcout << L"Constructing output string" << endl;
|
||||||
|
|
||||||
state state = OK;
|
state state = OK;
|
||||||
|
double fswap = (printInfo.aSwap / printInfo.tSwap) * 100.0;
|
||||||
|
|
||||||
if (printInfo.warn.rend(printInfo.swap))
|
if (!printInfo.warn.rend(printInfo.aSwap, printInfo.tSwap))
|
||||||
state = WARNING;
|
state = WARNING;
|
||||||
|
|
||||||
if (printInfo.crit.rend(printInfo.swap))
|
if (!printInfo.crit.rend(printInfo.aSwap, printInfo.tSwap))
|
||||||
state = CRITICAL;
|
state = CRITICAL;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case OK:
|
case OK:
|
||||||
wcout << L"SWAP OK " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
|
wcout << L"SWAP OK - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
|
<< printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
|
||||||
|
<< L";0;" << printInfo.tSwap << endl;
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
wcout << L"SWAP WARNING " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
|
wcout << L"SWAP WARNING - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
|
<< printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
|
||||||
|
<< L";0;" << printInfo.tSwap << endl;
|
||||||
break;
|
break;
|
||||||
case CRITICAL:
|
case CRITICAL:
|
||||||
wcout << L"SWAP CRITICAL " << printInfo.swap << L"% | swap=" << printInfo.swap << L"%;"
|
wcout << L"SWAP CRITICAL - " << fswap << L"% free | swap=" << printInfo.aSwap << L"B;"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;100" << endl;
|
<< printInfo.warn.pString(printInfo.tSwap) << L";" << printInfo.crit.pString(printInfo.tSwap)
|
||||||
|
<< L";0;" << printInfo.tSwap << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,49 +197,14 @@ int printOutput(printInfoStruct& printInfo)
|
|||||||
|
|
||||||
int check_swap(printInfoStruct& printInfo)
|
int check_swap(printInfoStruct& printInfo)
|
||||||
{
|
{
|
||||||
PDH_HQUERY phQuery;
|
_MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS;
|
||||||
PDH_HCOUNTER phCounter;
|
|
||||||
DWORD dwBufferSize = 0;
|
|
||||||
DWORD CounterType;
|
|
||||||
PDH_FMT_COUNTERVALUE DisplayValue;
|
|
||||||
PDH_STATUS err;
|
|
||||||
|
|
||||||
LPCWSTR path = L"\\Paging File(*)\\% Usage";
|
GlobalMemoryStatus(pMemBuf);
|
||||||
|
|
||||||
if (debug)
|
printInfo.tSwap = pMemBuf->dwTotalPageFile;
|
||||||
wcout << L"Opening querry handle" << endl;
|
printInfo.aSwap = pMemBuf->dwAvailPageFile;
|
||||||
|
|
||||||
err = PdhOpenQuery(NULL, NULL, &phQuery);
|
delete pMemBuf;
|
||||||
if (!SUCCEEDED(err))
|
|
||||||
goto die;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
wcout << L"Adding counter" << endl;
|
|
||||||
|
|
||||||
err = PdhAddEnglishCounter(phQuery, path, NULL, &phCounter);
|
|
||||||
if (!SUCCEEDED(err))
|
|
||||||
goto die;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
wcout << L"Collecting querry data" << endl;
|
|
||||||
|
|
||||||
err = PdhCollectQueryData(phQuery);
|
|
||||||
if (!SUCCEEDED(err))
|
|
||||||
goto die;
|
|
||||||
|
|
||||||
if (debug)
|
|
||||||
wcout << L"Formatting counter data" << endl;
|
|
||||||
|
|
||||||
err = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
|
|
||||||
if (SUCCEEDED(err)) {
|
|
||||||
printInfo.swap = DisplayValue.doubleValue;
|
|
||||||
PdhCloseQuery(phQuery);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
die:
|
|
||||||
if (phQuery)
|
|
||||||
PdhCloseQuery(phQuery);
|
|
||||||
die(err);
|
|
||||||
return 3;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user