#!/usr/bin/perl -w
#%# family=auto
#%# capabilities=autoconf


$showruntimestats="/opt/open-xchange/sbin/showruntimestats";
$showexec="$showruntimestats -r";

if ( $ARGV[0] and $ARGV[0] eq "autoconf")
{
	if (-x $showruntimestats) {
		print "yes\n";
		exit 0;
	}
	else {
		print "no\n";
		exit 0;
	}
}

if ( $ARGV[0] and $ARGV[0] eq "config")
{
	print "graph_title Java non Heap\n";
	print "graph_args --base 1024 -l 0\n";
	print "graph_category Open Xchange\n";
	print "graph_vlabel bytes\n";
	print "a.label Code Cache\n";
	print "a.draw AREA\n";
	print "b.label Perm Gen\n";
	print "b.draw STACK\n";
	exit 0
}
									

open(SHOWRUNTIME,"$showexec |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
	if ( $_ =~ /Code Cache,type=MemoryPool,Usage /) {
		s/.*\=//; 
		s/].*//;
		$val=$_+0;
		print "a.value $val\n";
		next;
	}
	if ( $_ =~ /Perm Gen,type=MemoryPool,Usage /) {
		s/.*\=//; 
		s/].*//;
		$val=$_+0;
		print "b.value $val\n";
		next;
	}
}

close (SHOWRUNTIME);
