Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Feb 2013 22:42:56 -0500
From:      Garrett Wollman <wollman@bimajority.org>
To:        stable@freebsd.org
Cc:        lupe@lupe-christoph.de
Subject:   A useful munin plugin for monitoring memory usage
Message-ID:  <20776.15040.300235.897884@hergotha.csail.mit.edu>

next in thread | raw e-mail | index | archive | help

--2gmmaHoB6p
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit

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:


--2gmmaHoB6p
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit


(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)
	}
}
'


--2gmmaHoB6p--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20776.15040.300235.897884>