Tidyfy code

This commit is contained in:
root 2016-08-31 10:30:20 +02:00
parent 746f5d3a4d
commit a067eddb20

View file

@ -202,7 +202,8 @@ if ( $opt{verbose} ) {
}
# for RPM distributions
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv" unless ( defined $opt{cvefile} and -f "$opt{cvefile}" );
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
unless ( defined $opt{cvefile} and -f "$opt{cvefile}" );
$opt{cvefile} = '' unless -f "$opt{cvefile}";
$opt{cvefile} = './vulnerabilities.csv' if -f './vulnerabilities.csv';
@ -238,6 +239,7 @@ my ( $mysqlvermajor, $mysqlverminor, $mysqlvermicro );
my %result;
$result{'MySQLTuner'}{'version'} = $tunerversion;
$result{'MySQLTuner'}{'options'} = \%opt;
# Functions that handle the print styles
sub prettyprint {
print $_[0] . "\n" unless ( $opt{'silent'} or $opt{'json'} );
@ -367,7 +369,8 @@ sub pretty_uptime {
my ( $physical_memory, $swap_memory, $duflags );
sub memerror {
badprint "Unable to determine total memory/swap; use '--forcemem' and '--forceswap'";
badprint
"Unable to determine total memory/swap; use '--forcemem' and '--forceswap'";
exit 1;
}
@ -456,7 +459,8 @@ sub os_setup {
$result{'OS'}{'Swap Memory'}{'bytes'} = $swap_memory;
$result{'OS'}{'Swap Memory'}{'pretty'} = hr_bytes($swap_memory);
$result{'OS'}{'Other Processes'}{'bytes'} = get_other_process_memory();
$result{'OS'}{'Other Processes'}{'pretty'} = hr_bytes(get_other_process_memory());
$result{'OS'}{'Other Processes'}{'pretty'} =
hr_bytes( get_other_process_memory() );
}
sub get_http_cli {
@ -801,8 +805,10 @@ sub mysql_setup {
debugprint "$mysqladmincmd $remotestring ping 2>&1";
my $loginstatus = `$mysqladmincmd $remotestring ping 2>&1`;
if ( $loginstatus =~ /mysqld is alive/ ) {
# Login went just fine
$mysqllogin = " $remotestring ";
# Did this go well because of a .my.cnf file or is there no password set?
my $userpath = `printenv HOME`;
if ( length($userpath) > 0 ) {
@ -810,7 +816,8 @@ sub mysql_setup {
}
unless ( -e "${userpath}/.my.cnf" or -e "${userpath}/.mylogin.cnf" )
{
badprint "Successfully authenticated with no password - SECURITY RISK!";
badprint
"Successfully authenticated with no password - SECURITY RISK!";
}
return 1;
}
@ -952,10 +959,12 @@ sub arr2hash {
}
sub get_all_vars {
# We need to initiate at least one query so that our data is useable
$dummyselect = select_one "SELECT VERSION()";
if ( not defined($dummyselect) or $dummyselect eq "" ) {
badprint "You probably doesn't get enough privileges for running MySQLTuner ...";
badprint
"You probably doesn't get enough privileges for running MySQLTuner ...";
exit(256);
}
$dummyselect =~ s/(.*?)\-.*/$1/;
@ -1060,16 +1069,22 @@ sub cve_recommendations {
#prettyprint "Look for related CVE for $myvar{'version'} or lower in $opt{cvefile}";
my $cvefound = 0;
open(my $fh, "<", $opt{cvefile}) or die "Can't open $opt{cvefile} for read: $!";
open( my $fh, "<", $opt{cvefile} )
or die "Can't open $opt{cvefile} for read: $!";
while ( my $cveline = <$fh> ) {
my @cve = split( ';', $cveline );
debugprint "Comparing $mysqlvermajor\.$mysqlverminor\.$mysqlvermicro with $cve[1]\.$cve[2]\.$cve[3] : ".(mysql_version_le( $cve[1], $cve[2], $cve[3] )?'<=':'>');
debugprint
"Comparing $mysqlvermajor\.$mysqlverminor\.$mysqlvermicro with $cve[1]\.$cve[2]\.$cve[3] : "
. ( mysql_version_le( $cve[1], $cve[2], $cve[3] ) ? '<=' : '>' );
# Avoid not major/minor version corresponding CVEs
next unless (int($cve[1])==$mysqlvermajor && int($cve[2])==$mysqlverminor);
next
unless ( int( $cve[1] ) == $mysqlvermajor
&& int( $cve[2] ) == $mysqlverminor );
if ( int( $cve[3] ) >= $mysqlvermicro ) {
badprint "$cve[4](<= $cve[1]\.$cve[2]\.$cve[3]) : $cve[6]";
$result{'CVE'}{'List'}{$cvefound}="$cve[4](<= $cve[1]\.$cve[2]\.$cve[3]) : $cve[6]";
$result{'CVE'}{'List'}{$cvefound} =
"$cve[4](<= $cve[1]\.$cve[2]\.$cve[3]) : $cve[6]";
$cvefound++;
}
}
@ -1082,7 +1097,8 @@ sub cve_recommendations {
return;
}
if ( $mysqlvermajor eq 5 and $mysqlverminor eq 5 ) {
infoprint "False positive CVE(s) for MySQL and MariaDB 5.5.x can be found.";
infoprint
"False positive CVE(s) for MySQL and MariaDB 5.5.x can be found.";
infoprint "Check careful each CVE for those particular versions";
}
badprint $cvefound . " CVE(s) found for your MySQL release.";
@ -1285,8 +1301,11 @@ sub get_kernel_info() {
}
# only if /proc/sys/sunrpc exists
my $tcp_slot_entries=`sysctl -n sunrpc.tcp_slot_table_entries 2>/dev/null`;
if ( -f "/proc/sys/sunrpc" and ($tcp_slot_entries eq '' or $tcp_slot_entries < 100) ) {
my $tcp_slot_entries =
`sysctl -n sunrpc.tcp_slot_table_entries 2>/dev/null`;
if ( -f "/proc/sys/sunrpc"
and ( $tcp_slot_entries eq '' or $tcp_slot_entries < 100 ) )
{
badprint
"Initial TCP slot entries is < 1M, please consider having a value greater than 100";
push @generalrec, "setup Initial TCP slot entries greater than 100";
@ -1369,6 +1388,7 @@ sub get_system_info() {
infoprint "Load Average : ";
infocmd_tab "top -n 1 -b | grep 'load average:'";
$result{'OS'}{'Load Average'} = `top -n 1 -b | grep 'load average:'`;
#infoprint "System Uptime Days/(HH:MM) : `uptime | awk '{print $3,$4}' | cut -f1 -d,`";
}
@ -1483,6 +1503,7 @@ sub security_recommendations {
badprint "MySQL version <=5.1 are deprecated and end of support.";
return;
}
# Looking for Empty Password
@mysqlstatlist = select_array
"SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE ($PASS_COLUMN_NAME = '' OR $PASS_COLUMN_NAME IS NULL) AND plugin NOT IN ('unix_socket', 'win_socket')";
@ -1662,9 +1683,11 @@ sub mysql_version_ge {
my ( $maj, $min, $mic ) = @_;
$min ||= 0;
$mic ||= 0;
return int($mysqlvermajor) > int($maj)
return
int($mysqlvermajor) > int($maj)
|| ( int($mysqlvermajor) == int($maj) && int($mysqlverminor) > int($min) )
|| ( int($mysqlverminor) == int($min) && int($mysqlvermicro) >= int($mic) );
|| ( int($mysqlverminor) == int($min)
&& int($mysqlvermicro) >= int($mic) );
}
# Checks if MySQL version is lower than equal to (major, minor, micro)
@ -1672,9 +1695,11 @@ sub mysql_version_le {
my ( $maj, $min, $mic ) = @_;
$min ||= 0;
$mic ||= 0;
return int($mysqlvermajor) < int($maj)
return
int($mysqlvermajor) < int($maj)
|| ( int($mysqlvermajor) == int($maj) && int($mysqlverminor) < int($min) )
|| ( int($mysqlverminor) == int($min) && int($mysqlvermicro) <= int($mic) );
|| ( int($mysqlverminor) == int($min)
&& int($mysqlvermicro) <= int($mic) );
}
# Checks if MySQL micro version is lower than equal to (major, minor, micro)
@ -2418,11 +2443,13 @@ sub mysql_stats {
. " per thread ($myvar{'max_connections'} max threads)";
infoprint "P_S Max memory usage: " . hr_bytes_rnd( get_pf_memory() );
$result{'P_S'}{'memory'} = get_other_process_memory();
$result{'P_S'}{'pretty_memory'}=hr_bytes_rnd(get_other_process_memory());
$result{'P_S'}{'pretty_memory'} =
hr_bytes_rnd( get_other_process_memory() );
infoprint "Galera GCache Max memory usage: "
. hr_bytes_rnd( get_gcache_memory() );
$result{'Galera'}{'GCache'}{'memory'} = get_gcache_memory();
$result{'Galera'}{'GCache'}{'pretty_memory'}=hr_bytes_rnd(get_gcache_memory());
$result{'Galera'}{'GCache'}{'pretty_memory'} =
hr_bytes_rnd( get_gcache_memory() );
if ( $opt{buffers} ne 0 ) {
infoprint "Global Buffers";
@ -2565,12 +2592,15 @@ sub mysql_stats {
# name resolution
if ( not defined( $result{'Variables'}{'skip_name_resolve'} ) ) {
infoprint "Skipped name resolution test due to missing skip_name_resolve in system variables. ?More info?";
} elsif( $result{'Variables'}{'skip_name_resolve'} eq 'OFF') {
infoprint
"Skipped name resolution test due to missing skip_name_resolve in system variables. ?More info?";
}
elsif ( $result{'Variables'}{'skip_name_resolve'} eq 'OFF' ) {
badprint
"name resolution is active : a reverse name resolution is made for each new connection and can reduce performance";
push( @generalrec,
"Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1" );
"Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1"
);
}
# Query cache
@ -2754,10 +2784,14 @@ sub mysql_stats {
badprint "Thread cache is disabled";
push( @generalrec, "Set thread_cache_size to 4 as a starting value" );
push( @adjvars, "thread_cache_size (start at 4)" );
} else {
if ( defined($myvar{'thread_handling'}) and $myvar{'thread_handling'} eq 'pools-of-threads') {
}
else {
if ( defined( $myvar{'thread_handling'} )
and $myvar{'thread_handling'} eq 'pools-of-threads' )
{
infoprint "Thread cache hit rate: not used with pool-of-threads";
} else {
}
else {
if ( $mycalc{'thread_cache_hit_rate'} <= 50 ) {
badprint
"Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% ("
@ -2767,7 +2801,8 @@ sub mysql_stats {
. " connections)";
push( @adjvars,
"thread_cache_size (> $myvar{'thread_cache_size'})" );
} else {
}
else {
goodprint
"Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% ("
. hr_num( $mystat{'Threads_created'} )
@ -3115,7 +3150,8 @@ sub mysqsl_pfs {
if ( grep /^sys$/, select_array("SHOW DATABASES") ) {
infoprint "Sys schema is installed.";
} else {
}
else {
infoprint "Sys schema isn't installed.";
return;
}
@ -3348,6 +3384,7 @@ having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
badprint
"There are $nbNodesSize nodes in wsrep_cluster_size. Prefer 3 or 5 nodes architecture.";
}
# wsrep_cluster_address doesn't include garbd nodes
if ( $nbNodes > $nbNodesSize ) {
badprint
@ -3393,13 +3430,22 @@ having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
}
if ( trim( $myvar{'wsrep_sst_method'} ) !~ "^xtrabackup.*" ) {
badprint "Galera SST method is not xtrabackup based.";
push( @adjvars, "set up parameter wsrep_sst_method to xtrabackup based parameter" );
push( @adjvars,
"set up parameter wsrep_sst_method to xtrabackup based parameter"
);
}
else {
goodprint "SST Method is based on xtrabackup.";
}
if ( (defined($myvar{'wsrep_OSU_method'}) && trim( $myvar{'wsrep_OSU_method'} ) eq "TOI") ||
(defined($myvar{'wsrep_osu_method'}) && trim( $myvar{'wsrep_osu_method'} ) eq "TOI") ) {
if (
(
defined( $myvar{'wsrep_OSU_method'} )
&& trim( $myvar{'wsrep_OSU_method'} ) eq "TOI"
)
|| ( defined( $myvar{'wsrep_osu_method'} )
&& trim( $myvar{'wsrep_osu_method'} ) eq "TOI" )
)
{
goodprint "TOI is default mode for upgrade.";
}
else {
@ -3592,19 +3638,37 @@ sub mysql_innodb {
# InnoDB Used Buffer Pool Size vs CHUNK size
if ( !defined( $myvar{'innodb_buffer_pool_chunk_size'} ) ) {
infoprint "InnoDB Buffer Pool Chunk Size not used or defined in your version";
} else {
infoprint "Number of InnoDB Buffer Pool Chunk : ". int($myvar{'innodb_buffer_pool_size'}) / int( $myvar{'innodb_buffer_pool_chunk_size'}) .
" for ". $myvar{'innodb_buffer_pool_instances'}. " Buffer Pool Instance(s)";
infoprint
"InnoDB Buffer Pool Chunk Size not used or defined in your version";
}
else {
infoprint "Number of InnoDB Buffer Pool Chunk : "
. int( $myvar{'innodb_buffer_pool_size'} ) /
int( $myvar{'innodb_buffer_pool_chunk_size'} ) . " for "
. $myvar{'innodb_buffer_pool_instances'}
. " Buffer Pool Instance(s)";
if (
int( $myvar{'innodb_buffer_pool_size'} ) % (
int( $myvar{'innodb_buffer_pool_chunk_size'} ) *
int( $myvar{'innodb_buffer_pool_instances'} )
) eq 0
)
{
goodprint
"innodb_buffer_pool_size is aligned with value innodb_buffer_pool_chunk_size and innodb_buffer_pool_instances";
}
else {
badprint
"innodb_buffer_pool_size is not aligned with value innodb_buffer_pool_chunk_size and innodb_buffer_pool_instances";
if ( int($myvar{'innodb_buffer_pool_size'}) % ( int( $myvar{'innodb_buffer_pool_chunk_size'}) * int($myvar{'innodb_buffer_pool_instances'})) eq 0 ) {
goodprint "innodb_buffer_pool_size is aligned with value innodb_buffer_pool_chunk_size and innodb_buffer_pool_instances";
} else {
badprint "innodb_buffer_pool_size is not aligned with value innodb_buffer_pool_chunk_size and innodb_buffer_pool_instances";
#push( @adjvars, "Adjust innodb_buffer_pool_instances, innodb_buffer_pool_chunk_size with innodb_buffer_pool_size" );
push( @adjvars, "innodb_buffer_pool_size must always be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances" );
push( @adjvars,
"innodb_buffer_pool_size must always be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances"
);
}
}
# InnoDB Read efficency
if ( defined $mycalc{'pct_read_efficiency'}
&& $mycalc{'pct_read_efficiency'} < 90 )
@ -4116,7 +4180,6 @@ get_all_vars; # Toss variables/status into hashes
get_tuning_info; # Get information about the tuning connexion
validate_mysql_version; # Check current MySQL version
check_architecture; # Suggest 64-bit upgrade
system_recommendations; # avoid to many service on the same host
check_storage_engines; # Show enabled storage engines