Merge pull request #665 from jmrenouard/master
Several improvements in remote management and feature testing
This commit is contained in:
commit
9085ceb000
3 changed files with 179 additions and 32 deletions
111
FEATURES.md
Normal file
111
FEATURES.md
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
Features list for option: --feature (dev only)
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
* arr2hash
|
||||||
|
* badprint
|
||||||
|
* calculations
|
||||||
|
* check_architecture
|
||||||
|
* check_metadata_perf
|
||||||
|
* check_storage_engines
|
||||||
|
* close_outputfile
|
||||||
|
* cmdprint
|
||||||
|
* compare_tuner_version
|
||||||
|
* cpu_cores
|
||||||
|
* cve_recommendations
|
||||||
|
* debugprint
|
||||||
|
* dump_result
|
||||||
|
* file2array
|
||||||
|
* file2string
|
||||||
|
* get_all_vars
|
||||||
|
* get_basic_passwords
|
||||||
|
* get_file_contents
|
||||||
|
* get_fs_info
|
||||||
|
* get_gcache_memory
|
||||||
|
* get_http_cli
|
||||||
|
* get_kernel_info
|
||||||
|
* get_log_file_real_path
|
||||||
|
* get_opened_ports
|
||||||
|
* get_os_release
|
||||||
|
* get_other_process_memory
|
||||||
|
* get_pf_memory
|
||||||
|
* get_process_memory
|
||||||
|
* get_replication_status
|
||||||
|
* get_system_info
|
||||||
|
* get_tuning_info
|
||||||
|
* get_wsrep_option
|
||||||
|
* get_wsrep_options
|
||||||
|
* goodprint
|
||||||
|
* greenwrap
|
||||||
|
* grep_file_contents
|
||||||
|
* headerprint
|
||||||
|
* hr_bytes
|
||||||
|
* hr_bytes_rnd
|
||||||
|
* hr_num
|
||||||
|
* hr_raw
|
||||||
|
* human_size
|
||||||
|
* infocmd
|
||||||
|
* infocmd_one
|
||||||
|
* infocmd_tab
|
||||||
|
* infoprint
|
||||||
|
* infoprintcmd
|
||||||
|
* infoprinthcmd
|
||||||
|
* infoprintml
|
||||||
|
* is_open_port
|
||||||
|
* is_virtual_machine
|
||||||
|
* log_file_recommendations
|
||||||
|
* make_recommendations
|
||||||
|
* mariadb_aria
|
||||||
|
* mariadb_connect
|
||||||
|
* mariadb_galera
|
||||||
|
* mariadb_rockdb
|
||||||
|
* mariadb_spider
|
||||||
|
* mariadb_threadpool
|
||||||
|
* mariadb_tokudb
|
||||||
|
* mariadb_xtradb
|
||||||
|
* memerror
|
||||||
|
* merge_hash
|
||||||
|
* mysql_databases
|
||||||
|
* mysql_indexes
|
||||||
|
* mysql_innodb
|
||||||
|
* mysql_myisam
|
||||||
|
* mysql_pfs
|
||||||
|
* mysql_routines
|
||||||
|
* mysql_setup
|
||||||
|
* mysql_stats
|
||||||
|
* mysql_tables
|
||||||
|
* mysql_triggers
|
||||||
|
* mysql_version_eq
|
||||||
|
* mysql_version_ge
|
||||||
|
* mysql_version_le
|
||||||
|
* mysql_views
|
||||||
|
* os_setup
|
||||||
|
* percentage
|
||||||
|
* pretty_uptime
|
||||||
|
* prettyprint
|
||||||
|
* redwrap
|
||||||
|
* remove_cr
|
||||||
|
* remove_empty
|
||||||
|
* security_recommendations
|
||||||
|
* select_array
|
||||||
|
* select_array_with_headers
|
||||||
|
* select_csv_file
|
||||||
|
* select_indexes_db
|
||||||
|
* select_one
|
||||||
|
* select_one_g
|
||||||
|
* select_routines_db
|
||||||
|
* select_str_g
|
||||||
|
* select_table_columns_db
|
||||||
|
* select_table_indexes_db
|
||||||
|
* select_tables_db
|
||||||
|
* select_triggers_db
|
||||||
|
* select_user_dbs
|
||||||
|
* select_views_db
|
||||||
|
* string2file
|
||||||
|
* subheaderprint
|
||||||
|
* system_recommendations
|
||||||
|
* trim
|
||||||
|
* update_tuner_version
|
||||||
|
* validate_mysql_version
|
||||||
|
* validate_tuner_version
|
||||||
|
* which
|
|
@ -9,7 +9,14 @@ perltidy -b mysqltuner.pl
|
||||||
echo "* Update CVE list"
|
echo "* Update CVE list"
|
||||||
perl updateCVElist.pl
|
perl updateCVElist.pl
|
||||||
dos2unix ../mysqltuner.pl
|
dos2unix ../mysqltuner.pl
|
||||||
git add ../vulnerabilities.csv ../mysqltuner.pl ../USAGE.md
|
|
||||||
|
# Update Feature list
|
||||||
|
(
|
||||||
|
echo -e "Features list for option: --feature (dev only)\n---\n\n"
|
||||||
|
grep -E '^sub ' ../mysqltuner.pl | perl -pe 's/sub //;s/\s*\{//g'| sort -n | perl -pe 's/^/* /g'
|
||||||
|
) > ../FEATURES.md
|
||||||
|
|
||||||
|
git add ../vulnerabilities.csv ../mysqltuner.pl ../USAGE.md ../FEATURES.md
|
||||||
#git commit -m 'Update Vulnerabilities list
|
#git commit -m 'Update Vulnerabilities list
|
||||||
#Indenting mysqltuner
|
#Indenting mysqltuner
|
||||||
#Update Usage information'
|
#Update Usage information'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# mysqltuner.pl - Version 2.1.3
|
# mysqltuner.pl - Version 2.1.4
|
||||||
# High Performance MySQL Tuning Script
|
# High Performance MySQL Tuning Script
|
||||||
# Copyright (C) 2006-2023 Major Hayden - major@mhtx.net
|
# Copyright (C) 2006-2023 Major Hayden - major@mhtx.net
|
||||||
# Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com
|
# Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com
|
||||||
|
@ -57,7 +57,7 @@ use Cwd 'abs_path';
|
||||||
#use Env;
|
#use Env;
|
||||||
|
|
||||||
# Set up a few variables for use in the script
|
# Set up a few variables for use in the script
|
||||||
my $tunerversion = "2.1.3";
|
my $tunerversion = "2.1.4";
|
||||||
my ( @adjvars, @generalrec );
|
my ( @adjvars, @generalrec );
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
|
@ -111,8 +111,7 @@ my %opt = (
|
||||||
"defaults-extra-file" => '',
|
"defaults-extra-file" => '',
|
||||||
"protocol" => '',
|
"protocol" => '',
|
||||||
"dumpdir" => '',
|
"dumpdir" => '',
|
||||||
"feature" => '',
|
"feature" => ''
|
||||||
"stop" => 0,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# Gather the options from the command line
|
# Gather the options from the command line
|
||||||
|
@ -145,7 +144,7 @@ GetOptions(
|
||||||
'idxstat', 'noidxstat',
|
'idxstat', 'noidxstat',
|
||||||
'server-log=s', 'protocol=s',
|
'server-log=s', 'protocol=s',
|
||||||
'defaults-extra-file=s', 'dumpdir=s',
|
'defaults-extra-file=s', 'dumpdir=s',
|
||||||
'feature=s', 'stop'
|
'feature=s'
|
||||||
)
|
)
|
||||||
or pod2usage(
|
or pod2usage(
|
||||||
-exitval => 1,
|
-exitval => 1,
|
||||||
|
@ -202,6 +201,7 @@ $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
|
# check if we need to enable verbose mode
|
||||||
|
if ( $opt{feature} ne '' ) { $opt{verbose} = 1; }
|
||||||
if ( $opt{verbose} ) {
|
if ( $opt{verbose} ) {
|
||||||
$opt{checkversion} = 1; # Check for updates to MySQLTuner
|
$opt{checkversion} = 1; # Check for updates to MySQLTuner
|
||||||
$opt{dbstat} = 1; # Print database information
|
$opt{dbstat} = 1; # Print database information
|
||||||
|
@ -275,10 +275,18 @@ sub prettyprint {
|
||||||
print $_[0] . "\n" unless ( $opt{'silent'} or $opt{'json'} );
|
print $_[0] . "\n" unless ( $opt{'silent'} or $opt{'json'} );
|
||||||
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 {
|
||||||
sub infoprint { prettyprint $info. " " . $_[0] unless ( $opt{noinfo} == 1 ); }
|
prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 );
|
||||||
sub badprint { prettyprint $bad. " " . $_[0] unless ( $opt{nobad} == 1 ); }
|
}
|
||||||
sub debugprint { prettyprint $deb. " " . $_[0] unless ( $opt{debug} == 0 ); }
|
sub infoprint {
|
||||||
|
prettyprint $info. " " . $_[0] unless ( $opt{noinfo} == 1 );
|
||||||
|
}
|
||||||
|
sub badprint {
|
||||||
|
prettyprint $bad. " " . $_[0] unless ( $opt{nobad} == 1 );
|
||||||
|
}
|
||||||
|
sub debugprint {
|
||||||
|
prettyprint $deb. " " . $_[0] unless ( $opt{debug} == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
sub redwrap {
|
sub redwrap {
|
||||||
return ( $opt{nocolor} == 0 ) ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0];
|
return ( $opt{nocolor} == 0 ) ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0];
|
||||||
|
@ -287,7 +295,9 @@ sub redwrap {
|
||||||
sub greenwrap {
|
sub greenwrap {
|
||||||
return ( $opt{nocolor} == 0 ) ? "\e[0;32m" . $_[0] . "\e[0m" : $_[0];
|
return ( $opt{nocolor} == 0 ) ? "\e[0;32m" . $_[0] . "\e[0m" : $_[0];
|
||||||
}
|
}
|
||||||
sub cmdprint { prettyprint $cmd. " " . $_[0] . $end; }
|
sub cmdprint {
|
||||||
|
prettyprint $cmd. " " . $_[0] . $end;
|
||||||
|
}
|
||||||
|
|
||||||
sub infoprintml {
|
sub infoprintml {
|
||||||
for my $ln (@_) { $ln =~ s/\n//g; infoprint "\t$ln"; }
|
for my $ln (@_) { $ln =~ s/\n//g; infoprint "\t$ln"; }
|
||||||
|
@ -312,6 +322,13 @@ sub infoprinthcmd {
|
||||||
infoprintcmd "$_[1]";
|
infoprintcmd "$_[1]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub is_remote() {
|
||||||
|
my $host = $opt{'host'};
|
||||||
|
return 0 if ( $host eq '' );
|
||||||
|
return 0 if ( $host eq 'localhost' );
|
||||||
|
return 0 if ( $host eq '127.0.0.1' );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
# Calculates the number of physical cores considering HyperThreading
|
# Calculates the number of physical cores considering HyperThreading
|
||||||
sub cpu_cores {
|
sub cpu_cores {
|
||||||
if ( $^O eq 'linux' ) {
|
if ( $^O eq 'linux' ) {
|
||||||
|
@ -768,18 +785,15 @@ sub mysql_setup {
|
||||||
chomp( $opt{host} );
|
chomp( $opt{host} );
|
||||||
|
|
||||||
# If we're doing a remote connection, but forcemem wasn't specified, we need to exit
|
# If we're doing a remote connection, but forcemem wasn't specified, we need to exit
|
||||||
if ( $opt{'forcemem'} eq 0
|
if ( $opt{'forcemem'} eq 0 && is_remote eq 1 )
|
||||||
&& ( $opt{host} ne "127.0.0.1" )
|
|
||||||
&& ( $opt{host} ne "localhost" ) )
|
|
||||||
{
|
{
|
||||||
badprint "The --forcemem option is required for remote connections";
|
badprint "The --forcemem option is required for remote connections";
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
infoprint "Performing tests on $opt{host}:$opt{port}";
|
infoprint "Performing tests on $opt{host}:$opt{port}";
|
||||||
$remotestring = " -h $opt{host} -P $opt{port}";
|
$remotestring = " -h $opt{host} -P $opt{port}";
|
||||||
if ( ( $opt{host} ne "127.0.0.1" ) && ( $opt{host} ne "localhost" ) ) {
|
$doremote = is_remote();
|
||||||
$doremote = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$opt{host} = '127.0.0.1';
|
$opt{host} = '127.0.0.1';
|
||||||
|
@ -1136,14 +1150,14 @@ sub select_user_dbs {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub select_tables_db() {
|
sub select_tables_db {
|
||||||
my $schema = shift;
|
my $schema = shift;
|
||||||
return select_array(
|
return select_array(
|
||||||
"SELECT DISTINCT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$schema'"
|
"SELECT DISTINCT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$schema'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub select_indexes_db() {
|
sub select_indexes_db {
|
||||||
my $schema = shift;
|
my $schema = shift;
|
||||||
return select_array(
|
return select_array(
|
||||||
"SELECT DISTINCT INDEX_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA='$schema'"
|
"SELECT DISTINCT INDEX_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA='$schema'"
|
||||||
|
@ -1409,6 +1423,10 @@ sub get_log_file_real_path {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub log_file_recommendations {
|
sub log_file_recommendations {
|
||||||
|
if ( is_remote eq 1 )
|
||||||
|
{
|
||||||
|
infoprint "Skipping error log files checks on remote host";
|
||||||
|
}
|
||||||
my $fh;
|
my $fh;
|
||||||
$myvar{'log_error'} = $opt{'server-log'}
|
$myvar{'log_error'} = $opt{'server-log'}
|
||||||
|| get_log_file_real_path( $myvar{'log_error'}, $myvar{'hostname'},
|
|| get_log_file_real_path( $myvar{'log_error'}, $myvar{'hostname'},
|
||||||
|
@ -1890,6 +1908,11 @@ sub get_system_info {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub system_recommendations {
|
sub system_recommendations {
|
||||||
|
if ( is_remote eq 1 )
|
||||||
|
{
|
||||||
|
infoprint "Skipping system checks on remote host";
|
||||||
|
return;
|
||||||
|
}
|
||||||
return if ( $opt{sysstat} == 0 );
|
return if ( $opt{sysstat} == 0 );
|
||||||
subheaderprint "System Linux Recommendations";
|
subheaderprint "System Linux Recommendations";
|
||||||
my $os = `uname`;
|
my $os = `uname`;
|
||||||
|
@ -2355,7 +2378,11 @@ sub mysql_version_le {
|
||||||
my ($arch);
|
my ($arch);
|
||||||
|
|
||||||
sub check_architecture {
|
sub check_architecture {
|
||||||
if ( $doremote eq 1 ) { return; }
|
if ( is_remote eq 1 )
|
||||||
|
{
|
||||||
|
infoprint "Skipping architecture check on remote host";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ( `uname` =~ /SunOS/ && `isainfo -b` =~ /64/ ) {
|
if ( `uname` =~ /SunOS/ && `isainfo -b` =~ /64/ ) {
|
||||||
$arch = 64;
|
$arch = 64;
|
||||||
goodprint "Operating on 64-bit architecture";
|
goodprint "Operating on 64-bit architecture";
|
||||||
|
@ -3973,7 +4000,7 @@ sub mysql_pfs {
|
||||||
"select * from sys.\`$sys_view\`"
|
"select * from sys.\`$sys_view\`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
exit 0 if ( $opt{stop} == 1 );
|
#exit 0 if ( $opt{stop} == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
# Top user per connection
|
# Top user per connection
|
||||||
|
@ -6511,7 +6538,7 @@ sub mysql_tables {
|
||||||
"select * from information_schema.$info_s_table"
|
"select * from information_schema.$info_s_table"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
exit 0 if ( $opt{stop} == 1 );
|
#exit 0 if ( $opt{stop} == 1 );
|
||||||
}
|
}
|
||||||
foreach ( select_user_dbs() ) {
|
foreach ( select_user_dbs() ) {
|
||||||
my $dbname = $_;
|
my $dbname = $_;
|
||||||
|
@ -6734,7 +6761,7 @@ ENDSQL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mysql_views() {
|
sub mysql_views {
|
||||||
subheaderprint "Views Metrics";
|
subheaderprint "Views Metrics";
|
||||||
unless ( mysql_version_ge( 5, 5 ) ) {
|
unless ( mysql_version_ge( 5, 5 ) ) {
|
||||||
infoprint
|
infoprint
|
||||||
|
@ -6743,7 +6770,7 @@ sub mysql_views() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mysql_routines() {
|
sub mysql_routines {
|
||||||
subheaderprint "Routines Metrics";
|
subheaderprint "Routines Metrics";
|
||||||
unless ( mysql_version_ge( 5, 5 ) ) {
|
unless ( mysql_version_ge( 5, 5 ) ) {
|
||||||
infoprint
|
infoprint
|
||||||
|
@ -6752,7 +6779,7 @@ sub mysql_routines() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mysql_triggers() {
|
sub mysql_triggers {
|
||||||
subheaderprint "Triggers Metrics";
|
subheaderprint "Triggers Metrics";
|
||||||
unless ( mysql_version_ge( 5, 5 ) ) {
|
unless ( mysql_version_ge( 5, 5 ) ) {
|
||||||
infoprint
|
infoprint
|
||||||
|
@ -6936,11 +6963,13 @@ get_tuning_info; # Get information about the tuning connection
|
||||||
calculations; # Calculate everything we need
|
calculations; # Calculate everything we need
|
||||||
|
|
||||||
if ($opt{'feature'} ne '') {
|
if ($opt{'feature'} ne '') {
|
||||||
subheaderprint "Running feature: $opt{'feature'}";
|
subheaderprint "See FEATURES.md for more information";
|
||||||
no strict 'refs';
|
no strict 'refs';
|
||||||
my $feature=$opt{'feature'};
|
for my $feature (split /,/, $opt{'feature'}) {
|
||||||
|
subheaderprint "Running feature: $opt{'feature'}";
|
||||||
$feature->();
|
$feature->();
|
||||||
exit(0)
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
validate_mysql_version; # Check current MySQL version
|
validate_mysql_version; # Check current MySQL version
|
||||||
|
|
||||||
|
@ -6992,7 +7021,7 @@ __END__
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
MySQLTuner 2.1.3 - MySQL High Performance Tuning Script
|
MySQLTuner 2.1.4 - MySQL High Performance Tuning Script
|
||||||
|
|
||||||
=head1 IMPORTANT USAGE GUIDELINES
|
=head1 IMPORTANT USAGE GUIDELINES
|
||||||
|
|
||||||
|
@ -7035,7 +7064,7 @@ You must provide the remote server's total memory when connecting to other serve
|
||||||
--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
|
||||||
--dumpdir <path> Path to a directory where to dump information files
|
--dumpdir <path> Path to a directory where to dump information files
|
||||||
|
--feature <feature> Run a specific feature (see FEATURES section)
|
||||||
=head1 OUTPUT OPTIONS
|
=head1 OUTPUT OPTIONS
|
||||||
|
|
||||||
--silent Don't output anything on screen
|
--silent Don't output anything on screen
|
||||||
|
|
Loading…
Reference in a new issue