From e9bda2bab695692872fee7553ccf068df3a04703 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 15 Oct 2014 17:11:35 -0400 Subject: [PATCH 1/2] Fix issue when seconds is greater than two digits. Also only use one query rather than a loop. --- plugins/mysql/mysql_slave | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/plugins/mysql/mysql_slave b/plugins/mysql/mysql_slave index 896f5800..b94d4581 100755 --- a/plugins/mysql/mysql_slave +++ b/plugins/mysql/mysql_slave @@ -45,9 +45,7 @@ use strict; my $MYSQLADMIN = $ENV{mysqladmin} || "mysql"; my $MYSQLOPTS = $ENV{mysqlopts} || ""; - -my %WANTED = ( "Seconds" => "seconds", - ); +my $COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status\\G' | grep 'Seconds_Behind_Master'"; my $arg = shift(); @@ -66,37 +64,10 @@ if ($arg eq 'config') { my $seconds = 0; my (@infos,$info,$i_seconds); -my $COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status;' | grep 'Slave'"; +my $info = `$COMMAND`; +$info =~ /: (\d+)/; -open(SERVICE, "$COMMAND |") - or die("Coult not execute '$COMMAND': $!"); - -while () { - (@infos) = split; -} -close(SERVICE); - -my $i = 0; -foreach $info (@infos) { - $i++; - if ($info eq 'Seconds_Behind_Master') { - $i_seconds = $i; - next; - } -} - -$COMMAND = "$MYSQLADMIN $MYSQLOPTS -e 'show slave status;' | cut -f $i_seconds | grep -v leng"; - -open(SERVICE, "$COMMAND |") - or die("Coult not execute '$COMMAND': $!"); - -while () { - (m/(\d+).*?(\d+(?:\.\d+)?)/); - $seconds += $1; -} -close(SERVICE); - -print("seconds.value $seconds\n"); +print("seconds.value $1\n"); sub print_config { From 868937c848ee6e761aa46b186ddd355e7c62f16e Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Thu, 16 Oct 2014 14:34:50 -0400 Subject: [PATCH 2/2] Report properly when value is undefined (slave error). --- plugins/mysql/mysql_slave | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/mysql/mysql_slave b/plugins/mysql/mysql_slave index b94d4581..5541a44a 100755 --- a/plugins/mysql/mysql_slave +++ b/plugins/mysql/mysql_slave @@ -65,9 +65,11 @@ my $seconds = 0; my (@infos,$info,$i_seconds); my $info = `$COMMAND`; -$info =~ /: (\d+)/; - -print("seconds.value $1\n"); +if($info =~ /: (\d+)/) { + print("seconds.value $1\n"); +} else { + print("seconds.value U\n"); +} sub print_config {