#!/bin/sh
#
# Wildcard-script to monitor number of processes running as a given user.
# To monitor a user, link psu_<program> to this file. E.g.
#
#    ln -s /usr/local/libexec/munin/plugins/psu_ /etc/munin/plugins/psu_munin
#
# ...will monitor number of processes owned by 'munin'.
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
# 	suggest  (optional - used by munin-config)
#
# $Log$
# Revision 1.4  2004/09/10 23:11:13  jimmyo
# Degraded generic/psu_ from auto to manual.
#
# Revision 1.3  2004/05/20 13:57:12  jimmyo
# Set categories to some of the plugins.
#
# Revision 1.2  2004/01/29 19:39:00  jimmyo
# Generic plugins now use printf instead of echo -n, as this is more portable (SF#885564)
#
# Revision 1.1  2004/01/02 18:50:00  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.2  2003/11/07 17:43:16  jimmyo
# Cleanups and log entries
#
#
#
# Magic markers (optional):
#%# family=manual
#%# capabilities=autoconf



name=`basename $0 | sed 's/^psu_//g'`

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

if [ "$1" = "suggest" ]; then
	exit 0
fi

if [ "$1" = "config" ]; then

	echo graph_title Number of processes owned by $name
	echo 'graph_args --base 1000 --vertical-label processes -l 0'
	echo 'graph_category processes'
	echo "count.label $name"
	echo 'processes.draw LINE2'
	exit 0
fi

printf "count.value "
(pgrep -u "$name"; pgrep -U "$name") | sort -u | wc -l

