Refactored snapin server_time to new snapin API
[check_mk.git] / checks / lparstat_aix
blob54bb557effc9e54be91f673630a7469072ed80c4
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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.
27 # +------------------------------------------------------------------+
28 # | This file has been contributed and is copyrighted by: |
29 # | |
30 # | Joerg Linge 2009 <joerg.linge@pnp4nagios.org> Copyright 2010 |
31 # +------------------------------------------------------------------+
33 # %user %sys %wait %idle physc %entc lbusy app vcsw phint
34 # ----- ---- ----- ----- ----- ----- ------ --- ---- -----
35 # 2.5 6.0 0.1 91.5 0.03 11.4 1.8 3.27 1976647217 490545630
37 # %user %sys %wait %idle physc %entc lbusy vcsw phint %nsp %utcyc
38 # ----- ----- ------ ------ ----- ----- ------ ----- ----- ----- ------
39 # 0.2 0.4 0.0 99.3 0.02 1.7 0.0 215 3 101 0.64
41 # %user %sys %wait %idle physc %entc lbusy app vcsw phint %nsp %utcyc
42 # ----- ----- ------ ------ ----- ----- ------ --- ----- ----- ----- ------
43 # 0.1 0.4 0.0 99.5 0.02 1.6 0.0 3.97 297 0 101 0.64
45 # %user %sys %wait %idle physc %entc lbusy vcsw phint %nsp
46 # ----- ----- ------ ------ ----- ----- ------ ----- ----- -----
47 # 0.1 0.2 0.0 99.6 0.04 1.8 2.3 371 0 58
49 lparstat_default_levels = (5, 10)
51 def inventory_lparstat(info):
52 if len(info) >= 1 and len(info[-1]) >= 5:
53 return [(None, "lparstat_default_levels")]
55 def check_lparstat(item, params, info):
56 if len(info) == 1:
57 # Old agent provided only the values in a single line
58 line = info[0]
59 if len(line) == 12:
60 cols = [ 'physc', 'entc', 'lbusy', 'app', 'vcsw', 'phint', 'nsp', 'utcyc' ]
61 uom = [ '', '%', '', '', '', '', '%', '%' ]
62 values = line[-8:]
63 elif len(line) == 11:
64 cols = [ 'physc', 'entc', 'lbusy', 'app', 'vcsw', 'phint', 'nsp' ]
65 uom = [ '', '%', '', '', '', '', '%' ]
66 values = line[-7:]
67 elif len(line) == 10:
68 cols = [ 'physc', 'entc', 'lbusy', 'app', 'vcsw', 'phint' ]
69 uom = [ '', '%', '', '', '', '' ]
70 values = line[-6:]
71 elif len(line) == 9:
72 cols = [ 'physc', 'entc', 'lbusy', 'app' ]
73 uom = [ '', '%', '', '' ]
74 values = line[-4:]
75 elif len(line) == 6:
76 cols = [ 'nsp', 'utcyc' ]
77 uom = [ '%', '%' ]
78 values = line[-2:]
79 # else:
80 # Invalid output, let exception happen
81 else:
82 # The new agent provides three lines, the title line, spacer line and the values
83 cols = [ c.replace('%', '') for c in info[-3] ]
84 uom = [ '%' * ('%' in c) for c in info[-3] ]
85 values = info[-1]
87 perfdata = zip(cols, map(float, values))
88 output = ', '.join("%s: %s%s" % (c.title(), v, u)
89 for c, v, u in zip(cols, values, uom))
90 return 0, output, perfdata
92 check_info["lparstat_aix"] = {
93 'check_function': check_lparstat,
94 'inventory_function': inventory_lparstat,
95 'service_description': 'lparstat',
96 'has_perfdata': True,
99 # Utilization and IO/Wait
100 kernel_util_default_levels = None
102 def inventory_lparstat_aix_cpu(info):
103 if len(info) >= 1 and len(info[-1]) >= 4:
104 return [(None, "kernel_util_default_levels")]
106 def check_lparstat_aix_cpu(_no_item, params, info):
107 if len(info) == 1:
108 line = info[0] # old (single line) agent output
109 else:
110 line = info[-1]
111 user, system, wait, _idle = map(float, line[:4])
112 perfdata = [
113 ("user", user),
114 ("system", system),
115 ("wait", wait),
118 util = user + system + wait
120 infotext = "user: %2.1f%%, system: %2.1f%%, wait: %2.1f%%" % (user, system, wait)
122 # You may set a warning/critical level on the io wait
123 # percentage. This can be done by setting params to
124 # a pair of (warn, crit)
125 result = 0
127 if type(params) == tuple: # old config only levels io wait
128 warn, crit = params
129 if wait >= crit:
130 result = max(result, 2)
131 infotext += "(!!)"
132 elif wait >= warn:
133 result = max(result, 1)
134 infotext += "(!)"
136 elif type(params) == dict:
137 if 'util' in params:
138 warn, crit = params['util']
139 if util >= crit:
140 result = max(result, 2)
141 elif util >= warn:
142 result = max(result, 1)
143 if 'iowait' in params:
144 warn, crit = params['iowait']
145 if wait >= crit:
146 result = max(result, 2)
147 elif wait >= warn:
148 result = max(result, 1)
150 return (result, infotext, perfdata)
152 check_info['lparstat_aix.cpu_util'] = {
153 "check_function" : check_lparstat_aix_cpu,
154 "inventory_function" : inventory_lparstat_aix_cpu,
155 "service_description" : "CPU utilization",
156 "has_perfdata" : True,
157 "group" : "cpu_iowait",