Created
December 5, 2011 16:34
-
-
Save gamefiend/1434208 to your computer and use it in GitHub Desktop.
MySQL Statistic Comparison Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mysql Comparison | |
# Compare two (or three) values pulled from a mysql show status command. | |
# compare (value 1)/(value 2) or (value 1)/(value 2+ value 3) | |
# represented by default as a percentage. | |
# representation coudl be tweaked however. | |
# also, you might need to tweak mysql commands to use username and password. | |
#!/usr/bin/perl -w | |
use strict; | |
use Getopt::Long; | |
my ($host, $data1, $data2,$data3); | |
my $params = GetOptions('host=s' => \$host, | |
'data1=s' => \$data1, | |
'data2=s' => \$data2, | |
'data3=s' => \$data3 | |
); | |
die "Missing parameters:\n\nNeed host and data1 and data2 fields\n" unless ($host && $data1 && $data2); | |
my $twi_cmd=`mysql --host $host -e \"show status;\" | grep $data1 | cut -f2`; | |
my $tli_cmd=`mysql --host $host -e \"show status;\" | grep $data2 | cut -f2`; | |
my $third; | |
if ($data3){ | |
$third=`mysql --host $host -e \"show status;\" | grep $data3 | cut -f2`; | |
chomp($third); | |
} | |
chomp($twi_cmd); | |
chomp($tli_cmd); | |
if ($data3){ | |
$tli_cmd+=$third; | |
} | |
my $percent = int(($twi_cmd/$tli_cmd) * 100); | |
print "$percent \n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment