Cleanup config.nodes_of
[check_mk.git] / checks / mysql_capacity
blob05db2e79f0694d7e875f6bc2c4d8faa482c8f4f3
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 # <<<mysql_capacity>>>
28 # greendb 163840 1428160512
29 # hirn 16384 238026752
30 # information_schema 9216 0
31 # mysql 650067 0
32 # performance_schema 0 0
33 # wa-confluence 15499264 13805551616
35 # new: can have instance headers (can be empty), e.g.:
36 # <<<mysql_capacity>>>
37 # [[]]
38 # information_schema 147456 0
39 # mysql 665902 292
40 # performance_schema 0 0
41 # test 409255936 54525952
44 def parse_mysql_capacity(info):
45 def _name_size_avail(line):
46 name = " ".join(line[:-2])
47 return name, line[-2], line[-1]
49 parsed = {}
50 for instance, line in _mysql_iter_instance_lines(info): # pylint: disable=undefined-variable
51 name, size, avail = _name_size_avail(line)
52 parsed.setdefault(instance, {})[name] = (size, avail)
53 return parsed
56 @discover
57 def inventory_mysql_size(instance, values):
58 for dbname, (used, avail) in values.iteritems():
59 if dbname not in ["information_schema", "mysql", "performance_schema"] \
60 and used != 'NULL' and avail != 'NULL':
61 yield "%s:%s" % (instance, dbname)
64 def check_mysql_size(item, params, parsed):
65 if ":" not in item:
66 # support items discovered before 1.2.7
67 instance = "mysql"
68 dbname = item
69 else:
70 instance, dbname = item.split(':')
72 instance_data = parsed.get(instance)
73 if not instance_data or dbname not in instance_data:
74 return
76 size, _avail = instance_data[dbname]
78 # size and avail are given as bytes
79 if size == 'NULL':
80 yield 3, "Missing information - Size is reported as 'NULL'"
81 return
83 size = int(size)
84 levels = (params[0] * 1024, params[1] * 1024) if params else None
85 yield check_levels(
86 size,
87 'database_size',
88 levels,
89 human_readable_func=get_bytes_human_readable,
90 infoname="Size")
93 check_info['mysql_capacity'] = {
94 "parse_function": parse_mysql_capacity,
95 "inventory_function": inventory_mysql_size,
96 "check_function": check_mysql_size,
97 "service_description": "MySQL DB Size %s",
98 "has_perfdata": True,
99 "group": "mysql_db_size",
100 "includes": ["mysql.include"],