#!/bin/bash

# Written by Bernd Zeimetz <bernd@bzed.de>, Wed, 26 Sep 2007 03:04:34 +0200
# This script is public domain, do with it what ever you want.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#%# family=auto
#%# capabilities=autoconf

[ "$1" = "autoconf" ] && echo yes && exit 0

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

    echo 'graph_title Vserver Process Overview'
    echo 'graph_args --base 1000 -l 0 '
    echo 'graph_vlabel number of processes'
    echo 'graph_category processes'
    echo 'graph_info This graph shows the number of processes in each vserver context.'

    for vserver in `vserver-stat | sed 1d | awk '{print $8}'`; do
        echo "${vserver}.label ${vserver}"
        echo "${vserver}.draw LINE2"
        echo "${vserver}.info Processes in the vserver context ${vserver}."
    done
    exit 0
fi

vserver-stat | sed 1d | awk '{print $8" "$2}' | while read vserver procs; do
    echo "${vserver}.value ${procs}"
done
exit 0
