This is a wildcard plugin that takes the name of a MySQL slave status variable, and plots it.
The MySQL manual says what the variables mean.
To use it, append the name of a slave status variable -- "mv mysql_slave_status_ mysql_slave_status_seconds_behind_master".
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
my $variable = basename $0;
$variable =~ s/^mysql_slave_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/mysql --batch -e "show slave status" |') or die $!;
chomp (my $keys = lc <MYSQL>);
my @keys = split /\t/, $keys;
chomp (my $values = <MYSQL>);
my @values = split /\t/, $values;
my %hash;
@hash{@keys} = @values;
if (defined $hash{$variable}) {
printf("%s.value %d\n", $variable, $hash{$variable});
}
