This commit is contained in:
Jean-Marie RENOUARD 2016-04-11 13:05:38 +02:00
commit 5fd8432bb6

View file

@ -212,11 +212,16 @@ open( $fh, '>', $outputfile )
if defined($outputfile); if defined($outputfile);
$opt{nocolor} = 1 if defined($outputfile); $opt{nocolor} = 1 if defined($outputfile);
# Setting up the colors for the print styles
my $me=`whoami`;
$me =~s/\n//g;
# Setting up the colors for the print styles # Setting up the colors for the print styles
my $good = ( $opt{nocolor} == 0 ) ? "[\e[0;32mOK\e[0m]" : "[OK]"; my $good = ( $opt{nocolor} == 0 ) ? "[\e[0;32mOK\e[0m]" : "[OK]";
my $bad = ( $opt{nocolor} == 0 ) ? "[\e[0;31m!!\e[0m]" : "[!!]"; my $bad = ( $opt{nocolor} == 0 ) ? "[\e[0;31m!!\e[0m]" : "[!!]";
my $info = ( $opt{nocolor} == 0 ) ? "[\e[0;34m--\e[0m]" : "[--]"; my $info = ( $opt{nocolor} == 0 ) ? "[\e[0;34m--\e[0m]" : "[--]";
my $deb = ( $opt{nocolor} == 0 ) ? "[\e[0;31mDG\e[0m]" : "[DG]"; my $deb = ( $opt{nocolor} == 0 ) ? "[\e[0;31mDG\e[0m]" : "[DG]";
my $cmd = ( $opt{nocolor} == 0 ) ? "\e[1;32m[CMD]($me)" : "[CMD]($me)";
my $end = ( $opt{nocolor} == 0 ) ? "\e[0m" : "";
# Super structure containing all information # Super structure containing all information
my %result; my %result;
@ -238,6 +243,24 @@ 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 infoprintml { for my $ln(@_) { $ln =~s/\n//g; infoprint "\t$ln"; } }
sub infoprintcmd { cmdprint "@_"; infoprintml grep { $_ ne '' and $_ !~ /^\s*$/ } `@_ 2>&1`; }
sub subheaderprint {
my $tln=100;
my $sln=8;
my $ln=length("@_")+2;
prettyprint " ";
#prettyprint "-"x$tln;
prettyprint "-"x$sln ." @_ ". "-"x($tln-$ln-$sln);
#prettyprint "-"x$tln;
}
sub infoprinthcmd {
# print Dumper @_;
subheaderprint "$_[0]";
infoprintcmd "$_[1]";
}
# Calculates the parameter passed in bytes, then rounds it to one decimal place # Calculates the parameter passed in bytes, then rounds it to one decimal place
sub hr_bytes { sub hr_bytes {
@ -1010,8 +1033,7 @@ sub get_basic_passwords {
} }
sub cve_recommendations { sub cve_recommendations {
prettyprint subheaderprint"CVE Security Recommendations";
"\n-------- CVE Security Recommendations ---------------------------------------";
unless ( defined( $opt{cvefile} ) && -f "$opt{cvefile}" ) { unless ( defined( $opt{cvefile} ) && -f "$opt{cvefile}" ) {
infoprint "Skipped due to --cvefile option undefined"; infoprint "Skipped due to --cvefile option undefined";
return; return;
@ -1260,8 +1282,7 @@ sub get_system_info() {
sub system_recommendations { sub system_recommendations {
return if ( $opt{sysstat} == 0 ); return if ( $opt{sysstat} == 0 );
prettyprint subheaderprint"System Linux Recommendations";
"\n-------- System Linux Recommendations ---------------------------------------";
my $os = `uname`; my $os = `uname`;
unless ( $os =~ /Linux/i ) { unless ( $os =~ /Linux/i ) {
infoprint "Skipped due to non Linux server"; infoprint "Skipped due to non Linux server";
@ -1334,8 +1355,7 @@ sub system_recommendations {
} }
sub security_recommendations { sub security_recommendations {
prettyprint subheaderprint "Security Recommendations";
"\n-------- Security Recommendations -------------------------------------------";
if ( $opt{skippassword} eq 1 ) { if ( $opt{skippassword} eq 1 ) {
infoprint "Skipped due to --skippassword option"; infoprint "Skipped due to --skippassword option";
return; return;
@ -1464,8 +1484,7 @@ sub security_recommendations {
} }
sub get_replication_status { sub get_replication_status {
prettyprint subheaderprint "Replication Metrics";
"\n-------- Replication Metrics -------------------------------------------------";
infoprint "Galera Synchronous replication: ". $myvar{'have_galera'}; infoprint "Galera Synchronous replication: ". $myvar{'have_galera'};
if ( scalar( keys %myslaves ) == 0 ) { if ( scalar( keys %myslaves ) == 0 ) {
infoprint "No replication slave(s) for this server."; infoprint "No replication slave(s) for this server.";
@ -1628,13 +1647,11 @@ my ( %enginestats, %enginecount, $fragtables );
sub check_storage_engines { sub check_storage_engines {
if ( $opt{skipsize} eq 1 ) { if ( $opt{skipsize} eq 1 ) {
prettyprint subheaderprint "Storage Engine Statistics";
"\n-------- Storage Engine Statistics -------------------------------------------";
infoprint "Skipped due to --skipsize option"; infoprint "Skipped due to --skipsize option";
return; return;
} }
prettyprint subheaderprint "Storage Engine Statistics";
"\n-------- Storage Engine Statistics -------------------------------------------";
my $engines; my $engines;
if ( mysql_version_ge( 5, 5 ) ) { if ( mysql_version_ge( 5, 5 ) ) {
@ -2234,8 +2251,7 @@ sub calculations {
} }
sub mysql_stats { sub mysql_stats {
prettyprint subheaderprint "Performance Metrics";
"\n-------- Performance Metrics -------------------------------------------------";
# Show uptime, queries per second, connections, traffic stats # Show uptime, queries per second, connections, traffic stats
my $qps; my $qps;
@ -2737,8 +2753,7 @@ sub mysql_stats {
# Recommendations for MyISAM # Recommendations for MyISAM
sub mysql_myisam { sub mysql_myisam {
prettyprint subheaderprint "MyISAM Metrics";
"\n-------- MyISAM Metrics ------------------------------------------------------";
# Key buffer usage # Key buffer usage
if ( defined( $mycalc{'pct_key_buffer_used'} ) ) { if ( defined( $mycalc{'pct_key_buffer_used'} ) ) {
@ -2863,8 +2878,7 @@ sub mysql_myisam {
# Recommendations for ThreadPool # Recommendations for ThreadPool
sub mariadb_threadpool { sub mariadb_threadpool {
prettyprint subheaderprint "ThreadPool Metrics";
"\n-------- ThreadPool Metrics --------------------------------------------------";
# AriaDB # AriaDB
unless ( defined $myvar{'have_threadpool'} unless ( defined $myvar{'have_threadpool'}
@ -2922,6 +2936,8 @@ sub mariadb_threadpool {
sub get_pf_memory sub get_pf_memory
{ {
# Performance Schema
return 0 unless ( defined( $myvar{'performance_schema'} ) and $myvar{'performance_schema'} eq 'ON' );
my @infoPFSMemory=grep /performance_schema.memory/, select_array("SHOW ENGINE PERFORMANCE_SCHEMA STATUS"); my @infoPFSMemory=grep /performance_schema.memory/, select_array("SHOW ENGINE PERFORMANCE_SCHEMA STATUS");
$infoPFSMemory[0] =~ s/.*\s+(\d+)$/$1/g; $infoPFSMemory[0] =~ s/.*\s+(\d+)$/$1/g;
@ -2929,8 +2945,7 @@ sub get_pf_memory
} }
# Recommendations for Performance Schema # Recommendations for Performance Schema
sub mysqsl_pfs { sub mysqsl_pfs {
prettyprint subheaderprint "Performance schema";
"\n-------- Performance schema --------------------------------------------------";
# Performance Schema # Performance Schema
unless ( defined( $myvar{'performance_schema'} ) unless ( defined( $myvar{'performance_schema'} )
@ -2946,8 +2961,7 @@ sub mysqsl_pfs {
# Recommendations for Ariadb # Recommendations for Ariadb
sub mariadb_ariadb { sub mariadb_ariadb {
prettyprint subheaderprint "AriaDB Metrics";
"\n-------- AriaDB Metrics ------------------------------------------------------";
# AriaDB # AriaDB
unless ( defined $myvar{'have_aria'} unless ( defined $myvar{'have_aria'}
@ -3016,8 +3030,7 @@ sub mariadb_ariadb {
# Recommendations for TokuDB # Recommendations for TokuDB
sub mariadb_tokudb { sub mariadb_tokudb {
prettyprint subheaderprint "TokuDB Metrics";
"\n-------- TokuDB Metrics ------------------------------------------------------";
# AriaDB # AriaDB
unless ( defined $myvar{'have_tokudb'} unless ( defined $myvar{'have_tokudb'}
@ -3061,8 +3074,7 @@ sub get_gcache_memory {
} }
# Recommendations for Galera # Recommendations for Galera
sub mariadb_galera { sub mariadb_galera {
prettyprint subheaderprint "Galera Metrics";
"\n-------- Galera Metrics ------------------------------------------------------";
# Galera Cluster # Galera Cluster
unless ( defined $myvar{'have_galera'} unless ( defined $myvar{'have_galera'}
@ -3146,8 +3158,7 @@ sub mariadb_galera {
# Recommendations for InnoDB # Recommendations for InnoDB
sub mysql_innodb { sub mysql_innodb {
prettyprint subheaderprint "InnoDB Metrics";
"\n-------- InnoDB Metrics ------------------------------------------------------";
# InnoDB # InnoDB
unless ( defined $myvar{'have_innodb'} unless ( defined $myvar{'have_innodb'}
@ -3358,8 +3369,7 @@ sub mysql_innodb {
sub mysql_databases { sub mysql_databases {
return if ( $opt{dbstat} == 0 ); return if ( $opt{dbstat} == 0 );
prettyprint subheaderprint "Database Metrics";
"\n-------- Database Metrics ----------------------------------------------------";
unless ( mysql_version_ge( 5, 5 ) ) { unless ( mysql_version_ge( 5, 5 ) ) {
infoprint infoprint
"Skip Database metrics from information schema missing in this version"; "Skip Database metrics from information schema missing in this version";
@ -3543,8 +3553,7 @@ sub mysql_databases {
sub mysql_indexes { sub mysql_indexes {
return if ( $opt{idxstat} == 0 ); return if ( $opt{idxstat} == 0 );
prettyprint subheaderprint "Indexes Metrics";
"\n-------- Indexes Metrics -----------------------------------------------------";
unless ( mysql_version_ge( 5, 5 ) ) { unless ( mysql_version_ge( 5, 5 ) ) {
infoprint infoprint
"Skip Index metrics from information schema missing in this version"; "Skip Index metrics from information schema missing in this version";
@ -3645,8 +3654,7 @@ ENDSQL
# Take the two recommendation arrays and display them at the end of the output # Take the two recommendation arrays and display them at the end of the output
sub make_recommendations { sub make_recommendations {
prettyprint subheaderprint "Recommendations";
"\n-------- Recommendations -----------------------------------------------------";
if ( @generalrec > 0 ) { if ( @generalrec > 0 ) {
prettyprint "General recommendations:"; prettyprint "General recommendations:";
foreach (@generalrec) { prettyprint " " . $_ . ""; } foreach (@generalrec) { prettyprint " " . $_ . ""; }