Start solving issue #80
This commit is contained in:
parent
60ab76b80d
commit
78680600cb
1 changed files with 63 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# mysqltuner.pl - Version 1.4.9
|
# mysqltuner.pl - Version 1.5.0
|
||||||
# High Performance MySQL Tuning Script
|
# High Performance MySQL Tuning Script
|
||||||
# Copyright (C) 2006-2015 Major Hayden - major@mhtx.net
|
# Copyright (C) 2006-2015 Major Hayden - major@mhtx.net
|
||||||
#
|
#
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
# Everett Barnes Tom Krouper Gary Barrueto
|
# Everett Barnes Tom Krouper Gary Barrueto
|
||||||
# Simon Greenaway Adam Stein Isart Montane
|
# Simon Greenaway Adam Stein Isart Montane
|
||||||
# Baptiste M. Cole Turner Major Hayden
|
# Baptiste M. Cole Turner Major Hayden
|
||||||
# Joe Ashcraft
|
# Joe Ashcraft Jean-Marie Renouard
|
||||||
#
|
#
|
||||||
# Inspired by Matthew Montgomery's tuning-primer.sh script:
|
# Inspired by Matthew Montgomery's tuning-primer.sh script:
|
||||||
# http://forge.mysql.com/projects/view.php?id=44
|
# http://forge.mysql.com/projects/view.php?id=44
|
||||||
|
@ -42,9 +42,10 @@ use File::Spec;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use Cwd 'abs_path';
|
use Cwd 'abs_path';
|
||||||
|
use Data::Dumper qw/Dumper/;
|
||||||
|
#use JSON;
|
||||||
# Set up a few variables for use in the script
|
# Set up a few variables for use in the script
|
||||||
my $tunerversion = "1.4.9";
|
my $tunerversion = "1.5.0";
|
||||||
my (@adjvars, @generalrec);
|
my (@adjvars, @generalrec);
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
|
@ -165,6 +166,9 @@ my $bad = ($opt{nocolor} == 0)? "[\e[0;31m!!\e[0m]" : "[!!]" ;
|
||||||
my $info = ($opt{nocolor} == 0)? "[\e[0;34m--\e[0m]" : "[--]" ;
|
my $info = ($opt{nocolor} == 0)? "[\e[0;34m--\e[0m]" : "[--]" ;
|
||||||
my $deb = ($opt{nocolor} == 0)? "[\e[0;31mDG\e[0m]" : "[DG]" ;
|
my $deb = ($opt{nocolor} == 0)? "[\e[0;31mDG\e[0m]" : "[DG]" ;
|
||||||
|
|
||||||
|
# Super sturucture containing all informations
|
||||||
|
my %result;
|
||||||
|
|
||||||
# Functions that handle the print styles
|
# Functions that handle the print styles
|
||||||
sub prettyprint {
|
sub prettyprint {
|
||||||
print $_[0];
|
print $_[0];
|
||||||
|
@ -297,14 +301,21 @@ sub os_setup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chomp($physical_memory);
|
chomp($physical_memory);
|
||||||
|
chomp($swap_memory);
|
||||||
|
chomp($os);
|
||||||
|
$result{'OS'}{'OS Type'}=$os;
|
||||||
|
$result{'OS'}{'Physical Memory'}{'bytes'}=$physical_memory;
|
||||||
|
$result{'OS'}{'Physical Memory'}{'pretty'}=hr_bytes($physical_memory);
|
||||||
|
$result{'OS'}{'Swap Memory'}{'bytes'}=$swap_memory;
|
||||||
|
$result{'OS'}{'Swap Memory'}{'pretty'}=hr_bytes($swap_memory);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks to see if a MySQL login is possible
|
# Checks to see if a MySQL login is possible
|
||||||
my ($mysqllogin,$doremote,$remotestring,$mysqlcmd);
|
my ($mysqllogin,$doremote,$remotestring,$mysqlcmd,$mysqladmincmd);
|
||||||
sub mysql_setup {
|
sub mysql_setup {
|
||||||
$doremote = 0;
|
$doremote = 0;
|
||||||
$remotestring = '';
|
$remotestring = '';
|
||||||
my $mysqladmincmd;
|
|
||||||
if ($opt{mysqladmin}) {
|
if ($opt{mysqladmin}) {
|
||||||
$mysqladmincmd = $opt{mysqladmin};
|
$mysqladmincmd = $opt{mysqladmin};
|
||||||
} else {
|
} else {
|
||||||
|
@ -318,7 +329,6 @@ sub mysql_setup {
|
||||||
badprint "Couldn't find mysqladmin in your \$PATH. Is MySQL installed?\n";
|
badprint "Couldn't find mysqladmin in your \$PATH. Is MySQL installed?\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($opt{mysqlcmd}) {
|
if ($opt{mysqlcmd}) {
|
||||||
$mysqlcmd = $opt{mysqlcmd};
|
$mysqlcmd = $opt{mysqlcmd};
|
||||||
} else {
|
} else {
|
||||||
|
@ -484,24 +494,43 @@ sub select_one {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_tuning_info {
|
||||||
|
my @infoconn = select_array "\\s";
|
||||||
|
@infoconn = grep {!/Threads:/ and !/Connection id:/ and !/pager:/ and !/Using/ } @infoconn;
|
||||||
|
foreach my $line (@infoconn) {
|
||||||
|
if ($line =~ /\s*(.*):\s*(.*)/) {
|
||||||
|
debugprint "$1 => $2\n";
|
||||||
|
chomp($1);
|
||||||
|
chomp($2);
|
||||||
|
$result{'MySQL Client'}{$1} = $2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result{'MySQL Client'}{'Client Path'}=$mysqlcmd;
|
||||||
|
$result{'MySQL Client'}{'Admin Path'}=$mysqladmincmd;
|
||||||
|
$result{'MySQL Client'}{'Authentication Info'}=$mysqllogin;
|
||||||
|
|
||||||
|
}
|
||||||
# Populates all of the variable and status hashes
|
# Populates all of the variable and status hashes
|
||||||
my (%mystat,%myvar,$dummyselect,%myrepl, %myslaves);
|
my (%mystat,%myvar,$dummyselect,%myrepl, %myslaves);
|
||||||
sub get_all_vars {
|
sub get_all_vars {
|
||||||
# We need to initiate at least one query so that our data is useable
|
# We need to initiate at least one query so that our data is useable
|
||||||
$dummyselect = select_one "SELECT VERSION()";
|
$dummyselect = select_one "SELECT VERSION()";
|
||||||
debugprint "VERSION: ".$dummyselect."\n";
|
debugprint "VERSION: ".$dummyselect."\n";
|
||||||
|
$result{'MySQL Client'}{'Version'}=$dummyselect;
|
||||||
my @mysqlvarlist = select_array "SHOW /*!50000 GLOBAL */ VARIABLES";
|
my @mysqlvarlist = select_array "SHOW /*!50000 GLOBAL */ VARIABLES";
|
||||||
foreach my $line (@mysqlvarlist) {
|
foreach my $line (@mysqlvarlist) {
|
||||||
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
||||||
$myvar{$1} = $2;
|
$myvar{$1} = $2;
|
||||||
debugprint "$1 = $2\n";
|
$result{'Variables'}{$1}=$2;
|
||||||
|
debugprint "V: $1 = $2\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my @mysqlstatlist = select_array "SHOW /*!50000 GLOBAL */ STATUS";
|
my @mysqlstatlist = select_array "SHOW /*!50000 GLOBAL */ STATUS";
|
||||||
foreach my $line (@mysqlstatlist) {
|
foreach my $line (@mysqlstatlist) {
|
||||||
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
$line =~ /([a-zA-Z_]*)\s*(.*)/;
|
||||||
$mystat{$1} = $2;
|
$mystat{$1} = $2;
|
||||||
|
$result{'Status'}{$1}=$2;
|
||||||
|
debugprint "S: $1 = $2\n";
|
||||||
}
|
}
|
||||||
# Workaround for MySQL bug #59393 wrt. ignore-builtin-innodb
|
# Workaround for MySQL bug #59393 wrt. ignore-builtin-innodb
|
||||||
if (($myvar{'ignore_builtin_innodb'} || "") eq "ON") {
|
if (($myvar{'ignore_builtin_innodb'} || "") eq "ON") {
|
||||||
|
@ -514,6 +543,7 @@ sub get_all_vars {
|
||||||
foreach my $line (@mysqlenginelist) {
|
foreach my $line (@mysqlenginelist) {
|
||||||
if ($line =~ /^([a-zA-Z_]+)\s+(\S+)/) {
|
if ($line =~ /^([a-zA-Z_]+)\s+(\S+)/) {
|
||||||
my $engine = lc($1);
|
my $engine = lc($1);
|
||||||
|
|
||||||
if ($engine eq "federated" || $engine eq "blackhole") {
|
if ($engine eq "federated" || $engine eq "blackhole") {
|
||||||
$engine .= "_engine";
|
$engine .= "_engine";
|
||||||
} elsif ($engine eq "berkeleydb") {
|
} elsif ($engine eq "berkeleydb") {
|
||||||
|
@ -521,6 +551,7 @@ sub get_all_vars {
|
||||||
}
|
}
|
||||||
my $val = ($2 eq "DEFAULT") ? "YES" : $2;
|
my $val = ($2 eq "DEFAULT") ? "YES" : $2;
|
||||||
$myvar{"have_$engine"} = $val;
|
$myvar{"have_$engine"} = $val;
|
||||||
|
$result{'Storage Engines'}{$engine}=$2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,6 +561,7 @@ sub get_all_vars {
|
||||||
if ($line =~ /\s*(.*):\s*(.*)/) {
|
if ($line =~ /\s*(.*):\s*(.*)/) {
|
||||||
debugprint "$1 => $2\n";
|
debugprint "$1 => $2\n";
|
||||||
$myrepl{"$1"} = $2;
|
$myrepl{"$1"} = $2;
|
||||||
|
$result{'Replication'}{'Status'}{$1}=$2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#print Dumper(%myrepl);
|
#print Dumper(%myrepl);
|
||||||
|
@ -538,8 +570,9 @@ sub get_all_vars {
|
||||||
my @lineitems=();
|
my @lineitems=();
|
||||||
foreach my $line (@mysqlslaves) {
|
foreach my $line (@mysqlslaves) {
|
||||||
debugprint "L: $line \n";
|
debugprint "L: $line \n";
|
||||||
@lineitems=split /\s*/, $line;
|
@lineitems=split /\s+/, $line;
|
||||||
$myslaves{$lineitems[0]}=$line;
|
$myslaves{$lineitems[0]}=$line;
|
||||||
|
$result{'Replication'}{'Slaves'}{$lineitems[0]}=$lineitems[4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1575,15 +1608,26 @@ sub make_recommendations {
|
||||||
sub close_reportfile {
|
sub close_reportfile {
|
||||||
close($fh) if defined($fh);
|
close($fh) if defined($fh);
|
||||||
}
|
}
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# BEGIN 'MAIN'
|
sub headerprint {
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
prettyprint " >> MySQLTuner $tunerversion - Major Hayden <major\@mhtx.net>\n".
|
prettyprint " >> MySQLTuner $tunerversion - Major Hayden <major\@mhtx.net>\n".
|
||||||
" >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
|
" >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
|
||||||
" >> Run with '--help' for additional options and output filtering\n";
|
" >> Run with '--help' for additional options and output filtering\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub dump_result {
|
||||||
|
$Data::Dumper::Pair = " : ";
|
||||||
|
print Dumper(\%result);
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# BEGIN 'MAIN'
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
headerprint # Header Print
|
||||||
mysql_setup; # Gotta login first
|
mysql_setup; # Gotta login first
|
||||||
os_setup; # Set up some OS variables
|
os_setup; # Set up some OS variables
|
||||||
get_all_vars; # Toss variables/status into hashes
|
get_all_vars; # Toss variables/status into hashes
|
||||||
|
get_tuning_info; # Get information about the tuning connexion
|
||||||
validate_mysql_version; # Check current MySQL version
|
validate_mysql_version; # Check current MySQL version
|
||||||
check_architecture; # Suggest 64-bit upgrade
|
check_architecture; # Suggest 64-bit upgrade
|
||||||
check_storage_engines; # Show enabled storage engines
|
check_storage_engines; # Show enabled storage engines
|
||||||
|
@ -1608,7 +1652,7 @@ __END__
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
MySQLTuner 1.4.9 - MySQL High Performance Tuning Script
|
MySQLTuner 1.5.0 - MySQL High Performance Tuning Script
|
||||||
|
|
||||||
=head1 IMPORTANT USAGE GUIDELINES
|
=head1 IMPORTANT USAGE GUIDELINES
|
||||||
|
|
||||||
|
@ -1787,6 +1831,10 @@ Major Hayden
|
||||||
|
|
||||||
Joe Ashcraft
|
Joe Ashcraft
|
||||||
|
|
||||||
|
=item *
|
||||||
|
|
||||||
|
Jean-Marie Renouard
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 SUPPORT
|
=head1 SUPPORT
|
||||||
|
|
Loading…
Reference in a new issue