Skip to content

Commit

Permalink
Merge pull request #137 from cloos/dependencies
Browse files Browse the repository at this point in the history
Dependencies
Thanks @cloos 

This solution is nicer than the way I try to do it :)
  • Loading branch information
jmrenouard committed Nov 23, 2015
2 parents edff8d7 + 11a8110 commit 8935266
Showing 1 changed file with 30 additions and 45 deletions.
75 changes: 30 additions & 45 deletions mysqltuner.pl
Expand Up @@ -36,14 +36,20 @@
# http://forge.mysql.com/projects/view.php?id=44
#
package main;

use 5.005;
use strict;
use warnings;

use diagnostics;
use File::Spec;
use Getopt::Long;
use File::Basename;
use Cwd 'abs_path';

use Data::Dumper;
$Data::Dumper::Pair = " : ";

# Set up a few variables for use in the script
my $tunerversion = "1.6.1";
my ( @adjvars, @generalrec );
Expand Down Expand Up @@ -365,23 +371,23 @@ sub validate_tuner_version {
chomp($httpcli);
if ( 1 != 1 and defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";

debugprint "$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli --connect-timeout 5 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
debugprint "VERSION: $update";


compare_tuner_version($update);
return;
}


$httpcli=`which wget`;
chomp($httpcli);
if ( defined($httpcli) and -e "$httpcli" ) {
debugprint "$httpcli is available.";

debugprint "$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2";
$update = `$httpcli -e timestamping=off -T 5 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2`;
chomp($update);
Expand Down Expand Up @@ -639,19 +645,6 @@ sub mysql_setup {
}
}

sub try_load {
my $mod = shift;

eval("use $mod");

if ($@) {
#print "\$@ = $@\n";
return(0);
} else {
return(1);
}
}

# MySQL Request Array
sub select_array {
my $req = shift;
Expand Down Expand Up @@ -1132,7 +1125,7 @@ sub check_storage_engines {
chomp($db);
if ( $db eq "information_schema"
or $db eq "performance_schema"
or $db eq "mysql"
or $db eq "mysql"
or $db eq "lost+found" )
{
next;
Expand Down Expand Up @@ -1687,7 +1680,7 @@ sub mysql_stats {

if ( defined $myvar{'query_cache_type'} ) {
infoprint "Query Cache Buffers";
infoprint " +-- Query Cache: "
infoprint " +-- Query Cache: "
. $myvar{'query_cache_type'} . " - "
. (
$myvar{'query_cache_type'} eq 0 |
Expand Down Expand Up @@ -2161,7 +2154,7 @@ sub mysql_myisam {
. " used / "
. hr_num( $myvar{'key_buffer_size'} )
. " cache)";
}
}

# Key buffer
if ( !defined( $mycalc{'total_myisam_indexes'} ) and $doremote == 1 ) {
Expand Down Expand Up @@ -2639,7 +2632,7 @@ sub mysql_indexes {
ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
AND s.TABLE_NAME = t.TABLE_NAME
INNER JOIN (
SELECT
SELECT
TABLE_SCHEMA
, TABLE_NAME
, INDEX_NAME
Expand Down Expand Up @@ -2688,12 +2681,12 @@ sub mysql_indexes {
and $myvar{'performance_schema'} eq 'ON' );

$selIdxReq = <<'ENDSQL';
SELECT CONCAT(CONCAT(object_schema,'.'),object_name) AS 'table', index_name
SELECT CONCAT(CONCAT(object_schema,'.'),object_name) AS 'table', index_name
FROM performance_schema.table_io_waits_summary_by_index_usage
WHERE index_name IS NOT NULL
AND count_star =0
AND index_name <> 'PRIMARY'
AND object_schema != 'mysql'
AND count_star =0
AND index_name <> 'PRIMARY'
AND object_schema != 'mysql'
ORDER BY count_star, object_schema, object_name;
ENDSQL
@idxinfo = select_array($selIdxReq);
Expand Down Expand Up @@ -2792,34 +2785,26 @@ sub file2string {
}
sub dump_result {
if ($opt{'debug'}) {

if (try_load('Data::Dumper')) {
badprint "Data::Dumper Module is needed.";
exit 1;
}

use Data::Dumper qw/Dumper/;
$Data::Dumper::Pair = " : ";
debugprint Dumper( \%result );
}

debugprint "HTML REPORT: $opt{'reportfile'}";

if ($opt{'reportfile'} ne 0 ) {
if (try_load('Text::Template')) {
eval "{ use Text::Template }";
if ($@) {
badprint "Text::Template Module is needed.";
exit 1;
}
if (try_load('Data::Dumper')) {
badprint "Data::Dumper Module is needed.";
exit 1;
}
use Text::Template;
use Data::Dumper qw/Dumper/;
$Data::Dumper::Pair = " : ";

my $vars= {'data' => Dumper( \%result ) };

my $template = Text::Template->new(TYPE => 'STRING', PREPEND => q{;}, SOURCE => $templateModel)
or die "Couldn't construct template: $Text::Template::ERROR";
my $template;
{
no warnings 'once';
$template = Text::Template->new(TYPE => 'STRING', PREPEND => q{;}, SOURCE => $templateModel)
or die "Couldn't construct template: $Text::Template::ERROR";
}
open my $fh, q(>), $opt{'reportfile'}
or die "Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
$template->fill_in(HASH =>$vars, OUTPUT=>$fh );
Expand Down Expand Up @@ -2893,7 +2878,7 @@ =head1 PERFORMANCE AND REPORTING OPTIONS
--forcemem <size> Amount of RAM installed in megabytes
--forceswap <size> Amount of swap memory configured in megabytes
--passwordfile <path>Path to a password file list(one password by line)
=head1 OUTPUT OPTIONS
--silent Don't output anything on screen
--nogood Remove OK responses
Expand Down

0 comments on commit 8935266

Please sign in to comment.