Module: check_mk
Branch: master
Commit: ff7d8054ab0021646867611ea97bc3cf67290ce5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ff7d8054ab0021…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jun 4 20:34:04 2012 +0200
postgres_stat_database.size: New check for PostgreSQL database size
---
ChangeLog | 1 +
agents/plugins/mk_postgres | 3 ++-
checks/postgres_stat_database | 22 ++++++++++++++++++++--
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 65cea20..4228009 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
* mysql_capacity: New check for used/free capacity of MySQL databases
* postgres_sessions: New check for PostgreSQL number of sessions
* postgres_stat_database: New check for PostgreSQL database statistics
+ * postgres_stat_database.size: New check for PostgreSQL database size
1.2.0b6:
Multisite:
diff --git a/agents/plugins/mk_postgres b/agents/plugins/mk_postgres
index 225690f..722f9dd 100755
--- a/agents/plugins/mk_postgres
+++ b/agents/plugins/mk_postgres
@@ -4,5 +4,6 @@ if id postgres >/dev/null ; then
echo '<<<postgres_sessions>>>'
echo "select current_query = '<IDLE>', count(*) from
pg_stat_activity group by (current_query = '<IDLE>');" | su - postgres
-c "psql -A -t -F' '"
echo '<<<postgres_stat_database>>>'
- echo 'select * from pg_stat_database' | su - postgres -c "psql -A -F'
'" | sed '$d'
+ echo 'select *, pg_database_size(datname) "datsize" from
pg_stat_database;' \
+ | su - postgres -c "psql -A -F' '" | sed '$d'
fi
diff --git a/checks/postgres_stat_database b/checks/postgres_stat_database
index c151f81..86ffc44 100644
--- a/checks/postgres_stat_database
+++ b/checks/postgres_stat_database
@@ -103,11 +103,29 @@ def check_postgres_stat_database(item, params, info):
return (status, nagios_state_names[status] + " - " + ",
".join(infos), perfdata)
-
check_info['postgres_stat_database'] = {
"check_function" : check_postgres_stat_database,
"inventory_function" : inventory_postgres_stat_database,
- "service_description" : "PostgreSQL Statistics",
+ "service_description" : "PostgreSQL Statistics %s",
"has_perfdata" : True,
"group" : "postgres_stat_database",
}
+
+
+def check_postgres_stat_database_size(item, _no_params, info):
+ parsed = parse_postgres_stat(info)
+ if item not in parsed:
+ return (3, "UNKNOWN - Database not found")
+ stats = parsed[item]
+ size = stats["datsize"]
+
+ return (0, "OK - Size is %s" % get_bytes_human_readable(size),
[("size", size)])
+
+
+check_info['postgres_stat_database.size'] = {
+ "check_function" : check_postgres_stat_database_size,
+ "inventory_function" : inventory_postgres_stat_database,
+ "service_description" : "PostgreSQL Database Size %s",
+ "has_perfdata" : True,
+}
+