Module: check_mk
Branch: master
Commit: 397958b86742003a4519c8df471f59b39a5f80f5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=397958b8674200…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Jun 4 19:12:56 2012 +0200
postgres_sessions: New check for PostgreSQL number of sessions
---
ChangeLog | 1 +
agents/plugins/mk_postgres | 6 +++
checks/postgres_sessions | 72 ++++++++++++++++++++++++++++++++++
web/plugins/wato/check_parameters.py | 31 ++++++++++++++
4 files changed, 110 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f1bdc43..f19d22e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
* mysql.sessions: New check for MySQL sessions (need new plugin mk_mysql)
* mysql.innodb_io: New check for Disk-IO of InnoDB
* mysql_capacity: New check for used/free capacity of MySQL databases
+ * postgres_sessions: New check for PostgreSQL number of sessions
1.2.0b6:
Multisite:
diff --git a/agents/plugins/mk_postgres b/agents/plugins/mk_postgres
new file mode 100755
index 0000000..3dc2840
--- /dev/null
+++ b/agents/plugins/mk_postgres
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+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' '"
+fi
diff --git a/checks/postgres_sessions b/checks/postgres_sessions
new file mode 100644
index 0000000..8e9b9cb
--- /dev/null
+++ b/checks/postgres_sessions
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2012 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# <<<postgres_sessions>>>
+# f 1
+# t 4
+
+# t -> idle sessions, f -> active sessions
+
+def inventory_postgres_sessions(info):
+ if len(info) == 2:
+ return [(None, {})]
+
+def check_postgres_sessions(_no_item, params, info):
+ parsed = dict(info)
+ idle = int(parsed['t'])
+ running = int(parsed['f'])
+ total = idle + running
+
+ status = 0
+ infos = []
+ perfdata = []
+ for value, what, format, unit in [
+ ( total, "total", "%d", "" ),
+ ( running, "running", "%d", "" )]:
+ infos.append((format + " %s%s") % (value, what, unit))
+ if what in params:
+ warn, crit = params[what]
+ if value >= crit:
+ status = 2
+ infos[-1] += "(!!)"
+ elif value >= warn:
+ status = max(status, 1)
+ infos[-1] += "(!)"
+ else:
+ warn, crit = None, None
+ perfdata.append((what, value, warn, crit))
+
+ infotext = " - " + ", ".join(infos)
+ return (status, nagios_state_names[status] + infotext, perfdata)
+
+
+check_info['postgres_sessions'] = {
+ "check_function" : check_postgres_sessions,
+ "inventory_function" : inventory_postgres_sessions,
+ "service_description" : "PostgreSQL Sessions",
+ "has_perfdata" : True,
+ "group" : "postgres_sessions",
+}
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 3738b51..f7b9543 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -1032,6 +1032,37 @@ checkgroups.append((
checkgroups.append((
subgroup_applications,
+ "postgres_sessions",
+ _("PostgreSQL Sessions"),
+ Dictionary(
+ help = _("This check monitors the current number of active and idle
sessions on PostgreSQL"),
+ elements = [
+ ( "total",
+ Tuple(
+ title = _("Number of current sessions"),
+ elements = [
+ Integer(title = _("Warning at"), unit =
_("sessions"), default_value = 100),
+ Integer(title = _("Critical at"), unit =
_("sessions"), default_value = 200),
+ ],
+ ),
+ ),
+ ( "running",
+ Tuple(
+ title = _("Number of currently running sessions"),
+ help = _("Levels for the number of sessions that are currently
active"),
+ elements = [
+ Integer(title = _("Warning at"), unit =
_("sessions"), default_value = 10),
+ Integer(title = _("Critical at"), unit =
_("sessions"), default_value = 20),
+ ],
+ ),
+ ),
+ ]
+ ),
+ None,
+ None))
+
+checkgroups.append((
+ subgroup_applications,
"win_dhcp_pools",
_("Windows DHCP Pool"),
Tuple(