GUI CSS: Removed snapin styles from py modules and added a _snapins.scss for the...
[check_mk.git] / checks / db2_bp_hitratios
blob2bd8620722162dde7b5e1714a34f948cd3c1021d
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 # <<<db2_bp_hitratios>>>
28 # [[[db2taddm:CMDBS1]]]
29 # BP_NAME TOTAL_HIT_RATIO_PERCENT DATA_HIT_RATIO_PERCENT INDEX_HIT_RATIO_PERCENT XDA_HIT_RATIO_PERCENT
30 # IBMDEFAULTBP 99.36 98.48 99.94 -
31 # BUF8K 99.94 99.94 99.95 -
32 # BUF32K 99.99 99.98 99.99 -
33 # BP8 100.00 100.00 - -
36 def parse_db2_bp_hitratios(info):
37 pre_parsed = parse_db2_dbs(info)
39 # Some databases run in DPF mode. This means they are split over several instances
40 # Each instance has its own bufferpool hitratio information. We create on service for each instance
41 databases = {}
42 for instance, lines in pre_parsed[1].items():
43 header_idx, node_names = None, []
44 for idx, line in enumerate(lines):
45 if line[0] == "node":
46 node_names.append(" ".join(line[1:]))
47 elif line[0] == "BP_NAME":
48 header_idx = idx
49 node_headers = line
50 break
52 if node_names:
53 # DPF mode
54 current_node_offset = -1
55 current_instance = None
56 for line in lines[header_idx + 1:]:
57 if line[0] == "IBMDEFAULTBP":
58 current_node_offset += 1
59 current_instance = "%s DPF %s" % (instance, node_names[current_node_offset])
60 databases.setdefault(current_instance, [node_headers])
61 databases[current_instance].append(line)
62 else:
63 databases[instance] = lines
65 return databases
68 def inventory_db2_bp_hitratios(parsed):
69 for key, values in parsed.items():
70 for field in values[1:]:
71 if not field[0].startswith("IBMSYSTEMBP"):
72 yield "%s:%s" % (key, field[0]), {}
75 def check_db2_bp_hitratios(item, no_params, parsed):
76 db_instance, field = item.rsplit(":", 1)
77 db = parsed.get(db_instance)
78 if not db:
79 raise MKCounterWrapped("Login into database failed")
81 headers = db[0]
82 for line in db[1:]:
83 if field == line[0]:
84 hr_info = dict(zip(headers[1:], line[1:])) # skip BP_NAME
85 for key in headers[1:]:
86 value = hr_info[key]
87 value = value.replace("-", "0").replace(",", ".")
88 key = key.replace("_RATIO_PERCENT", "")
89 map_key_to_text = {
90 "TOTAL_HIT": "Total",
91 "DATA_HIT": "Data",
92 "INDEX_HIT": "Index",
93 "XDA_HIT": "XDA",
95 yield 0, "%s: %s%%" % (map_key_to_text[key], value), [("%sratio" % key.lower(),
96 float(value), None, None, 0,
97 100)]
98 break
101 check_info['db2_bp_hitratios'] = {
102 "parse_function": parse_db2_bp_hitratios,
103 "service_description": "DB2 BP-Hitratios %s",
104 "check_function": check_db2_bp_hitratios,
105 "inventory_function": inventory_db2_bp_hitratios,
106 "has_perfdata": True,
107 "includes": ["db2.include"]