#!/bin/sh
# -*- sh -*-
# vim: ft=sh

: << =cut

=head1 NAME

contentserv - Plugin to monitor the speed of Contentserv

=head1 CONFIGURATION

No configuration

=head1 AUTHOR

Thomas Antepoth

=head1 LICENSE

GNU GPL

=head1 MAGIC MARKERS

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

=cut

CSPATH=/daten/www/htdocs/CONTENTSERV/admin

if [ "$1" = "autoconf" ]; then
	[ -d $CSPATH ] && echo "yes" || echo "no"
	exit 0
fi

if [ "$1" = "config" ]; then
    echo 'graph_title Time for one Contentserv PHP roundtrip'
    echo 'graph_vlabel CS Roundtrip time'
    echo 'graph_category apache'
    echo 'graph_info This graph shows the php roundtrip time in Contentserv.'
    echo 'contentserv.label ms'
    echo 'contentserv.info The current roundtrip time.'
    exit 0
fi

# -s suppresses errors about files that vanished before they could
# be read.  It isn't entirely portable, but GNU grep should be a given on
# Linux.  Sadly awk has no such equivalent option or we could skip grep
# altogether
# grep -s '^Threads' /proc/[0-9]*/status | awk '{ sum += $2; } END { print "threads.value", sum; }'

cd $CSPATH && (
	wget -q http://localhost/admin/ping.php -O - | sed 's/\,/\./g' | awk '{ print "contentserv.value", $1 ;}'
	# su -s /bin/bash apache -c 'php ping.php | awk "{ print \"contentserv.value\", \$1 ;}" '
	# php ping.php | awk '{ print "contentserv.value", $1 ;}'
)
