Added lots of InnoDB support

Flipped spaces to tabs
Added more storage engine checks
Adjusted output display
This commit is contained in:
Major Hayden 2008-01-14 00:57:46 +00:00
parent bc69094412
commit aee3d61131

View file

@ -1,9 +1,9 @@
#!/usr/bin/perl -w
# mysqltuner.pl - Revision 20071201
# mysqltuner.pl - Version 20080113
# High Performance MySQL Tuning Script
# Copyright (C) 2006-2007 Major Hayden - major@mhtx.net
# Copyright (C) 2006-2008 Major Hayden - major@mhtx.net
#
# For the latest updates, please visit http://mysqltuner.com
# For the latest updates, please visit http://mysqltuner.com/
# Subversion repository available at http://tools.assembla.com/svn/mysqltuner/
#
# This program is free software: you can redistribute it and/or modify
@ -100,6 +100,16 @@ sub badprint {
print $bad." ".$text;
}
sub redwrap {
my $text = shift;
return "\e[00;31m".$text."\e[00m";
}
sub greenwrap {
my $text = shift;
return "\e[00;32m".$text."\e[00m";
}
my ($physical_memory,$swap_memory,$duflags);
sub os_setup {
my $os = `uname`;
@ -197,13 +207,14 @@ sub get_all_vars {
my ($mysqlvermajor,$mysqlverminor);
sub validate_mysql_version {
print "-------- General Statistics --------------------------------------------------\n";
($mysqlvermajor,$mysqlverminor) = $myvar{'version'} =~ /(\d)\.(\d)/;
if ($mysqlvermajor < 5) {
badprint "Your MySQL version ".$myvar{'version'}." is EOL software! Upgrade soon!\n";
} elsif ($mysqlvermajor == 5 && $mysqlverminor == 1) {
badprint "Currently running supported MySQL version ".$myvar{'version'}." (BETA - USE CAUTION)\n";
} else {
} elsif ($mysqlvermajor == 5) {
goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n";
} else {
badprint "Currently running unsupported MySQL version ".$myvar{'version'}."\n";
}
}
@ -222,6 +233,43 @@ sub check_architecture {
}
}
my %enginestats;
sub check_storage_engines {
print "-------- Storage Engine Statistics -------------------------------------------\n";
infoprint "Status: ";
my $engines;
$engines .= (defined $myvar{'have_archive'} && $myvar{'have_archive'} eq "YES")? greenwrap "+Archive " : redwrap "-Archive " ;
$engines .= (defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES")? greenwrap "+BDB " : redwrap "-BDB " ;
$engines .= (defined $myvar{'have_federated'} && $myvar{'have_federated'} eq "YES")? greenwrap "+Federated " : redwrap "-Federated " ;
$engines .= (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES")? greenwrap "+InnoDB " : redwrap "-InnoDB " ;
$engines .= (defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES")? greenwrap "+ISAM " : redwrap "-ISAM " ;
$engines .= (defined $myvar{'have_ndbcluster'} && $myvar{'have_ndbcluster'} eq "YES")? greenwrap "+NDBCluster " : redwrap "-NDBCluster " ;
print "$engines\n";
my @tblist;
my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`;
foreach my $db (@dblist) {
chomp($db);
push (@tblist,`mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM $db" | awk '{print \$2,\$7}'`);
foreach my $line (@tblist) {
$line =~ /([a-zA-Z_]*)\s*(.*)/;
if (defined $enginestats{$1}) {
$enginestats{$1} = $enginestats{$1} + $2;
} else {
$enginestats{$1} = $2;
}
}
}
while (my ($engine,$size) = each(%enginestats)) {
infoprint "Data in $engine tables: ".hr_bytes_rnd($size)."\n";
}
if (!defined $enginestats{'InnoDB'} && defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES") {
badprint "InnoDB is enabled but isn't being used\n";
}
if (!defined $enginestats{'BDB'} && defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES") {
badprint "BDB is enabled but isn't being used\n";
}
}
sub pretty_uptime {
my $uptime = shift;
my $seconds = $uptime % 60;
@ -250,7 +298,7 @@ sub hr_bytes_rnd {
} elsif ($num >= 1024) { #KB
return int(($num/1024))."K";
} else {
return $num;
return $num."B";
}
}
@ -263,7 +311,7 @@ sub hr_bytes {
} elsif ($num >= 1024) { #KB
return sprintf("%.1f",($num/1024))."K";
} else {
return $num;
return $num."B";
}
}
@ -402,13 +450,11 @@ sub calculations {
if ($myvar{'have_innodb'} eq "YES") {
$mycalc{'innodb_log_size_pct'} = ($myvar{'innodb_log_file_size'} * 100 / $myvar{'innodb_buffer_pool_size'});
}
}
my (@adjvars, @generalrec);
sub mysql_stats {
print "-------- General Statistics --------------------------------------------------\n";
print "-------- Performance Metrics -------------------------------------------------\n";
# Show uptime, queries per second, connections, traffic stats
my $qps;
if ($mystat{'Uptime'} > 0) { $qps = sprintf("%.3f",$mystat{'Questions'}/$mystat{'Uptime'}); }
@ -419,8 +465,7 @@ sub mysql_stats {
infoprint "Reads / Writes: ".$mycalc{'pct_reads'}."% / ".$mycalc{'pct_writes'}."%\n";
# Memory usage
infoprint "Total buffers per thread: ".hr_bytes($mycalc{'per_thread_buffers'})."\n";
infoprint "Total global buffers: ".hr_bytes($mycalc{'server_buffers'})."\n";
infoprint "Total buffers: ".hr_bytes($mycalc{'per_thread_buffers'})." per thread and ".hr_bytes($mycalc{'server_buffers'})." global\n";
if ($mycalc{'total_possible_used_memory'} > 2*1024*1024*1024 && $arch eq 32) {
badprint "Allocating > 2GB RAM on 32-bit systems can cause system instability\n";
badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n";
@ -433,9 +478,9 @@ sub mysql_stats {
# Slow queries
if ($mycalc{'pct_slow_queries'} > 5) {
badprint "Slow queries: $mycalc{'pct_slow_queries'}%\n";
badprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n";
} else {
goodprint "Slow queries: $mycalc{'pct_slow_queries'}%\n";
goodprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n";
}
if ($myvar{'long_query_time'} > 10) { push(@adjvars,"long_query_time (<= 10)"); }
if (defined($myvar{'log_slow_queries'})) {
@ -444,12 +489,12 @@ sub mysql_stats {
# Connections
if ($mycalc{'pct_connections_used'} > 85) {
badprint "Highest connection usage: $mycalc{'pct_connections_used'}%\n";
badprint "Highest connection usage: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n";
push(@adjvars,"max_connections (> ".$myvar{'max_connections'}.")");
push(@adjvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")");
push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage")
} else {
goodprint "Highest usage of available connections: $mycalc{'pct_connections_used'}%\n";
goodprint "Highest usage of available connections: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n";
}
# Key buffer
@ -602,16 +647,14 @@ sub mysql_stats {
}
# InnoDB
if ($myvar{'have_innodb'} eq "YES") {
if ($mycalc{'innodb_log_size_pct'} > 20 && $mycalc{'innodb_log_size_pct'} < 30) {
goodprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n";
if (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES" && defined $enginestats{'InnoDB'}) {
if ($myvar{'innodb_buffer_pool_size'} > $enginestats{'InnoDB'}) {
goodprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n";
} else {
badprint "InnoDB log size is ".hr_bytes($myvar{'innodb_log_file_size'})." ($mycalc{'innodb_log_size_pct'}% of InnoDB buffer pool)\n";
push(@generalrec,"Set innodb_log_file_size to 25% of InnoDB buffer pool");
push(@adjvars,"innodb_log_file_size (".hr_bytes($myvar{'innodb_buffer_pool_size'}*.25).", which is 25% of InnoDB buffer pool)");
badprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n";
push(@adjvars,"innodb_buffer_pool_size (>= ".hr_bytes_rnd($enginestats{'InnoDB'}).")");
}
}
}
sub make_recommendations {
@ -633,14 +676,15 @@ sub make_recommendations {
# ---------------------------------------------------------------------------
# BEGIN 'MAIN'
# ---------------------------------------------------------------------------
print " MySQL High-Performance Tuning Script - Major Hayden <major\@mhtx.net>\n".
" Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
" Run with '--help' for additional options and output filtering\n";
print " >> MySQL High-Performance Tuning Script - Major Hayden <major\@mhtx.net>\n".
" >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n".
" >> Run with '--help' for additional options and output filtering\n";
os_setup; # Set up some OS variables
mysql_setup; # Gotta login first
get_all_vars; # Toss variables/status into hashes
validate_mysql_version; # Check current MySQL version
check_architecture; # Suggest 64-bit upgrade
check_storage_engines; # Show enabled storage engines
calculations; # Calculate everything we need
mysql_stats; # Print the server stats
make_recommendations; # Make recommendations based on stats