Module: check_mk
Branch: master
Commit: 6c669905976809cd23f1c5dd14618962bce246c1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6c669905976809…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Oct 27 15:56:30 2010 +0200
New check tcp_conn_states
---
ChangeLog | 1 +
agents/check_mk_agent.linux | 4 ++
checkman/tcp_conn_stats | 27 ++++++++++
checks/tcp_conn_stats | 75 +++++++++++++++++++++++++++
pnp-rraconf/check_mk-tcp_conn_stats.rra.cfg | 1 +
pnp-templates/check_mk-tcp_conn_stats.php | 49 +++++++++++++++++
6 files changed, 157 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8b746c1..fc36b90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
* blade_blowers: Can handle responses without rpm values now. Improved output
* cisco_fan: Does not inentorize 'notPresent' sensors anymore. Improved output
* cisco_power: Not using power source as threshold anymore. Improved output
+ * tcp_conn_stats: new check for monitoring number of current TCP connections
Multisite:
* The custom open/close states of custom links are now stored for each
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 655b661..c3c2f14 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -124,6 +124,10 @@ then
done
fi
+# Number of TCP connections in the various states
+echo '<<<tcp_conn_stats>>>'
+netstat -nt | awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
+
# Platten- und RAID-Status von LSI-Controlleren, falls vorhanden
if which cfggen > /dev/null ; then
echo '<<<lsi>>>'
diff --git a/checkman/tcp_conn_stats b/checkman/tcp_conn_stats
new file mode 100644
index 0000000..0e14777
--- /dev/null
+++ b/checkman/tcp_conn_stats
@@ -0,0 +1,27 @@
+title: Monitor number of TCP connections per state
+agents: linux
+author: Mathias Kettner <mk(a)mathias-kettner.de>
+license: GPL
+distribution: check_mk
+description:
+ This check monitors the number of TCP connections in the various possible states,
+ which are: {ESTABLISHED}, {SYN_SENT}, {SYN_RECV}, {LAST_ACK}, {CLOSE_WAIT}, {TIME_WAIT}, {CLOSED}, {CLOSING}, {FIN_WAIT1}, {FIN_WAIT2}.
+
+perfdata:
+ One variable for each of the state types listed in the description (which are ten).
+
+inventory:
+ If there is at least one TCP connection, then one check will be created.
+ On agents supporting {tcp_conn_state} this should always be the case since at
+ least the connection to the agent should be shown.
+
+examples:
+ # set levels for TIME_WAIT and ESTABLISHED
+ tcp_conn_state_default_levels = { "TIME_WAIT" : (20, 50), "ESTABLISHED" : (100, 200) }
+
+[parameters]
+levels(dict from string to (int, int)): A python dictionary from check state to a pair of integers for warning and critical levels. For state types not listed in the dictionary no state check is done. The default parameter is an empty dictionary, which makes this check always OK.
+
+[configuration]
+tcp_conn_state_default_levels (dict from string to (int, int)): default levels used for all
+ inventorized checks.
diff --git a/checks/tcp_conn_stats b/checks/tcp_conn_stats
new file mode 100644
index 0000000..e745879
--- /dev/null
+++ b/checks/tcp_conn_stats
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 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.
+
+tcp_conn_states = [
+"ESTABLISHED", # connection up and passing data
+"SYN_SENT", # session has been requested by us; waiting for reply from remote endpoint
+"SYN_RECV", # session has been requested by a remote endpoint for a socket on which we were listening
+"LAST_ACK", # our socket is closed; remote endpoint has also shut down; we are waiting for a final acknowledgement
+"CLOSE_WAIT", # remote endpoint has shut down; the kernel is waiting for the application to close the socket
+"TIME_WAIT", # socket is waiting after closing for any packets left on the network
+"CLOSED", # socket is not being used (FIXME. What does mean?)
+"CLOSING", # our socket is shut down; remote endpoint is shut down; not all data has been sent
+"FIN_WAIT1", # our socket has closed; we are in the process of tearing down the connection
+"FIN_WAIT2", # the connection has been closed; our socket is waiting for the remote endpoint to shut down
+]
+
+
+tcp_conn_stats_default_levels = { }
+
+def inventory_tcp_conn_stats(checkname, info):
+ if len(info) > 0:
+ return [ (None, 'tcp_conn_stats_default_levels') ]
+
+def check_tcp_conn_stats(item, params, info):
+ stats = dict(info)
+ worst_state = 0
+ info = []
+ perfdata = []
+ for state in tcp_conn_states:
+ num = int(stats.get(state, 0))
+ if num > 0:
+ infotext = "%s: %d" % (state, num)
+ else:
+ infotext = None
+ levels = params.get(state)
+ perf = [state, num]
+ if levels:
+ warn, crit = levels
+ perf.append(warn)
+ perf.append(crit)
+ if num >= crit:
+ worst_state = 2
+ infotext += "(critical at %d!!)" % crit
+ elif num >= warn:
+ worst_state = max(1, worst_state)
+ infotext += "(warning at %d!)" % warn
+ perfdata.append(perf)
+ if infotext:
+ info.append(infotext)
+ return (worst_state, "%s - %s" % (nagios_state_names[worst_state], ", ".join(info)), perfdata)
+
+check_info['tcp_conn_stats'] = (check_tcp_conn_stats, "TCP Connections", 1, inventory_tcp_conn_stats)
diff --git a/pnp-rraconf/check_mk-tcp_conn_stats.rra.cfg b/pnp-rraconf/check_mk-tcp_conn_stats.rra.cfg
new file mode 120000
index 0000000..19dbf77
--- /dev/null
+++ b/pnp-rraconf/check_mk-tcp_conn_stats.rra.cfg
@@ -0,0 +1 @@
+max.rra.cfg
\ No newline at end of file
diff --git a/pnp-templates/check_mk-tcp_conn_stats.php b/pnp-templates/check_mk-tcp_conn_stats.php
new file mode 100644
index 0000000..71dd3c4
--- /dev/null
+++ b/pnp-templates/check_mk-tcp_conn_stats.php
@@ -0,0 +1,49 @@
+<?php
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2010 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.
+
+$opt[1] = "--vertical-label 'Number' -u 10 -X0 --title \"TCP Connection stats on $hostname\" ";
+
+$stats = array(
+ array(2, "SYN_SENT", " ", "#a00000", ""),
+ array(3, "SYN_RECV", " ", "#ff4000", ""),
+ array(1, "ESTABLISHED", "", "#00f040", ""),
+ array(6, "TIME_WAIT", " ", "#00b0b0", "\\n"),
+ array(4, "LAST_ACK", " ", "#c060ff", ""),
+ array(5, "CLOSE_WAIT", " ", "#f000f0", ""),
+ array(7, "CLOSED", " ", "#ffc000", ""),
+ array(8, "CLOSING", " ", "#ffc080", "\\n"),
+ array(9, "FIN_WAIT1", " ", "#cccccc", ""),
+ array(10, "FIN_WAIT2", " ", "#888888", "\\n")
+);
+
+$def[1] = "";
+
+foreach ($stats as $entry) {
+ list($i, $stat, $spaces, $color, $nl) = $entry;
+ $def[1] .= "DEF:$stat=$RRDFILE[$i]:$DS[$i]:MAX ";
+ $def[1] .= "AREA:$stat$color:\"$stat\":STACK ";
+ $def[1] .= "GPRINT:$stat:LAST:\"$spaces%3.0lf$nl\" ";
+}
+