Added GetOptions check if fails show help
Added verbose mode
This commit is contained in:
parent
5c9f9952aa
commit
6c280de32f
1 changed files with 100 additions and 84 deletions
184
mysqltuner.pl
184
mysqltuner.pl
|
@ -84,74 +84,81 @@ my %opt = (
|
||||||
"template" => 0,
|
"template" => 0,
|
||||||
"json" => 0,
|
"json" => 0,
|
||||||
"prettyjson" => 0,
|
"prettyjson" => 0,
|
||||||
"reportfile" => 0
|
"reportfile" => 0,
|
||||||
|
"verbose" => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
# Gather the options from the command line
|
# Gather the options from the command line
|
||||||
GetOptions(
|
my $getOptionsCheck = 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', 'prettyjson', 'idxstat', 'noask',
|
'json', 'prettyjson', 'idxstat', 'noask',
|
||||||
'template=s', 'reportfile=s', 'cvefile=s', 'bannedports=s',
|
'template=s', 'reportfile=s', 'cvefile=s', 'bannedports=s',
|
||||||
'updateversion', '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 {
|
||||||
|
|
||||||
# Shown with --help option passed
|
# Shown with --help option passed
|
||||||
print " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n"
|
print " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n"
|
||||||
. " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n"
|
. " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n"
|
||||||
. " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n"
|
. " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n"
|
||||||
. "\n"
|
. "\n"
|
||||||
. " Important Usage Guidelines:\n"
|
. " Important Usage Guidelines:\n"
|
||||||
. " To run the script with the default options, run the script without arguments\n"
|
. " To run the script with the default options, run the script without arguments\n"
|
||||||
. " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n"
|
. " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n"
|
||||||
. " Some routines may require root level privileges (script will provide warnings)\n"
|
. " Some routines may require root level privileges (script will provide warnings)\n"
|
||||||
. " You must provide the remote server's total memory when connecting to other servers\n"
|
. " You must provide the remote server's total memory when connecting to other servers\n"
|
||||||
. "\n"
|
. "\n"
|
||||||
. " Connection and Authentication\n"
|
. " Connection and Authentication\n"
|
||||||
. " --host <hostname> Connect to a remote host to perform tests (default: localhost)\n"
|
. " --host <hostname> Connect to a remote host to perform tests (default: localhost)\n"
|
||||||
. " --socket <socket> Use a different socket for a local connection\n"
|
. " --socket <socket> Use a different socket for a local connection\n"
|
||||||
. " --port <port> Port to use for connection (default: 3306)\n"
|
. " --port <port> Port to use for connection (default: 3306)\n"
|
||||||
. " --user <username> Username to use for authentication\n"
|
. " --user <username> Username to use for authentication\n"
|
||||||
. " --pass <password> Password to use for authentication\n"
|
. " --pass <password> Password to use for authentication\n"
|
||||||
. " --mysqladmin <path> Path to a custom mysqladmin executable\n"
|
. " --mysqladmin <path> Path to a custom mysqladmin executable\n"
|
||||||
. " --mysqlcmd <path> Path to a custom mysql executable\n" . "\n"
|
. " --mysqlcmd <path> Path to a custom mysql executable\n" . "\n"
|
||||||
. " --noask Dont ask password if needed\n" . "\n"
|
. " --noask Dont ask password if needed\n" . "\n"
|
||||||
. " Performance and Reporting Options\n"
|
. " Performance and Reporting Options\n"
|
||||||
. " --skipsize Don't enumerate tables and their types/sizes (default: on)\n"
|
. " --skipsize Don't enumerate tables and their types/sizes (default: on)\n"
|
||||||
. " (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"
|
. " --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"
|
||||||
. " Output Options:\n"
|
. " Output Options:\n"
|
||||||
. " --silent Don't output anything on screen\n"
|
. " --silent Don't output anything on screen\n"
|
||||||
. " --nogood Remove OK responses\n"
|
. " --nogood Remove OK responses\n"
|
||||||
. " --nobad Remove negative/suggestion responses\n"
|
. " --nobad Remove negative/suggestion responses\n"
|
||||||
. " --noinfo Remove informational responses\n"
|
. " --noinfo Remove informational responses\n"
|
||||||
. " --debug Print debug information\n"
|
. " --debug Print debug information\n"
|
||||||
. " --dbstat Print database information\n"
|
. " --dbstat Print database information\n"
|
||||||
. " --idxstat Print index information\n"
|
. " --idxstat Print index information\n"
|
||||||
. " --bannedports Ports banned separated by comma(,)\n"
|
. " --bannedports Ports banned separated by comma(,)\n"
|
||||||
. " --maxportallowed Number of ports opened allowed on this hosts\n"
|
. " --maxportallowed Number of ports opened allowed on this hosts\n"
|
||||||
. " --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"
|
. " --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"
|
||||||
exit 0;
|
. " --verbose Prints out all options (default: no verbose) \n" . "\n";
|
||||||
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $devnull = File::Spec->devnull();
|
my $devnull = File::Spec->devnull();
|
||||||
|
@ -164,6 +171,15 @@ 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}");
|
||||||
|
@ -3350,34 +3366,34 @@ You must provide the remote server's total memory when connecting to other serve
|
||||||
|
|
||||||
=head1 PERFORMANCE AND REPORTING OPTIONS
|
=head1 PERFORMANCE AND REPORTING OPTIONS
|
||||||
|
|
||||||
--skipsize Don't enumerate tables and their types/sizes (default: on)
|
--skipsize Don't enumerate tables and their types/sizes (default: on)
|
||||||
(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)
|
--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)
|
||||||
|
|
||||||
=head1 OUTPUT OPTIONS
|
=head1 OUTPUT OPTIONS
|
||||||
|
|
||||||
--silent Don't output anything on screen
|
--silent Don't output anything on screen
|
||||||
--nogood Remove OK responses
|
--nogood Remove OK responses
|
||||||
--nobad Remove negative/suggestion responses
|
--nobad Remove negative/suggestion responses
|
||||||
--noinfo Remove informational responses
|
--noinfo Remove informational responses
|
||||||
--debug Print debug information
|
--debug Print debug information
|
||||||
--dbstat Print database information
|
--dbstat Print database information
|
||||||
--idxstat Print index information
|
--idxstat Print index information
|
||||||
--bannedports Ports banned separated by comma(,)
|
--bannedports Ports banned separated by comma(,)
|
||||||
--maxportallowed Number of ports opened allowed on this hosts
|
--maxportallowed Number of ports opened allowed on this hosts
|
||||||
--cvefile CVE File for vulnerability checks
|
--cvefile CVE File for vulnerability checks
|
||||||
--nocolor Don't print output in color
|
--nocolor Don't print output in color
|
||||||
--json Print result as JSON string
|
--json Print result as JSON string
|
||||||
--buffers Print global and per-thread buffer values
|
--buffers Print global and per-thread buffer values
|
||||||
--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