Repository
Munin (master)
Last change
2018-10-10
Graph Categories
Family
contrib
Capabilities
Keywords
Language
Bash

netstat_rate_tcp_

Sadly there is no documentation for this plugin.

#!/usr/local/bin/bash
#
# netstat_rate_tcp_ - Munin wildcard plug-in to parse netstat TCP counters
#
# Contributed by <ralph dot grothe at itdz minus berlin dot de>
#
#%# family=contrib
#%# capabilities=autoconf suggest

proto=$(basename "$0" | cut -d_ -f3)
type=${0##*_}

if [[ $1 = autoconf ]]; then
    if uname -s|grep -qEi "hp-?ux"; then
	echo yes
	exit 0
    else
	echo "no (This plugin only parses output of HP-UX netstat command)"
	exit 0
    fi
fi
[[ $1 = suggest ]] && printf 'socket\nthroughput\n' && exit 0

set -A SOCKET_LABELS requests accepts established closed

if [[ $1 = config ]]; then
    echo "graph_title netstat $proto $type rate"
    echo "graph_category network"
    echo "graph_args --base 1000"
    case $type in
	socket)
	    echo "graph_vlabel connections per \${graph_period}"
	    for tag in ${SOCKET_LABELS[*]}; do
                printf '%s.label %s\n' "$tag" "$tag"
                printf '%s.type COUNTER\n' "$tag"
	    done
	    ;;
	throughput)
	    echo "graph_vlabel packets per \${graph_period}"
	    echo "ingress.label packets received"
	    echo "ingress.type COUNTER"
	    echo "ingress.graph no"
	    echo "egress.label packets sent"
	    echo "egress.type COUNTER"
	    echo "egress.negative ingress"
	    ;;
    esac
    exit 0
fi

case $type in
    socket)
	typeset -i i=-1
	netstat -s -p tcp \
	    |awk '/connections? (requests|accepts|established|closed)/{print$1}' \
                | while read -r count; do
                    printf '%s.value %s\n' "${SOCKET_LABELS[((i+=1))]}" "$count"
    		done
	;;
    throughput)
	# shellcheck disable=SC2046
	set -- $(netstat -s -p tcp|awk '/packets (sent|received)$/{print$1}')
	echo "ingress.value $2"
	echo "egress.value $1"
	;;
esac