2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
28 def check_wmic_process(item
, params
, info
):
29 name
, memwarn
, memcrit
, pagewarn
, pagecrit
, cpuwarn
, cpucrit
= params
30 count
, mem
, page
, userc
, kernelc
= 0, 0, 0, 0, 0
33 return (3, "No output from agent in section wmic_process")
36 psinfo
= dict(zip(legend
, line
))
37 if psinfo
.get("Name") is None:
39 elif "ThreadCount" in legend
and psinfo
["Name"].lower() == "system idle process":
40 cpucores
= int(psinfo
["ThreadCount"])
41 elif psinfo
["Name"].lower() == name
.lower():
43 mem
+= int(psinfo
["WorkingSetSize"])
44 page
+= int(psinfo
["PageFileUsage"])
45 userc
+= int(psinfo
["UserModeTime"])
46 kernelc
+= int(psinfo
["KernelModeTime"])
48 mem_mb
= mem
/ 1048576.0
49 page_mb
= page
/ 1048576.0
50 user_per_sec
= get_rate("wmic_process.user.%s.%d" % (name
, count
), time
.time(), userc
)
51 kernel_per_sec
= get_rate("wmic_process.kernel.%s.%d" % (name
, count
), time
.time(), kernelc
)
52 user_perc
= user_per_sec
/ 100000.0 / cpucores
53 kernel_perc
= kernel_per_sec
/ 100000.0 / cpucores
54 cpu_perc
= user_perc
+ kernel_perc
56 ("mem", mem_mb
, memwarn
, memcrit
),
57 ("page", page_mb
, pagewarn
, pagecrit
),
58 ("user", user_perc
, cpuwarn
, cpucrit
, 0, 100),
59 ("kernel", kernel_perc
, cpuwarn
, cpucrit
, 0, 100),
63 messages
.append("%d processes" % count
)
66 msg
= "%.0f%%/%.0f%% User/Kernel" % (user_perc
, kernel_perc
)
67 if cpu_perc
>= cpucrit
:
69 msg
+= "(!!) (critical at %d%%)" % cpucrit
70 elif cpu_perc
>= cpuwarn
:
72 msg
+= "(!) (warning at %d%%)" % cpuwarn
75 msg
= "%.1fMB RAM" % mem_mb
76 if mem_mb
>= memcrit
and memcrit
> 0:
78 msg
+= "(!!) (critical at %d MB)" % memcrit
79 elif mem_mb
>= memwarn
and memwarn
> 0:
81 msg
+= "(!) (warning at %d MB)" % memwarn
84 msg
= "%1.fMB Page" % page_mb
85 if page_mb
>= pagecrit
:
87 msg
+= "(!!) (critical at %d MB)" % pagecrit
88 elif page_mb
>= pagewarn
:
90 msg
+= "(!) (warning at %d MB)" % pagewarn
93 return (state
, ", ".join(messages
), perfdata
)
96 check_info
["wmic_process"] = {
97 'check_function': check_wmic_process
,
98 'service_description': 'Process %s',
100 'group': 'wmic_process'