Skip to content

--server-log enhancements for containers/pods/systemd journal #539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 50 additions & 31 deletions mysqltuner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ package main;
"noprocess" => 0,
"dbstat" => 0,
"nodbstat" => 0,
"server-log" => '',
"tbstat" => 0,
"notbstat" => 0,
"idxstat" => 0,
Expand Down Expand Up @@ -133,6 +134,7 @@ package main;
'sysstat', 'nosysstat',
'pfstat', 'nopfstat',
'idxstat', 'noidxstat',
'server-log=s',
)
or pod2usage(
-exitval => 1,
Expand Down Expand Up @@ -236,6 +238,9 @@ package main;
my $cmd = ( $opt{nocolor} == 0 ) ? "\e[1;32m[CMD]($me)" : "[CMD]($me)";
my $end = ( $opt{nocolor} == 0 ) ? "\e[0m" : "";

# Maximum lines of log output to read from end
my $maxlines = 30000;

# Checks for supported or EOL'ed MySQL versions
my ( $mysqlvermajor, $mysqlverminor, $mysqlvermicro );

Expand Down Expand Up @@ -1242,7 +1247,8 @@ sub get_log_file_real_path {
}

sub log_file_recommendations {
$myvar{'log_error'} =
my $fh;
$myvar{'log_error'} = $opt{'server-log'} ||
get_log_file_real_path( $myvar{'log_error'}, $myvar{'hostname'},
$myvar{'datadir'} );

Expand All @@ -1251,39 +1257,54 @@ sub log_file_recommendations {
badprint "log_error is set to $myvar{'log_error'} MT can't read stderr";
return
}
if ( -f "$myvar{'log_error'}" ) {
goodprint "Log file $myvar{'log_error'} exists";
elsif ( $myvar{'log_error'} =~ /^(docker|podman|kubectl):(.*)/ ) {
open( $fh, '-|', "$1 logs --tail=$maxlines '$2'" )
// die "Can't start $1 $!";
goodprint "Log from cloud` $myvar{'log_error'} exists";
}
else {
badprint "Log file $myvar{'log_error'} doesn't exist";
return;
elsif ($myvar{'log_error'} =~ /^systemd:(.*)/ ) {
open( $fh, '-|', "journalctl -n $maxlines -b -u '$1'" )
// die "Can't start journalctl $!";
goodprint "Log journal` $myvar{'log_error'} exists";
}
infoprint "Log file: "
. $myvar{'log_error'} . "("
. hr_bytes_rnd( ( stat $myvar{'log_error'} )[7] ) . ")";

if ( -r "$myvar{'log_error'}" ) {
elsif ( -f "$myvar{'log_error'}" ) {
goodprint "Log file $myvar{'log_error'} exists";
my $size = ( stat $myvar{'log_error'} )[7];
infoprint "Log file: "
. $myvar{'log_error'} . "("
. hr_bytes_rnd( $size ) . ")";

if ( $size > 0 ) {
goodprint "Log file $myvar{'log_error'} is not empty";
if ( $size < 32 * 1024 * 1024 ) {
goodprint "Log file $myvar{'log_error'} is smaller than 32 Mb";
}
else {
badprint "Log file $myvar{'log_error'} is bigger than 32 Mb";
push @generalrec,
$myvar{'log_error'}
. " is > 32Mb, you should analyze why or implement a rotation log strategy such as logrotate!";
}
}
else {
infoprint
"Log file $myvar{'log_error'} is empty. Assuming log-rotation. Use --server-log={file} for explicit file";
return;
}
if ( ! open( $fh, '<', $myvar{'log_error'} ) ) {
badprint "Log file $myvar{'log_error'} isn't readable.";
return;
}
goodprint "Log file $myvar{'log_error'} is readable.";
}
else {
badprint "Log file $myvar{'log_error'} isn't readable.";
return;
}
if ( ( stat $myvar{'log_error'} )[7] > 0 ) {
goodprint "Log file $myvar{'log_error'} is not empty";
}
else {
badprint "Log file $myvar{'log_error'} is empty";
}

if ( ( stat $myvar{'log_error'} )[7] < 32 * 1024 * 1024 ) {
goodprint "Log file $myvar{'log_error'} is smaller than 32 Mb";
if ( $maxlines * 80 < $size ) {
seek( $fh, -$maxlines * 80, 2);
<$fh> ; # discard line fragment
}
}
else {
badprint "Log file $myvar{'log_error'} is bigger than 32 Mb";
push @generalrec,
$myvar{'log_error'}
. " is > 32Mb, you should analyze why or implement a rotation log strategy such as logrotate!";
badprint "Log file $myvar{'log_error'} doesn't exist";
return;
}

my $numLi = 0;
Expand All @@ -1292,9 +1313,6 @@ sub log_file_recommendations {
my @lastShutdowns;
my @lastStarts;

open( my $fh, '<', $myvar{'log_error'} )
or die "Can't open $myvar{'log_error'} for read: $!";

while ( my $logLi = <$fh> ) {
chomp $logLi;
$numLi++;
Expand Down Expand Up @@ -6428,6 +6446,7 @@ =head1 CONNECTION AND AUTHENTICATION
--mysqladmin <path> Path to a custom mysqladmin executable
--mysqlcmd <path> Path to a custom mysql executable
--defaults-file <path> Path to a custom .my.cnf
--server-log <path> Path to explict log file

=head1 PERFORMANCE AND REPORTING OPTIONS

Expand Down