diff --git a/lib/Core/MysqlStatus.pm b/lib/Core/MysqlStatus.pm index 2d539e9..ba25d1a 100644 --- a/lib/Core/MysqlStatus.pm +++ b/lib/Core/MysqlStatus.pm @@ -62,33 +62,51 @@ connecting as REPLICATION CLIENT privileges. =cut sub handler { - my $self = shift; - my $config = $self->{'config'}; - my $target = $self->{'check_name'}; - my $port = $config->{'port'} || 3306; - my $user = $config->{'user'}; - my $pass = $config->{'pass'}; - my $dbh = DBI->connect("DBI:mysql::$target;port=$port", $user, $pass); - - my $select_query = "SHOW /*!50002 GLOBAL */ STATUS"; - my $sth = $dbh->prepare($select_query); - $sth->execute(); - - my %metrics; - while (my $result = $sth->fetchrow_hashref) { - $metrics{$result->{'Variable_name'}} = $result->{'Value'}; + my $self = shift; + my $config = $self->{'config'}; + my $target = $self->{'check_name'}; + my $port = $config->{'port'} || 3306; + my $user = $config->{'user'}; + my $pass = $config->{'pass'}; + my $dbh = DBI->connect("DBI:mysql::$target;port=$port", $user, $pass); + + my $select_query = "SHOW /*!50002 GLOBAL */ STATUS"; + my $sth = $dbh->prepare($select_query); + $sth->execute(); + + my %metrics; + while (my $result = $sth->fetchrow_hashref) { + my $type; + # Skip blank values + next if $result->{'Value'} eq ''; + if ( $result->{'Value'} =~ /^[0-9]+/ ) { + $type = "L"; + } elsif ( $result->{'Value'} =~ /^[a-z]+/i ) { # TODO: improve the regex? + $type = "s"; } - my $slave_query = "SHOW SLAVE STATUS"; - my $s_sth = $dbh->prepare($slave_query); - $s_sth->execute(); - while (my $s_result = $s_sth->fetchrow_hashref) { - foreach my $field ( keys %{ $s_result } ) { - $metrics{$field} = $s_result->{$field}; + $metrics{$result->{'Variable_name'}} = [ $result->{'Value'}, $type ]; + } + + my $slave_query = "SHOW SLAVE STATUS"; + my $s_sth = $dbh->prepare($slave_query); + $s_sth->execute(); + while (my $s_result = $s_sth->fetchrow_hashref) { + foreach my $field ( keys %{ $s_result } ) { + next if $s_result->{$field} eq ''; + my $s_type; + if ( $s_result->{$field} =~ /^[0-9]+/ ) { + $s_type = "L"; + } elsif ( $s_result->{$field} =~ /^[a-z]+/i ) { + $s_type = "s"; } + + $metrics{$field} = [ $s_result->{$field}, $s_type ]; } + } + - return \%metrics; + return \%metrics; }; 1;