use strict; use warnings; use Getopt::Long; use DBI; # -- # Print out the usage message # -- sub usage { print " MySQL Health Check Script\n"; print " Maintained By DataVail.com\n"; print " Important Usage Guidelines\n"; print " perl MysqlHC.pl -H -u -p -role \n"; print " --role \n"; print " Optional parameters:\n"; print " --port \n"; } $|=1; # -- # Parse arguments and read Configuration # -- my ($host, $user, $password, $port, $role, $help); GetOptions ( 'host=s' => \$host, 'H=s' => \$host, 'user=s' => \$user, 'u=s' => \$user, 'password=s' => \$password, 'p:s' => \$password, 'port=i' => \$port, 'role=s' => \$role, 'help' => \$help, ); if (!$host || !$user || !$role || !$help eq '') { usage(); exit(1); } if (!$port) { $port = 3306; } sub var { my $statement; if ($MySQLVersion =~ /^3.*|^4.*/ ) { $statement = 'show variables'; } elsif ($MySQLVersion =~ /^5\.0.*/ ) { $statement = 'show global variables'; } elsif ($MySQLVersion =~ /^5\.[1-9].*|^6.*/ ) { $statement = 'Select * from information_schema.global_variables order by 1'; }; # print $statement,"\n"; my $sth = $dbh->prepare($statement); $sth->execute(); while (my ($keyword, $value) = $sth->fetchrow_array()) { # print $keyword,"=",$value,"\n"; $variables{lc($keyword)}=lc($value); } $sth->finish(); } sub stat { my $statement; if ($MySQLVersion =~ /^3.*|^4.*/ ) { $statement = 'show status'; } elsif ($MySQLVersion =~ /^5\.0.*/ ) { $statement = 'show global status'; } elsif ($MySQLVersion =~ /^5\.[1-9].*|^6.*/ ) { $statement = 'Select * from information_schema.global_status order by 1'; }; # print $statement,"\n"; my $sth = $dbh->prepare($statement); $sth->execute(); while (my ($keyword, $value) = $sth->fetchrow_array()) { # print $keyword,"=",$value,"\n"; $status{lc($keyword)}=lc($value); } $sth->finish(); } system_memory=`cat /proc/meminfo |grep -w MemTotal |awk '{print $2}'` total_system_memory=$(echo "$system_memory * 1024" | bc -l)