#!/bin/sh # # Plugin to monitor CPU usage, for a selected set of users # # Usage: Place in /etc/munin/node.d/ (or link it there using ln -s) # Add this to your /etc/munin/plugin-conf.d/munin-node: # [cpubyuser] # env.USERS root yann # # root and yann being a list of the users to monitor. # You need to also make sure that awk is installed # # Parameters understood: # # config (required) # autoconf (optional - used by munin-config) # #%# family=auto #%# capabilities=autoconf if [ "$1" = "autoconf" ] ; then if [ -n "$USERS" ] ; then echo "yes" else echo "\$USERS not defined." fi exit fi if [ "$1" = "config" ] ; then echo "graph_args --base 1000 -r --lower-limit 0"; echo "graph_title CPU usage, by user"; echo "graph_category system"; echo "graph_info This graph shows CPU usage, for monitored users."; echo 'graph_vlabel %' echo 'graph_scale no' echo 'graph_period second' echo "graph_order $USERS" FIRSTUSER=1; for USER in $USERS; do echo "${USER}.label $USER" echo "${USER}.info CPU used by user $USER" echo "${USER}.type GAUGE" if [ $FIRSTUSER -eq 1 ] ; then echo "${USER}.draw AREA" export FIRSTUSER=0; else echo "${USER}.draw STACK" fi done ; exit fi for USER in $USERS ; do { ps -u $USER -o "%C" | awk ' BEGIN { FS=" " CPU_USER=0 } { CPU_USER+=$0 } END { print "'$USER'.value "CPU_USER }' } done;