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 # <<<postgres_stat_database>>>
28 # datid datname numbackends xact_commit xact_rollback blks_read blks_hit tup_returned tup_fetched tup_inserted tup_updated tup_deleted
29 # 1 template1 0 0 0 0 0 0 0 0 0 0
30 # 11563 template0 0 0 0 0 0 0 0 0 0 0
31 # 11564 postgres 2 568360 17 811 8855508 157949341 879922 0 0 0
32 # 16385 foobardb 7 43619118 262 3589 838098632 854602076 441785363 8298 602481 2806
35 def parse_postgres_stat_database(info
):
48 if line
[0].startswith("[[[") and line
[0].endswith("]]]"):
49 instance_name
= line
[0][3:-3].upper()
51 elif line
[0] == "datid" and line
[1] == "datname":
54 row
= dict(zip(headers
, map(s
, line
)))
56 db_name
= "%s/%s" % (instance_name
, row
["datname"])
58 db_name
= row
["datname"]
64 # Create a check for all databases that have seen at least
65 # one commit in their live.
66 def inventory_postgres_stat_database(parsed
):
67 return [(k
, {}) for k
in parsed
.keys() if parsed
[k
]["xact_commit"] > 0]
70 def check_postgres_stat_database(item
, params
, parsed
):
71 if item
not in parsed
:
72 return (3, "Database not found")
78 this_time
= time
.time()
80 ("blks_read", "Blocks Read"),
81 ("tup_fetched", "Fetches"),
82 ("xact_commit", "Commits"),
83 ("tup_deleted", "Deletes"),
84 ("tup_updated", "Updates"),
85 ("tup_inserted", "Inserts"),
87 rate
= get_rate("postgres_stat_database.%s.%s" % (item
, what
), this_time
, stats
[what
])
88 infos
.append("%s: %.2f/s" % (title
, rate
))
90 warn
, crit
= params
[what
]
95 status
= max(status
, 1)
98 warn
, crit
= None, None
99 perfdata
.append((what
, rate
, warn
, crit
))
100 return (status
, ", ".join(infos
), perfdata
)
103 check_info
['postgres_stat_database'] = {
104 "parse_function": parse_postgres_stat_database
,
105 "inventory_function": inventory_postgres_stat_database
,
106 "check_function": check_postgres_stat_database
,
107 "service_description": "PostgreSQL DB %s Statistics",
108 "has_perfdata": True,
109 "group": "postgres_stat_database",
113 def check_postgres_stat_database_size(item
, _no_params
, parsed
):
114 if item
not in parsed
:
115 # In case of missing information we assume that the login into
116 # the database has failed and we simply skip this check. It won't
117 # switch to UNKNOWN, but will get stale.
118 raise MKCounterWrapped("Login into database failed")
121 size
= stats
["datsize"]
122 return (0, "Size is %s" % get_bytes_human_readable(size
), [("size", size
)])
125 check_info
['postgres_stat_database.size'] = {
126 "check_function": check_postgres_stat_database_size
,
127 "inventory_function": inventory_postgres_stat_database
,
128 "service_description": "PostgreSQL DB %s Size",
129 "has_perfdata": True,