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

$showexec="/opt/open-xchange/sbin/showruntimestats";
$showruntimestats="$showexec -d com.openexchange.caching:name=JCSCacheInformation!getMemoryCacheCount!";

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

if ( $ARGV[0] and $ARGV[0] eq "config")
{
	print "graph_title Cache objects\n";
	print "graph_args --base 1000 -l 0\n";
	print "graph_category Open Xchange\n";
	print "graph_vlabel Number of objects in caches\n";
	print "a.label Context\n";
	print "a.draw LINE1\n";
    print "b.label Filestore\n";
    print "b.draw LINE1\n";
    print "c.label DBPool\n";
    print "c.draw LINE1\n";
    print "d.label User\n";
    print "d.draw LINE1\n";
    print "e.label UserConfiguration\n";
    print "e.draw LINE1\n";
    print "f.label UserSettingMail\n";
    print "f.draw LINE1\n";
    print "g.label OXFolder\n";
    print "g.draw LINE1\n";
    print "h.label OXFolderQuery\n";
    print "h.draw LINE1\n";
    print "i.label IMAP Connection\n";
    print "i.draw LINE1\n";
    print "j.label Message\n";
    print "j.draw LINE1\n";
    print "k.label Mail Message\n";
    print "k.draw LINE1\n";
    print "l.label Mail Connection\n";
    print "l.draw LINE1\n";
    print "m.label Calendar\n";
    print "m.draw LINE1\n";
    print "n.label Session\n";
    print "n.draw LINE1\n";
	exit 0
}
									

open(SHOWRUNTIME,"${showruntimestats}Context | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
	if ( $_ =~ /[0-9]*/) {
		$val=$_+0;
		print "a.value $val\n";
		next;
	}
}

open(SHOWRUNTIME,"${showruntimestats}Filestore | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "b.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}OXDBPoolCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "c.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}User | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "d.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}UserConfiguration | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "e.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}UserSettingMail | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "f.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}OXFolderCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "g.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}OXFolderQueryCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "h.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}OXIMAPConCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "i.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}OXMessageCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "j.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}MailMessageCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "k.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}MailConnectionCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "l.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}CalendarCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "m.value $val\n";
        next;
    }
}

open(SHOWRUNTIME,"${showruntimestats}SessionCache | head -1 |") || die "can not read monitoring output";   

while (<SHOWRUNTIME>)
{
    if ( $_ =~ /[0-9]*/) {
        $val=$_+0;
        print "n.value $val\n";
        next;
    }
}
