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.
27 # <<<mysql_capacity>>>
28 # greendb 163840 1428160512
29 # hirn 16384 238026752
30 # information_schema 9216 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>>>
38 # information_schema 147456 0
40 # performance_schema 0 0
41 # test 409255936 54525952
43 # FIXME: Crapy copy n paste! Consolidate with other mysql_* parse functions
44 def parse_mysql_capacity(info
):
46 name
= " ".join(line
[:-2])
49 return name
, size
, avail
54 if line
[0].startswith("[["):
55 instance
= line
[0][2:-2]
60 parsed
[instance
].append(cut_spaces(line
))
65 parsed
['mysql'].append(cut_spaces(line
))
71 def inventory_mysql_size(instance
, values
):
72 for dbname
, used
, avail
in values
:
73 if dbname
not in ["information_schema", "mysql", "performance_schema"] \
74 and used
!= 'NULL' and avail
!= 'NULL':
75 yield "%s:%s" % (instance
, dbname
)
77 def check_mysql_size(item
, params
, parsed
):
79 # support items discovered before 1.2.7
83 instance
, dbname
= item
.split(':')
85 dbs
= parsed
[instance
]
87 # size and avail are given as bytes
88 for db
, size
, _avail
in dbs
:
91 return 3, "Missing information - Size is reported as 'NULL'"
93 infotext
= "Size is %s" % get_bytes_human_readable(size
)
99 perfdata
= [("database_size", size
, warn_b
, crit_b
)]
102 infotext
+= " (critical at %s)" % get_bytes_human_readable(crit_b
)
105 infotext
+= " (warning at %s)" % get_bytes_human_readable(crit_b
)
108 perfdata
= [("database_size", size
)]
109 return state
, infotext
, perfdata
112 check_info
['mysql_capacity'] = {
113 "parse_function" : parse_mysql_capacity
,
114 "inventory_function" : inventory_mysql_size
,
115 "check_function" : check_mysql_size
,
116 "service_description" : "MySQL DB Size %s",
117 "has_perfdata" : True,
118 "group" : "mysql_db_size",