diff --git a/docs/docs/reference/windows/CheckSystem.md b/docs/docs/reference/windows/CheckSystem.md
index a8b164bff..1394f1eda 100644
--- a/docs/docs/reference/windows/CheckSystem.md
+++ b/docs/docs/reference/windows/CheckSystem.md
@@ -104,6 +104,7 @@ CPU Load ok|'total 5m'=16%;80;90 'total 1m'=13%;80;90 'total 5s'=13%;80;90
+
#### Command-line Arguments
@@ -131,6 +132,7 @@ CPU Load ok|'total 5m'=16%;80;90 'total 1m'=13%;80;90 'total 5s'=13%;80;90
| [detail-syntax](#check_cpu_detail-syntax) | ${time}: ${load}% | Detail level syntax. |
| [perf-syntax](#check_cpu_perf-syntax) | ${core} ${time} | Performance alias syntax. |
| time | | The time to check |
+| cores | N/A | This will remove the filter to include the cores, if you use filter dont use this as well. |
diff --git a/include/win_sysinfo/win_sysinfo.cpp b/include/win_sysinfo/win_sysinfo.cpp
index 1effafdbc..cdc29c890 100644
--- a/include/win_sysinfo/win_sysinfo.cpp
+++ b/include/win_sysinfo/win_sysinfo.cpp
@@ -23,10 +23,14 @@
#include
#include
+#include
+#include
+#include "str/xtos.hpp"
+
#include
+#include
#include
#include
-#include
#include
namespace windows {
@@ -46,6 +50,7 @@ namespace windows {
typedef DWORD(WINAPI *tGetProcessImageFileName)(HANDLE hProcess, LPWSTR lpImageFileName, DWORD nSize);
typedef LONG(NTAPI *tNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
typedef DWORD(WINAPI *tWTSGetActiveConsoleSessionId)();
+ typedef LONG(NTAPI *tGetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
typedef BOOL(*tWTSQueryUserToken)(ULONG SessionId,PHANDLE phToken);
@@ -58,6 +63,7 @@ namespace windows {
tIsWow64Process pIsWow64Process = NULL;
tGetProcessImageFileName pGetProcessImageFileName = NULL;
tNtQuerySystemInformation pNtQuerySystemInformation = NULL;
+ tGetNativeSystemInfo pGetNativeSystemInfo = NULL;
tWTSQueryUserToken pWTSQueryUserToken = NULL;
tWTSGetActiveConsoleSessionId pWTSGetActiveConsoleSessionId = NULL;
@@ -160,9 +166,17 @@ namespace windows {
throw nsclient::nsclient_exception("Failed to load: NtQuerySystemInformation: " + error::lookup::last_error());
return pNtQuerySystemInformation(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength);
}
+
+ bool GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) {
+ if (pGetNativeSystemInfo == NULL)
+ pGetNativeSystemInfo = reinterpret_cast(GetProcAddress(LoadLibrary(L"Kernel32"), "GetNativeSystemInfo"));
+ if (pGetNativeSystemInfo == NULL)
+ return false;
+ pGetNativeSystemInfo(lpSystemInfo);
+ return true;
+ }
}
- winapi::SYSTEM_BASIC_INFORMATION g_systemBasicInformation;
unsigned long g_windowsVersion;
// ACCESS_MASK ProcessQueryAccess;
// ACCESS_MASK ProcessAllAccess;
@@ -171,9 +185,6 @@ namespace windows {
// ACCESS_MASK ThreadAllAccess;
//RTL_OSVERSIONINFOEXW g_versionInfo;
RTL_OSVERSIONINFOEXW g_versionInfo;
- void QuerySystemInformation() {
- winapi::NtQuerySystemInformation(winapi::SystemBasicInformation, &g_systemBasicInformation, sizeof(winapi::SYSTEM_BASIC_INFORMATION), NULL);
- }
// RTL_OSVERSIONINFOEXW is defined in winnt.h
bool GetOsVersion(RTL_OSVERSIONINFOEXW* pk_OsVer) {
@@ -238,7 +249,8 @@ namespace windows {
}
bool g_hasVersion = false;
- bool g_hasBasicInfo = false;
+ unsigned long numberOfCores = 0;
+
boost::scoped_array g_CPUIdleTimeOld;
boost::scoped_array g_CPUTotalTimeOld;
@@ -352,12 +364,20 @@ namespace windows {
}
- long system_info::get_numberOfProcessorscores() {
- if (!g_hasBasicInfo) {
- QuerySystemInformation();
- g_hasBasicInfo = true;
+ unsigned long system_info::get_numberOfProcessorscores() {
+ if (numberOfCores == 0) {
+ SYSTEM_INFO si;
+ if (winapi::GetNativeSystemInfo(&si)) {
+ numberOfCores = si.dwNumberOfProcessors;
+ NSC_LOG_MESSAGE("Number of cores detected (new) as " + str::xtos(numberOfCores));
+ return numberOfCores;
+ }
+ winapi::SYSTEM_BASIC_INFORMATION systemBasicInformation;
+ winapi::NtQuerySystemInformation(winapi::SystemBasicInformation, &systemBasicInformation, sizeof(winapi::SYSTEM_BASIC_INFORMATION), NULL);
+ numberOfCores = static_cast(systemBasicInformation.NumberOfProcessors);
+ NSC_LOG_MESSAGE("Number of cores detected (old) as " + str::xtos(numberOfCores));
}
- return g_systemBasicInformation.NumberOfProcessors;
+ return numberOfCores;
}
hlp::buffer system_info::get_system_process_information(int size) {
diff --git a/include/win_sysinfo/win_sysinfo.hpp b/include/win_sysinfo/win_sysinfo.hpp
index 595f18506..b81b1d780 100644
--- a/include/win_sysinfo/win_sysinfo.hpp
+++ b/include/win_sysinfo/win_sysinfo.hpp
@@ -115,7 +115,7 @@ namespace windows {
static std::string get_version_string();
static unsigned long get_version();
static OSVERSIONINFOEX* get_versioninfo();
- static long get_numberOfProcessorscores();
+ static unsigned long get_numberOfProcessorscores();
static std::vector get_suite_list();
static long long get_suite_i();
@@ -136,6 +136,8 @@ namespace windows {
bool IsWow64(HANDLE hProcess, bool def = false);
DWORD GetProcessImageFileName(HANDLE hProcess, LPWSTR lpImageFileName, DWORD nSize);
LONG NtQueryInformationProcess(HANDLE ProcessHandle, DWORD ProcessInformationClass, PVOID ProcessInformation, DWORD ProcessInformationLength, PDWORD ReturnLength);
+ bool GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo);
+
INT VDMEnumTaskWOWEx(DWORD dwProcessId, tTASKENUMPROCEX fp, LPARAM lparam);
}
diff --git a/modules/CheckSystem/CheckSystem.cpp b/modules/CheckSystem/CheckSystem.cpp
index bd96ac4f0..86435edf5 100644
--- a/modules/CheckSystem/CheckSystem.cpp
+++ b/modules/CheckSystem/CheckSystem.cpp
@@ -559,17 +559,24 @@ void CheckSystem::check_cpu(const PB::Commands::QueryRequestMessage::Request &re
modern_filter::data_container data;
modern_filter::cli_helper filter_helper(request, response, data);
std::vector times;
+ bool show_all_cores = false;
filter_type filter;
filter_helper.add_options("load > 80", "load > 90", "core = 'total'", filter.get_filter_syntax(), "ignored");
- filter_helper.add_syntax("${status}: ${problem_list}", "${time}: ${load}%", "${core} ${time}", "", "%(status): CPU load is ok.");
+ filter_helper.add_syntax("${status}: ${problem_list}", "${time}: ${load}%", "${core} ${time}", "", "%(status): CPU load is ok.");
filter_helper.get_desc().add_options()
- ("time", po::value>(×), "The time to check")
+ ("time", po::value>(×), "The time to check")
+ ("cores", boost::program_options::bool_switch(&show_all_cores),
+ "This will remove the filter to include the cores, if you use filter dont use this as well.")
;
if (!filter_helper.parse_options())
return;
+ if (show_all_cores && filter_helper.data.filter_string.size() == 1) {
+ filter_helper.data.filter_string.clear();
+ }
+
if (times.empty()) {
times.push_back("5m");
times.push_back("1m");