Merge pull request #137 from cloos/dependencies

Dependencies
Thanks @cloos 

This solution is nicer than the way I try to do it :)
This commit is contained in:
Jean-Marie Renouard 2015-11-23 09:55:51 +01:00
commit 8935266d06

View file

@ -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 );
@ -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);
@ -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;
@ -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;
@ -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 |
@ -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 ) {
@ -2639,7 +2632,7 @@ FROM INFORMATION_SCHEMA.STATISTICS s
ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
AND s.TABLE_NAME = t.TABLE_NAME
INNER JOIN (
SELECT
SELECT
TABLE_SCHEMA
, TABLE_NAME
, INDEX_NAME
@ -2688,12 +2681,12 @@ ENDSQL
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);
@ -2792,34 +2785,26 @@ END_TEMPLATE
}
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 );
@ -2893,7 +2878,7 @@ You must provide the remote server's total memory when connecting to other serve
--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