fix for perl 5.10 and 5.8
This commit is contained in:
parent
2d4afc2e82
commit
5faf456d77
1 changed files with 172 additions and 262 deletions
126
mysqltuner.pl
126
mysqltuner.pl
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# mysqltuner.pl - Version 1.6.9
|
# mysqltuner.pl - Version 1.6.8
|
||||||
# High Performance MySQL Tuning Script
|
# High Performance MySQL Tuning Script
|
||||||
# Copyright (C) 2006-2016 Major Hayden - major@mhtx.net
|
# Copyright (C) 2006-2015 Major Hayden - major@mhtx.net
|
||||||
#
|
#
|
||||||
# For the latest updates, please visit http://mysqltuner.com/
|
# For the latest updates, please visit http://mysqltuner.com/
|
||||||
# Git repository available at http://github.com/major/MySQLTuner-perl
|
# Git repository available at http://github.com/major/MySQLTuner-perl
|
||||||
|
@ -51,7 +51,7 @@ use Data::Dumper;
|
||||||
$Data::Dumper::Pair = " : ";
|
$Data::Dumper::Pair = " : ";
|
||||||
|
|
||||||
# Set up a few variables for use in the script
|
# Set up a few variables for use in the script
|
||||||
my $tunerversion = "1.6.9";
|
my $tunerversion = "1.6.8";
|
||||||
my ( @adjvars, @generalrec );
|
my ( @adjvars, @generalrec );
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
|
@ -71,7 +71,6 @@ my %opt = (
|
||||||
"pass" => 0,
|
"pass" => 0,
|
||||||
"skipsize" => 0,
|
"skipsize" => 0,
|
||||||
"checkversion" => 0,
|
"checkversion" => 0,
|
||||||
"updateversion" => 0,
|
|
||||||
"buffers" => 0,
|
"buffers" => 0,
|
||||||
"passwordfile" => 0,
|
"passwordfile" => 0,
|
||||||
"bannedports" => '',
|
"bannedports" => '',
|
||||||
|
@ -83,29 +82,21 @@ my %opt = (
|
||||||
"noask" => 0,
|
"noask" => 0,
|
||||||
"template" => 0,
|
"template" => 0,
|
||||||
"json" => 0,
|
"json" => 0,
|
||||||
"prettyjson" => 0,
|
"reportfile" => 0
|
||||||
"reportfile" => 0,
|
|
||||||
"verbose" => 0
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# Gather the options from the command line
|
# Gather the options from the command line
|
||||||
my $getOptionsCheck = GetOptions(
|
GetOptions(
|
||||||
\%opt, 'nobad', 'nogood', 'noinfo',
|
\%opt, 'nobad', 'nogood', 'noinfo',
|
||||||
'debug', 'nocolor', 'forcemem=i', 'forceswap=i',
|
'debug', 'nocolor', 'forcemem=i', 'forceswap=i',
|
||||||
'host=s', 'socket=s', 'port=i', 'user=s',
|
'host=s', 'socket=s', 'port=i', 'user=s',
|
||||||
'pass=s', 'skipsize', 'checkversion', 'mysqladmin=s',
|
'pass=s', 'skipsize', 'checkversion', 'mysqladmin=s',
|
||||||
'mysqlcmd=s', 'help', 'buffers', 'skippassword',
|
'mysqlcmd=s', 'help', 'buffers', 'skippassword',
|
||||||
'passwordfile=s', 'outputfile=s', 'silent', 'dbstat',
|
'passwordfile=s', 'outputfile=s', 'silent', 'dbstat', 'json',
|
||||||
'json', 'prettyjson', 'idxstat', 'noask',
|
'idxstat', 'noask', 'template=s', 'reportfile=s', 'cvefile=s',
|
||||||
'template=s', 'reportfile=s', 'cvefile=s', 'bannedports=s',
|
'bannedports=s','maxportallowed=s',
|
||||||
'updateversion', 'maxportallowed=s', 'verbose'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#If params are incorrect return help
|
|
||||||
if ($getOptionsCheck ne 1) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( defined $opt{'help'} && $opt{'help'} == 1 ) { usage(); }
|
if ( defined $opt{'help'} && $opt{'help'} == 1 ) { usage(); }
|
||||||
|
|
||||||
sub usage {
|
sub usage {
|
||||||
|
@ -135,7 +126,6 @@ sub usage {
|
||||||
. " (Recommended for servers with many tables)\n"
|
. " (Recommended for servers with many tables)\n"
|
||||||
. " --skippassword Don't perform checks on user passwords(default: off)\n"
|
. " --skippassword Don't perform checks on user passwords(default: off)\n"
|
||||||
. " --checkversion Check for updates to MySQLTuner (default: don't check)\n"
|
. " --checkversion Check for updates to MySQLTuner (default: don't check)\n"
|
||||||
. " --updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)\n"
|
|
||||||
. " --forcemem <size> Amount of RAM installed in megabytes\n"
|
. " --forcemem <size> Amount of RAM installed in megabytes\n"
|
||||||
. " --forceswap <size> Amount of swap memory configured in megabytes\n"
|
. " --forceswap <size> Amount of swap memory configured in megabytes\n"
|
||||||
. " --passwordfile <path>Path to a password file list(one password by line)\n"
|
. " --passwordfile <path>Path to a password file list(one password by line)\n"
|
||||||
|
@ -152,12 +142,10 @@ sub usage {
|
||||||
. " --cvefile CVE File for vulnerability checks\n"
|
. " --cvefile CVE File for vulnerability checks\n"
|
||||||
. " --nocolor Don't print output in color\n"
|
. " --nocolor Don't print output in color\n"
|
||||||
. " --json Print result as JSON string\n"
|
. " --json Print result as JSON string\n"
|
||||||
. " --prettyjson Print result as human readable JSON\n"
|
|
||||||
. " --buffers Print global and per-thread buffer values\n"
|
. " --buffers Print global and per-thread buffer values\n"
|
||||||
. " --outputfile <path> Path to a output txt file\n" . "\n"
|
. " --outputfile <path> Path to a output txt file\n" . "\n"
|
||||||
. " --reportfile <path> Path to a report txt file\n" . "\n"
|
. " --reportfile <path> Path to a report txt file\n" . "\n"
|
||||||
. " --template <path> Path to a template file\n" . "\n"
|
. " --template <path> Path to a template file\n" . "\n";
|
||||||
. " --verbose Prints out all options (default: no verbose) \n" . "\n";
|
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,15 +159,6 @@ my $basic_password_files =
|
||||||
$basic_password_files = "/usr/share/mysqltuner/basic_passwords.txt"
|
$basic_password_files = "/usr/share/mysqltuner/basic_passwords.txt"
|
||||||
unless -f "$basic_password_files";
|
unless -f "$basic_password_files";
|
||||||
|
|
||||||
# check if we need to enable verbose mode
|
|
||||||
if ($opt{verbose}) {
|
|
||||||
$opt{checkversion} = 1; #Check for updates to MySQLTuner
|
|
||||||
$opt{dbstat} = 1; #Print database information
|
|
||||||
$opt{idxstat} = 1; #Print index information
|
|
||||||
$opt{buffers} = 1; #Print global and per-thread buffer values
|
|
||||||
$opt{cvefile} = 'vulnerabilities.csv'; #CVE File for vulnerability checks
|
|
||||||
}
|
|
||||||
|
|
||||||
# for RPM distributions
|
# for RPM distributions
|
||||||
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
|
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
|
||||||
unless ( defined $opt{cvefile} and -f "$opt{cvefile}");
|
unless ( defined $opt{cvefile} and -f "$opt{cvefile}");
|
||||||
|
@ -210,7 +189,7 @@ my %result;
|
||||||
|
|
||||||
# Functions that handle the print styles
|
# Functions that handle the print styles
|
||||||
sub prettyprint {
|
sub prettyprint {
|
||||||
print $_[0] . "\n" unless ($opt{'silent'} or $opt{'json'});
|
print $_[0] . "\n" unless $opt{'silent'};
|
||||||
print $fh $_[0] . "\n" if defined($fh);
|
print $fh $_[0] . "\n" if defined($fh);
|
||||||
}
|
}
|
||||||
sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); }
|
sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); }
|
||||||
|
@ -406,8 +385,8 @@ sub os_setup {
|
||||||
|
|
||||||
# Checks for updates to MySQLTuner
|
# Checks for updates to MySQLTuner
|
||||||
sub validate_tuner_version {
|
sub validate_tuner_version {
|
||||||
if ($opt{'checkversion'} eq 0 and $opt{'updateversion'} eq 0) {
|
if ($opt{checkversion} eq 0) {
|
||||||
print "\n" unless ($opt{'silent'} or $opt{'json'});
|
print "\n";
|
||||||
infoprint "Skipped version check for MySQLTuner script";
|
infoprint "Skipped version check for MySQLTuner script";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -445,80 +424,12 @@ sub validate_tuner_version {
|
||||||
infoprint "Unable to check for the latest MySQLTuner version";
|
infoprint "Unable to check for the latest MySQLTuner version";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks for updates to MySQLTuner
|
|
||||||
sub update_tuner_version {
|
|
||||||
if ($opt{'updateversion'} eq 0) {
|
|
||||||
badprint "Skipped version update for MySQLTuner script";
|
|
||||||
print "\n" unless ($opt{'silent'} or $opt{'json'});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#use Cwd;
|
|
||||||
my $update;
|
|
||||||
my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/";
|
|
||||||
my @scripts = ("mysqltuner.pl", "basic_passwords.txt", "vulnerabilities.csv");
|
|
||||||
my $totalScripts = scalar(keys @scripts);
|
|
||||||
my $receivedScripts = 0;
|
|
||||||
my $httpcli =`which curl`;
|
|
||||||
|
|
||||||
foreach my $script (@scripts) {
|
|
||||||
|
|
||||||
chomp($httpcli);
|
|
||||||
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
|
|
||||||
debugprint "$httpcli is available.";
|
|
||||||
|
|
||||||
debugprint "$httpcli --connect-timeout 5 -silent '$url$script' > $script";
|
|
||||||
$update = `$httpcli --connect-timeout 5 -silent '$url$script' > $script`;
|
|
||||||
chomp($update);
|
|
||||||
debugprint "$script updated: $update";
|
|
||||||
|
|
||||||
if ( -s $script eq 0) {
|
|
||||||
badprint "Couldn't update $script";
|
|
||||||
} else {
|
|
||||||
++$receivedScripts;
|
|
||||||
debugprint "$script updated: $update";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$httpcli=`which wget`;
|
|
||||||
chomp($httpcli);
|
|
||||||
if ( defined($httpcli) and -e "$httpcli" ) {
|
|
||||||
debugprint "$httpcli is available.";
|
|
||||||
|
|
||||||
debugprint "$httpcli -qe timestamping=off -T 5 -O $script '$url$script'";
|
|
||||||
$update = `$httpcli -qe timestamping=off -T 5 -O $script '$url$script'`;
|
|
||||||
chomp($update);
|
|
||||||
|
|
||||||
if ( -s $script eq 0) {
|
|
||||||
badprint "Couldn't update $script";
|
|
||||||
} else {
|
|
||||||
++$receivedScripts;
|
|
||||||
debugprint "$script updated: $update";
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
debugprint "curl and wget are not available.";
|
|
||||||
infoprint "Unable to check for the latest MySQLTuner version";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($receivedScripts eq $totalScripts) {
|
|
||||||
goodprint "Successfully updated MySQLTuner script";
|
|
||||||
} else {
|
|
||||||
badprint "Couldn't update MySQLTuner script";
|
|
||||||
}
|
|
||||||
|
|
||||||
exit 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub compare_tuner_version {
|
sub compare_tuner_version {
|
||||||
my $remoteversion=shift;
|
my $remoteversion=shift;
|
||||||
debugprint "Remote data: $remoteversion";
|
debugprint "Remote data: $remoteversion";
|
||||||
#exit 0;
|
#exit 0;
|
||||||
if ($remoteversion ne $tunerversion) {
|
if ($remoteversion ne $tunerversion) {
|
||||||
badprint "There is a new version of MySQLTuner available ($remoteversion)";
|
badprint "There is a new version of MySQLTuner available ($remoteversion)";
|
||||||
update_tuner_version();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
goodprint "You have the latest version of MySQLTuner($tunerversion)";
|
goodprint "You have the latest version of MySQLTuner($tunerversion)";
|
||||||
|
@ -1050,7 +961,7 @@ sub system_recommendations {
|
||||||
my @opened_ports=get_opened_ports;
|
my @opened_ports=get_opened_ports;
|
||||||
infoprint "There is ". scalar @opened_ports. " listening port(s) on this server.";
|
infoprint "There is ". scalar @opened_ports. " listening port(s) on this server.";
|
||||||
if (scalar(@opened_ports) > $opt{'maxportallowed'}) {
|
if (scalar(@opened_ports) > $opt{'maxportallowed'}) {
|
||||||
badprint "There is too many listening ports: ". scalar(@opened_ports). " opened > ".$opt{'maxportallowed'}. "allowed.";
|
badprint "There is too many listening ports: ". scalar(@opened_ports) " opened > ".$opt{'maxportallowed'}. "allowed.";
|
||||||
push( @generalrec, "Consider dedicating a server for your database installation with less services running on !" );
|
push( @generalrec, "Consider dedicating a server for your database installation with less services running on !" );
|
||||||
} else {
|
} else {
|
||||||
goodprint "There is less than ".$opt{'maxportallowed'}." opened ports on this server.";
|
goodprint "There is less than ".$opt{'maxportallowed'}." opened ports on this server.";
|
||||||
|
@ -2628,9 +2539,9 @@ sub mysqsl_pfs {
|
||||||
# Performance Schema
|
# Performance Schema
|
||||||
unless ( defined($myvar{'performance_schema'}) and $myvar{'performance_schema'} eq 'ON' ) {
|
unless ( defined($myvar{'performance_schema'}) and $myvar{'performance_schema'} eq 'ON' ) {
|
||||||
infoprint "Performance schema is disabled.";
|
infoprint "Performance schema is disabled.";
|
||||||
} else {
|
|
||||||
infoprint "Performance schema is enabled.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infoprint "Performance schema is enabled.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2996,7 +2907,7 @@ sub mysql_databases {
|
||||||
$result{'Databases'}{'All databases'}{'Index Pct'} =
|
$result{'Databases'}{'All databases'}{'Index Pct'} =
|
||||||
percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
|
percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
|
||||||
$result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
|
$result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
|
||||||
print "\n" unless ($opt{'silent'} or $opt{'json'});
|
print "\n";
|
||||||
foreach (@dblist) {
|
foreach (@dblist) {
|
||||||
chomp($_);
|
chomp($_);
|
||||||
if ( $_ eq "information_schema"
|
if ( $_ eq "information_schema"
|
||||||
|
@ -3297,7 +3208,7 @@ sub dump_result {
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
my $json = JSON->new->allow_nonref;
|
my $json = JSON->new->allow_nonref;
|
||||||
print $json->utf8(1)->pretty(($opt{'prettyjson'} ? 1 : 0))->encode(\%result);
|
print JSON->new->utf8(1)->pretty(1)->encode(%result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3370,7 +3281,6 @@ You must provide the remote server's total memory when connecting to other serve
|
||||||
(Recommended for servers with many tables)
|
(Recommended for servers with many tables)
|
||||||
--skippassword Don't perform checks on user passwords(default: off)
|
--skippassword Don't perform checks on user passwords(default: off)
|
||||||
--checkversion Check for updates to MySQLTuner (default: don't check)
|
--checkversion Check for updates to MySQLTuner (default: don't check)
|
||||||
--updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)
|
|
||||||
--forcemem <size> Amount of RAM installed in megabytes
|
--forcemem <size> Amount of RAM installed in megabytes
|
||||||
--forceswap <size> Amount of swap memory configured in megabytes
|
--forceswap <size> Amount of swap memory configured in megabytes
|
||||||
--passwordfile <path>Path to a password file list(one password by line)
|
--passwordfile <path>Path to a password file list(one password by line)
|
||||||
|
@ -3393,7 +3303,7 @@ You must provide the remote server's total memory when connecting to other serve
|
||||||
--outputfile <path> Path to a output txt file
|
--outputfile <path> Path to a output txt file
|
||||||
--reportfile <path> Path to a report txt file
|
--reportfile <path> Path to a report txt file
|
||||||
--template <path> Path to a template file
|
--template <path> Path to a template file
|
||||||
--verbose Prints out all options (default: no verbose)
|
|
||||||
=head1 PERLDOC
|
=head1 PERLDOC
|
||||||
|
|
||||||
You can find documentation for this module with the perldoc command.
|
You can find documentation for this module with the perldoc command.
|
||||||
|
|
Loading…
Reference in a new issue