#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
my $variable = basename $0;
$variable =~ s/^mysql_status_//;
$variable or die "no variable";
if ($ARGV[0] && $ARGV[0] eq 'config') {
print <<END;
graph_title MySQL $variable
graph_vlabel $variable
$variable.label $variable
END
exit;
}
open(MYSQL, '/usr/bin/mysqladmin extended-status |') or die $!;
while (<MYSQL>) {
my (undef, $name, undef, $value) = split;
if ($name && $value && lc $name eq $variable) {
printf("%s.value %d\n", $variable, $value);
exit;
}
}