Skip to content

Instantly share code, notes, and snippets.

@yyuu
Created July 22, 2011 08:44
Show Gist options
  • Save yyuu/1099104 to your computer and use it in GitHub Desktop.
Save yyuu/1099104 to your computer and use it in GitHub Desktop.
tcp6? connection monitor for munin
#!/bin/sh
case $1 in
config)
cat <<EOF
graph_title Connections through firewall
graph_vlabel Connections
graph_category network
graph_args -l 0
established.label ESTABLISHED
established.type GAUGE
established.draw AREA
syn_sent.label SYN_SENT
syn_sent.type GAUGE
syn_sent.draw STACK
syn_recv.label SYN_RECV
syn_recv.type GAUGE
syn_recv.draw STACK
fin_wait1.label FIN_WAIT1
fin_wait1.type GAUGE
fin_wait1.draw STACK
fin_wait2.label FIN_WAIT2
fin_wait2.type GAUGE
fin_wait2.draw STACK
time_wait.label TIME_WAIT
time_wait.type GAUGE
time_wait.draw STACK
close.label CLOSE
close.type GAUGE
close.draw STACK
close_wait.label CLOSE_WAIT
close_wait.type GAUGE
close_wait.draw STACK
last_ack.label LAST_ACK
last_ack.type GAUGE
last_ack.draw STACK
listen.label LISTEN
listen.type GAUGE
listen.draw STACK
closing.label CLOSING
closing.type GAUGE
closing.draw STACK
EOF
exit 0
;;
autoconf)
echo yes
exit 0
esac
PROCNET_TCP=/proc/net/tcp
PROCNET_TCP6=/proc/net/tcp6
cat $PROCNET_TCP $PROCNET_TCP6 | awk -v st=4 '
function get(dic, key, default_val) { return dic[key] ? dic[key] : default_val; }
function set(dic, key, val) { return dic[key] = val; }
function inc(dic, key) { return dic[key] ? ++dic[key] : (dic[key]=1); }
$1 ~ /^[0-9]+:$/ {
inc(STATE, $st);
}
END {
print("established.value " get(STATE, "01", 0));
print("syn_sent.value " get(STATE, "02", 0));
print("syn_recv.value " get(STATE, "03", 0));
print("fin_wait1.value " get(STATE, "04", 0));
print("fin_wait2.value " get(STATE, "05", 0));
print("time_wait.value " get(STATE, "06", 0));
print("close.value " get(STATE, "07", 0));
print("close_wait.value " get(STATE, "08", 0));
print("last_ack.value " get(STATE, "09", 0));
print("listen.value " get(STATE, "0A", 0));
print("closing.value " get(STATE, "0B", 0));
}
'
# vim:set ft=sh :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment