Module: check_mk
Branch: master
Commit: abc37645142428fd132ed5d4fec382e4b382d29e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=abc37645142428…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Feb 21 16:51:23 2017 +0100
4029 Windows Agent Process Monitoring: Now able to set levels to process age
Change-Id: I64643c7865623716bf6e9a39bfe5e751379342e4
---
.werks/4029 | 9 ++++++++
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 1329664 -> 1332224 bytes
agents/windows/check_mk_agent-64.unstripped.exe | Bin 15658530 -> 15690517 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 1329664 -> 1332224 bytes
agents/windows/check_mk_agent.exe | Bin 1305600 -> 1308672 bytes
agents/windows/check_mk_agent.msi | Bin 2905088 -> 2910720 bytes
agents/windows/check_mk_agent.unstripped.exe | Bin 13549114 -> 13575746 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 1305600 -> 1308672 bytes
agents/windows/crash.exe | Bin 101624 -> 101624 bytes
agents/windows/install_agent-64.exe | Bin 586870 -> 588355 bytes
agents/windows/install_agent.exe | Bin 583912 -> 585583 bytes
agents/windows/nowin.exe | Bin 103760 -> 103760 bytes
agents/windows/sections/SectionPS.cc | 26 +++++++++++++++++++----
agents/windows/sections/SectionPS.h | 2 +-
checks/ps.include | 16 +++++++++++++-
16 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/.werks/4029 b/.werks/4029
new file mode 100644
index 0000000..04f161e
--- /dev/null
+++ b/.werks/4029
@@ -0,0 +1,9 @@
+Title: Windows Agent Process Monitoring: Now able to set levels to process age
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.5.0i1
+Date: 1487692248
+Class: feature
+
+
diff --git a/agents/windows/build_version b/agents/windows/build_version
index fe534ad..7f9c296 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-2543
+2599
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 79ab757..5a5f003 100755
Binary files a/agents/windows/check_mk_agent-64.exe and
b/agents/windows/check_mk_agent-64.exe differ
diff --git a/agents/windows/check_mk_agent-64.unstripped.exe
b/agents/windows/check_mk_agent-64.unstripped.exe
index cd2401d..bda51ed 100755
Binary files a/agents/windows/check_mk_agent-64.unstripped.exe and
b/agents/windows/check_mk_agent-64.unstripped.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index 8ad627c..bdb8e76 100755
Binary files a/agents/windows/check_mk_agent-64.unversioned.exe and
b/agents/windows/check_mk_agent-64.unversioned.exe differ
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 9723e87..e172ed1 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/check_mk_agent.msi b/agents/windows/check_mk_agent.msi
index 0b254b8..291835a 100755
Binary files a/agents/windows/check_mk_agent.msi and b/agents/windows/check_mk_agent.msi
differ
diff --git a/agents/windows/check_mk_agent.unstripped.exe
b/agents/windows/check_mk_agent.unstripped.exe
index 824db74..9b23f09 100755
Binary files a/agents/windows/check_mk_agent.unstripped.exe and
b/agents/windows/check_mk_agent.unstripped.exe differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index 6896b17..9fc5bc2 100755
Binary files a/agents/windows/check_mk_agent.unversioned.exe and
b/agents/windows/check_mk_agent.unversioned.exe differ
diff --git a/agents/windows/crash.exe b/agents/windows/crash.exe
index a672400..d05202c 100755
Binary files a/agents/windows/crash.exe and b/agents/windows/crash.exe differ
diff --git a/agents/windows/install_agent-64.exe b/agents/windows/install_agent-64.exe
index 4fdd569..844efbe 100755
Binary files a/agents/windows/install_agent-64.exe and
b/agents/windows/install_agent-64.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index 962a2c6..0a6cdea 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ
diff --git a/agents/windows/nowin.exe b/agents/windows/nowin.exe
index dbd94c0..72eb539 100755
Binary files a/agents/windows/nowin.exe and b/agents/windows/nowin.exe differ
diff --git a/agents/windows/sections/SectionPS.cc b/agents/windows/sections/SectionPS.cc
index ebf1579..8d84e31 100644
--- a/agents/windows/sections/SectionPS.cc
+++ b/agents/windows/sections/SectionPS.cc
@@ -29,6 +29,12 @@
#include "../logging.h"
#include <windows.h>
#include <tlhelp32.h>
+#include <iomanip>
+
+
+extern double file_time(const FILETIME *filetime);
+extern double current_time();
+
SectionPS::SectionPS(Configuration &config)
: Section("ps")
@@ -146,7 +152,7 @@ bool SectionPS::produceOutputInner(std::ostream &out, const
Environment&) {
void SectionPS::outputProcess(std::ostream &out, ULONGLONG virtual_size,
ULONGLONG working_set_size,
- ULONGLONG pagefile_usage, ULONGLONG usermode_time,
+ ULONGLONG pagefile_usage, ULONGLONG uptime, ULONGLONG
usermode_time,
ULONGLONG kernelmode_time, DWORD process_id,
DWORD process_handle_count, DWORD thread_count,
const std::string &user, LPCSTR exe_file) {
@@ -156,7 +162,7 @@ void SectionPS::outputProcess(std::ostream &out, ULONGLONG
virtual_size,
<< working_set_size / 1024 << ",0"
<< "," << process_id << "," <<
pagefile_usage / 1024 << ","
<< usermode_time << "," << kernelmode_time <<
","
- << process_handle_count << "," << thread_count
<< ")\t" << exe_file
+ << process_handle_count << "," << thread_count
<< "," << uptime << ")\t" << exe_file
<< "\n";
}
@@ -195,10 +201,18 @@ bool SectionPS::outputWMI(std::ostream &out) {
LocalFree(argv);
}
+ auto creation_date =
result.get<std::wstring>(L"CreationDate");
+ std::wistringstream ss(creation_date);
+ std::tm t;
+ ss >> std::get_time(&t, L"%Y%m%d%H%M%S");
+ time_t creation_time = mktime(&t);
+ auto uptime = (ULONGLONG)((time_t)current_time() - creation_time);
+
outputProcess(
out,
std::stoull(result.get<std::string>(L"VirtualSize")),
std::stoull(result.get<std::string>(L"WorkingSetSize")),
result.get<int>(L"PagefileUsage"),
+ uptime,
std::stoull(result.get<std::wstring>(L"UserModeTime")),
std::stoull(result.get<std::wstring>(L"KernelModeTime")),
processId, result.get<int>(L"HandleCount"),
@@ -288,10 +302,14 @@ bool SectionPS::outputNative(std::ostream &out) {
pagefile_usage = it_perf->second.pagefile_usage;
}
+ // Uptime
+ double ft = file_time(&createTime);
+ ULONGLONG uptime = (ULONGLONG)(current_time() - ft);
+
// Note: CPU utilization is determined out of usermodetime and
// kernelmodetime
outputProcess(out, virtual_size, working_set_size, pagefile_usage,
- usermodetime.QuadPart, kernelmodetime.QuadPart,
+ uptime, usermodetime.QuadPart, kernelmodetime.QuadPart,
pe32.th32ProcessID, processHandleCount,
pe32.cntThreads, user, pe32.szExeFile);
}
@@ -304,7 +322,7 @@ bool SectionPS::outputNative(std::ostream &out) {
// We simply fake this entry..
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
- outputProcess(out, 0, 0, 0, 0, 0, 0, 0, sysinfo.dwNumberOfProcessors,
+ outputProcess(out, 0, 0, 0, 0, 0, 0, 0, 0, sysinfo.dwNumberOfProcessors,
"SYSTEM", "System Idle Process");
return true;
}
diff --git a/agents/windows/sections/SectionPS.h b/agents/windows/sections/SectionPS.h
index 42ea89d..56edb08 100644
--- a/agents/windows/sections/SectionPS.h
+++ b/agents/windows/sections/SectionPS.h
@@ -63,7 +63,7 @@ private:
void outputProcess(std::ostream &out, ULONGLONG virtual_size,
ULONGLONG working_set_size, ULONGLONG pagefile_usage,
- ULONGLONG usermode_time, ULONGLONG kernelmode_time,
+ ULONGLONG uptime, ULONGLONG usermode_time, ULONGLONG
kernelmode_time,
DWORD process_id, DWORD process_handle_count,
DWORD thread_count, const std::string &user,
LPCSTR exe_file);
diff --git a/checks/ps.include b/checks/ps.include
index 13d35d3..02fcd5f 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -376,6 +376,20 @@ def check_ps_common(item, params, parsed, cpu_cores = 1, info_name =
"processes"
# even more data: processId, pagefile_usage, usermodetime,
kernelmodetime, threadCount, openHandles
pid, pagefile_usage, user_c, kernel_c, handle_c = map(saveint,
process_info[4:9])
+ # Info may include creation time
+ if len(process_info) >= 11:
+ uptime_secs = int(process_info[10])
+ creation_time_unix = int(now - uptime_secs)
+ if creation_time_unix != 0:
+ process.append(("creation time",
(get_timestamp_human_readable(creation_time_unix), "")))
+
+ elapsed = now - creation_time_unix
+ max_elapsed = max(max_elapsed, elapsed)
+ if min_elapsed == None:
+ min_elapsed = elapsed
+ else:
+ min_elapsed = min(min_elapsed, elapsed)
+
process.append(("pagefile usage", (pagefile_usage,
"")))
process.append(("handle count", (handle_c,
"")))
@@ -552,7 +566,7 @@ def check_ps_common(item, params, parsed, cpu_cores = 1, info_name =
"processes"
if max_elapsed >= crit_age:
state = 2
infotext += "(!!)"
- elif max_elapsed >= crit_age:
+ elif max_elapsed >= warn_age:
state = max(state, 1)
infotext += "(!)"