A useful munin plugin for monitoring memory usage

Garrett Wollman wollman at bimajority.org
Sat Feb 23 03:43:03 UTC 2013


We were having some memory starvation issues (which it turned out were
caused by our backup system), and I found it useful to create a munin
plugin to monitor UMA statistics (as displayed by 'vmstat -z').  As
I'm not interested in dealing with github.com, I thought I would share
it with the people most likely to benefit.  Here's an example of the
graph that gets generated:

-------------- next part --------------

(hopefully mailman will let the image through).  The plugin itself
(undoubtedly not in the best of style) follows.

-GAWollman

#!/bin/sh
#
# Plugin to monitor FreeBSD Unified Memory Allocator
# (UMA) statistics from "vmstat -z"
# Based on the nfsd (NFS server statistics) plugin.
#
#%# family=auto
#%# capabilities=autoconf

getnames () {
    /usr/bin/vmstat -z | awk -F: 'NR > 2 && NF > 1 { print $1 }'
}

if [ "$1" = "autoconf" ]; then
    if /usr/bin/vmstat -z 2>/dev/null | \
      egrep '^ITEM[[:space:]]+' >/dev/null; then
	echo yes
	exit 0
    else
	echo no
	exit 0
    fi
fi

if [ "$1" = "config" ]; then
    area='AREA'
    echo 'graph_title FreeBSD Unified Memory Allocator'
    echo 'graph_vlabel bytes'
    echo 'graph_total total'
    echo 'graph_category system'
    getnames | while read label; do
	a=$(printf "%s" "$label" | tr -C 'A-Za-z0-9_' '_')
	echo "$a.label $label"
	echo "$a.type GAUGE"
	echo "$a.min 0"
	echo "$a.draw $area"
	area='STACK'
    done
    exit 0
fi

/usr/bin/vmstat -z | awk -F '[:,] +' '
NR > 2 && NF > 1 { 
	name=$1
        gsub("[^A-Za-z0-9_]", "_", name)
	print name ".value " $2*$4
	if($3 > 0) {
		print name ".warning " int($2*$3*0.92)
		print name ".critical " int($2*$3*0.95)
	}
}
'



More information about the freebsd-stable mailing list