#!/bin/sh # # Copyright (c) 2016 Babak Farrokhi. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # 17-Feb-2015 @farrokhi # This script extracts network memory usage counters from "netstat -m" # on FreeBSD and feeds to munin # # Magic markers: #%# family=auto #%# capabilities=autoconf suggest SCRIPT_NAME=$(basename $0) STAT_TYPE=`echo $SCRIPT_NAME | sed -n s/netmem_//p` if [ $# -lt 1 ]; then if [ "${STAT_TYPE}" == "mbufs" ]; then netstat -m | grep "mbufs in use" | sed -E -n 's/([0-9]+)\/([0-9]+)\/([0-9]+) .+/mbufs_current.value \1,mbufs_cache.value \2,mbufs_total.value \3/p' | tr ',' '\n' elif [ "${STAT_TYPE}" == "clusters" ]; then netstat -m | grep "mbuf clusters in use" | sed -E -n 's/([0-9]+)\/([0-9]+)\/([0-9]+)\/([0-9]+) .+/clusters_current.value \1,clusters_cache.value \2,clusters_total.value \3,clusters_max.value \4/p' | tr ',' '\n' elif [ "${STAT_TYPE}" == "sendfile" ]; then netstat -m | grep sendfile | sed -E -n 's/(^[0-9]+).+/sendfile.value \1/p' fi elif [ "$1" == "suggest" ]; then echo "mbufs" echo "clusters" echo "sendfile" elif [ "$1" == "autoconf" ]; then [ -x "/usr/bin/netstat" ] && echo yes || echo no exit 0 elif [ "$1" == "config" ]; then if [ "${STAT_TYPE}" == "mbufs" ]; then echo "graph_title mbufs usage" echo "graph_args --lower-limit 0 --base 1000" echo "graph_vlabel mbufs" echo "graph_category network" echo "mbufs_current.label current" echo "mbufs_current.draw AREA" echo "mbufs_cache.label cache" echo "mbufs_cache.draw STACK" echo "mbufs_total.label total" echo "mbufs_total.draw LINE2" elif [ "${STAT_TYPE}" == "clusters" ]; then echo "graph_title mbuf clusters usage" echo "graph_args --lower-limit 0 --base 1000" echo "graph_vlabel clusters" echo "graph_category network" echo "clusters_current.label current" echo "clusters_current.draw AREA" echo "clusters_cache.label cache" echo "clusters_cache.draw STACK" echo "clusters_total.label total" echo "clusters_total.draw LINE2" #echo "clusters_max.label max" #echo "clusters_max.draw LINE1" elif [ "${STAT_TYPE}" == "sendfile" ]; then echo "graph_title sendfile() calls" echo "graph_args --lower-limit 0 --base 1000" echo "graph_vlabel calls" echo "graph_period minute" echo "graph_category network" echo "sendfile.label calls" echo "sendfile.draw LINE1" echo "sendfile.type DERIVE" fi fi