You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6558 line
215KB

  1. #!/usr/bin/env perl
  2. # mysqltuner.pl - Version 1.7.13
  3. # High Performance MySQL Tuning Script
  4. # Copyright (C) 2006-2018 Major Hayden - major@mhtx.net
  5. #
  6. # For the latest updates, please visit http://mysqltuner.com/
  7. # Git repository available at http://github.com/major/MySQLTuner-perl
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # This project would not be possible without help from:
  23. # Matthew Montgomery Paul Kehrer Dave Burgess
  24. # Jonathan Hinds Mike Jackson Nils Breunese
  25. # Shawn Ashlee Luuk Vosslamber Ville Skytta
  26. # Trent Hornibrook Jason Gill Mark Imbriaco
  27. # Greg Eden Aubin Galinotti Giovanni Bechis
  28. # Bill Bradford Ryan Novosielski Michael Scheidell
  29. # Blair Christensen Hans du Plooy Victor Trac
  30. # Everett Barnes Tom Krouper Gary Barrueto
  31. # Simon Greenaway Adam Stein Isart Montane
  32. # Baptiste M. Cole Turner Major Hayden
  33. # Joe Ashcraft Jean-Marie Renouard Christian Loos
  34. # Julien Francoz
  35. #
  36. # Inspired by Matthew Montgomery's tuning-primer.sh script:
  37. # http://forge.mysql.com/projects/view.php?id=44
  38. #
  39. package main;
  40. use 5.005;
  41. use strict;
  42. use warnings;
  43. use diagnostics;
  44. use File::Spec;
  45. use Getopt::Long;
  46. use Pod::Usage;
  47. use File::Basename;
  48. use Cwd 'abs_path';
  49. use Data::Dumper;
  50. $Data::Dumper::Pair = " : ";
  51. # for which()
  52. #use Env;
  53. # Set up a few variables for use in the script
  54. my $tunerversion = "1.7.13";
  55. my ( @adjvars, @generalrec );
  56. # Set defaults
  57. my %opt = (
  58. "silent" => 0,
  59. "nobad" => 0,
  60. "nogood" => 0,
  61. "noinfo" => 0,
  62. "debug" => 0,
  63. "nocolor" => ( !-t STDOUT ),
  64. "color" => 0,
  65. "forcemem" => 0,
  66. "forceswap" => 0,
  67. "host" => 0,
  68. "socket" => 0,
  69. "port" => 0,
  70. "user" => 0,
  71. "pass" => 0,
  72. "password" => 0,
  73. "ssl-ca" => 0,
  74. "skipsize" => 0,
  75. "checkversion" => 0,
  76. "updateversion" => 0,
  77. "buffers" => 0,
  78. "passwordfile" => 0,
  79. "bannedports" => '',
  80. "maxportallowed" => 0,
  81. "outputfile" => 0,
  82. "dbstat" => 0,
  83. "tbstat" => 0,
  84. "notbstat" => 0,
  85. "idxstat" => 0,
  86. "sysstat" => 0,
  87. "pfstat" => 0,
  88. "skippassword" => 0,
  89. "noask" => 0,
  90. "template" => 0,
  91. "json" => 0,
  92. "prettyjson" => 0,
  93. "reportfile" => 0,
  94. "verbose" => 0,
  95. "defaults-file" => '',
  96. );
  97. # Gather the options from the command line
  98. GetOptions(
  99. \%opt, 'nobad',
  100. 'nogood', 'noinfo',
  101. 'debug', 'nocolor',
  102. 'forcemem=i', 'forceswap=i',
  103. 'host=s', 'socket=s',
  104. 'port=i', 'user=s',
  105. 'pass=s', 'skipsize',
  106. 'checkversion', 'mysqladmin=s',
  107. 'mysqlcmd=s', 'help',
  108. 'buffers', 'skippassword',
  109. 'passwordfile=s', 'outputfile=s',
  110. 'silent', 'dbstat',
  111. 'json', 'prettyjson',
  112. 'idxstat', 'noask',
  113. 'template=s', 'reportfile=s',
  114. 'cvefile=s', 'bannedports=s',
  115. 'updateversion', 'maxportallowed=s',
  116. 'verbose', 'sysstat',
  117. 'password=s', 'pfstat',
  118. 'passenv=s', 'userenv=s',
  119. 'defaults-file=s', 'ssl-ca=s',
  120. 'color', 'tbstat',
  121. 'notbstat'
  122. )
  123. or pod2usage(
  124. -exitval => 1,
  125. -verbose => 99,
  126. -sections => [
  127. "NAME",
  128. "IMPORTANT USAGE GUIDELINES",
  129. "CONNECTION AND AUTHENTICATION",
  130. "PERFORMANCE AND REPORTING OPTIONS",
  131. "OUTPUT OPTIONS"
  132. ]
  133. );
  134. if ( defined $opt{'help'} && $opt{'help'} == 1 ) {
  135. pod2usage(
  136. -exitval => 0,
  137. -verbose => 99,
  138. -sections => [
  139. "NAME",
  140. "IMPORTANT USAGE GUIDELINES",
  141. "CONNECTION AND AUTHENTICATION",
  142. "PERFORMANCE AND REPORTING OPTIONS",
  143. "OUTPUT OPTIONS"
  144. ]
  145. );
  146. }
  147. my $devnull = File::Spec->devnull();
  148. my $basic_password_files =
  149. ( $opt{passwordfile} eq "0" )
  150. ? abs_path( dirname(__FILE__) ) . "/basic_passwords.txt"
  151. : abs_path( $opt{passwordfile} );
  152. # Username from envvar
  153. if ( exists $opt{userenv} && exists $ENV{ $opt{userenv} } ) {
  154. $opt{user} = $ENV{ $opt{userenv} };
  155. }
  156. # Related to password option
  157. if ( exists $opt{passenv} && exists $ENV{ $opt{passenv} } ) {
  158. $opt{pass} = $ENV{ $opt{passenv} };
  159. }
  160. $opt{pass} = $opt{password} if ( $opt{pass} eq 0 and $opt{password} ne 0 );
  161. # for RPM distributions
  162. $basic_password_files = "/usr/share/mysqltuner/basic_passwords.txt"
  163. unless -f "$basic_password_files";
  164. # check if we need to enable verbose mode
  165. if ( $opt{verbose} ) {
  166. $opt{checkversion} = 1; #Check for updates to MySQLTuner
  167. $opt{dbstat} = 1; #Print database information
  168. $opt{tbstat} = 1; #Print database information
  169. $opt{idxstat} = 1; #Print index information
  170. $opt{sysstat} = 1; #Print index information
  171. $opt{buffers} = 1; #Print global and per-thread buffer values
  172. $opt{pfstat} = 1; #Print performance schema info.
  173. $opt{cvefile} = 'vulnerabilities.csv'; #CVE File for vulnerability checks
  174. }
  175. $opt{nocolor} = 1 if defined($opt{outputfile});
  176. $opt{tbstat} = 1 if ($opt{notbstat} != 0); # Don't Print database information
  177. # for RPM distributions
  178. $opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
  179. unless ( defined $opt{cvefile} and -f "$opt{cvefile}" );
  180. $opt{cvefile} = '' unless -f "$opt{cvefile}";
  181. $opt{cvefile} = './vulnerabilities.csv' if -f './vulnerabilities.csv';
  182. $opt{'bannedports'} = '' unless defined( $opt{'bannedports'} );
  183. my @banned_ports = split ',', $opt{'bannedports'};
  184. #
  185. my $outputfile = undef;
  186. $outputfile = abs_path( $opt{outputfile} ) unless $opt{outputfile} eq "0";
  187. my $fh = undef;
  188. open( $fh, '>', $outputfile )
  189. or die("Fail opening $outputfile")
  190. if defined($outputfile);
  191. $opt{nocolor} = 1 if defined($outputfile);
  192. $opt{nocolor} = 1 unless ( -t STDOUT );
  193. $opt{nocolor} = 0 if ( $opt{color} == 1 );
  194. # Setting up the colors for the print styles
  195. my $me = `whoami`;
  196. $me =~ s/\n//g;
  197. # Setting up the colors for the print styles
  198. my $good = ( $opt{nocolor} == 0 ) ? "[\e[0;32mOK\e[0m]" : "[OK]";
  199. my $bad = ( $opt{nocolor} == 0 ) ? "[\e[0;31m!!\e[0m]" : "[!!]";
  200. my $info = ( $opt{nocolor} == 0 ) ? "[\e[0;34m--\e[0m]" : "[--]";
  201. my $deb = ( $opt{nocolor} == 0 ) ? "[\e[0;31mDG\e[0m]" : "[DG]";
  202. my $cmd = ( $opt{nocolor} == 0 ) ? "\e[1;32m[CMD]($me)" : "[CMD]($me)";
  203. my $end = ( $opt{nocolor} == 0 ) ? "\e[0m" : "";
  204. # Checks for supported or EOL'ed MySQL versions
  205. my ( $mysqlvermajor, $mysqlverminor, $mysqlvermicro );
  206. # Super structure containing all information
  207. my %result;
  208. $result{'MySQLTuner'}{'version'} = $tunerversion;
  209. $result{'MySQLTuner'}{'options'} = \%opt;
  210. # Functions that handle the print styles
  211. sub prettyprint {
  212. print $_[0] . "\n" unless ( $opt{'silent'} or $opt{'json'} );
  213. print $fh $_[0] . "\n" if defined($fh);
  214. }
  215. sub goodprint { prettyprint $good. " " . $_[0] unless ( $opt{nogood} == 1 ); }
  216. sub infoprint { prettyprint $info. " " . $_[0] unless ( $opt{noinfo} == 1 ); }
  217. sub badprint { prettyprint $bad. " " . $_[0] unless ( $opt{nobad} == 1 ); }
  218. sub debugprint { prettyprint $deb. " " . $_[0] unless ( $opt{debug} == 0 ); }
  219. sub redwrap {
  220. return ( $opt{nocolor} == 0 ) ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0];
  221. }
  222. sub greenwrap {
  223. return ( $opt{nocolor} == 0 ) ? "\e[0;32m" . $_[0] . "\e[0m" : $_[0];
  224. }
  225. sub cmdprint { prettyprint $cmd. " " . $_[0] . $end; }
  226. sub infoprintml {
  227. for my $ln (@_) { $ln =~ s/\n//g; infoprint "\t$ln"; }
  228. }
  229. sub infoprintcmd {
  230. cmdprint "@_";
  231. infoprintml grep { $_ ne '' and $_ !~ /^\s*$/ } `@_ 2>&1`;
  232. }
  233. sub subheaderprint {
  234. my $tln = 100;
  235. my $sln = 8;
  236. my $ln = length("@_") + 2;
  237. prettyprint " ";
  238. prettyprint "-" x $sln . " @_ " . "-" x ( $tln - $ln - $sln );
  239. }
  240. sub infoprinthcmd {
  241. subheaderprint "$_[0]";
  242. infoprintcmd "$_[1]";
  243. }
  244. # Calculates the number of physical cores considering HyperThreading
  245. sub cpu_cores {
  246. my $cntCPU =
  247. `awk -F: '/^core id/ && !P[\$2] { CORES++; P[\$2]=1 }; /^physical id/ && !N[\$2] { CPUs++; N[\$2]=1 }; END { print CPUs*CORES }' /proc/cpuinfo`;
  248. return ( $cntCPU == 0 ? `nproc` : $cntCPU );
  249. }
  250. # Calculates the parameter passed in bytes, then rounds it to one decimal place
  251. sub hr_bytes {
  252. my $num = shift;
  253. return "0B" unless defined($num);
  254. return "0B" if $num eq "NULL";
  255. if ( $num >= ( 1024**3 ) ) { #GB
  256. return sprintf( "%.1f", ( $num / ( 1024**3 ) ) ) . "G";
  257. }
  258. elsif ( $num >= ( 1024**2 ) ) { #MB
  259. return sprintf( "%.1f", ( $num / ( 1024**2 ) ) ) . "M";
  260. }
  261. elsif ( $num >= 1024 ) { #KB
  262. return sprintf( "%.1f", ( $num / 1024 ) ) . "K";
  263. }
  264. else {
  265. return $num . "B";
  266. }
  267. }
  268. sub hr_raw {
  269. my $num = shift;
  270. return "0" unless defined($num);
  271. return "0" if $num eq "NULL";
  272. if ( $num =~ /^(\d+)G$/ ) {
  273. return $1 * 1024 * 1024 * 1024;
  274. }
  275. if ( $num =~ /^(\d+)M$/ ) {
  276. return $1 * 1024 * 1024;
  277. }
  278. if ( $num =~ /^(\d+)K$/ ) {
  279. return $1 * 1024;
  280. }
  281. if ( $num =~ /^(\d+)$/ ) {
  282. return $1;
  283. }
  284. return $num;
  285. }
  286. # Calculates the parameter passed in bytes, then rounds it to the nearest integer
  287. sub hr_bytes_rnd {
  288. my $num = shift;
  289. return "0B" unless defined($num);
  290. return "0B" if $num eq "NULL";
  291. if ( $num >= ( 1024**3 ) ) { #GB
  292. return int( ( $num / ( 1024**3 ) ) ) . "G";
  293. }
  294. elsif ( $num >= ( 1024**2 ) ) { #MB
  295. return int( ( $num / ( 1024**2 ) ) ) . "M";
  296. }
  297. elsif ( $num >= 1024 ) { #KB
  298. return int( ( $num / 1024 ) ) . "K";
  299. }
  300. else {
  301. return $num . "B";
  302. }
  303. }
  304. # Calculates the parameter passed to the nearest power of 1000, then rounds it to the nearest integer
  305. sub hr_num {
  306. my $num = shift;
  307. if ( $num >= ( 1000**3 ) ) { # Billions
  308. return int( ( $num / ( 1000**3 ) ) ) . "B";
  309. }
  310. elsif ( $num >= ( 1000**2 ) ) { # Millions
  311. return int( ( $num / ( 1000**2 ) ) ) . "M";
  312. }
  313. elsif ( $num >= 1000 ) { # Thousands
  314. return int( ( $num / 1000 ) ) . "K";
  315. }
  316. else {
  317. return $num;
  318. }
  319. }
  320. # Calculate Percentage
  321. sub percentage {
  322. my $value = shift;
  323. my $total = shift;
  324. $total = 0 unless defined $total;
  325. $total = 0 if $total eq "NULL";
  326. return 100, 00 if $total == 0;
  327. return sprintf( "%.2f", ( $value * 100 / $total ) );
  328. }
  329. # Calculates uptime to display in a more attractive form
  330. sub pretty_uptime {
  331. my $uptime = shift;
  332. my $seconds = $uptime % 60;
  333. my $minutes = int( ( $uptime % 3600 ) / 60 );
  334. my $hours = int( ( $uptime % 86400 ) / (3600) );
  335. my $days = int( $uptime / (86400) );
  336. my $uptimestring;
  337. if ( $days > 0 ) {
  338. $uptimestring = "${days}d ${hours}h ${minutes}m ${seconds}s";
  339. }
  340. elsif ( $hours > 0 ) {
  341. $uptimestring = "${hours}h ${minutes}m ${seconds}s";
  342. }
  343. elsif ( $minutes > 0 ) {
  344. $uptimestring = "${minutes}m ${seconds}s";
  345. }
  346. else {
  347. $uptimestring = "${seconds}s";
  348. }
  349. return $uptimestring;
  350. }
  351. # Retrieves the memory installed on this machine
  352. my ( $physical_memory, $swap_memory, $duflags );
  353. sub memerror {
  354. badprint
  355. "Unable to determine total memory/swap; use '--forcemem' and '--forceswap'";
  356. exit 1;
  357. }
  358. sub os_setup {
  359. my $os = `uname`;
  360. $duflags = ( $os =~ /Linux/ ) ? '-b' : '';
  361. if ( $opt{'forcemem'} > 0 ) {
  362. $physical_memory = $opt{'forcemem'} * 1048576;
  363. infoprint "Assuming $opt{'forcemem'} MB of physical memory";
  364. if ( $opt{'forceswap'} > 0 ) {
  365. $swap_memory = $opt{'forceswap'} * 1048576;
  366. infoprint "Assuming $opt{'forceswap'} MB of swap space";
  367. }
  368. else {
  369. $swap_memory = 0;
  370. badprint "Assuming 0 MB of swap space (use --forceswap to specify)";
  371. }
  372. }
  373. else {
  374. if ( $os =~ /Linux|CYGWIN/ ) {
  375. $physical_memory =
  376. `grep -i memtotal: /proc/meminfo | awk '{print \$2}'`
  377. or memerror;
  378. $physical_memory *= 1024;
  379. $swap_memory =
  380. `grep -i swaptotal: /proc/meminfo | awk '{print \$2}'`
  381. or memerror;
  382. $swap_memory *= 1024;
  383. }
  384. elsif ( $os =~ /Darwin/ ) {
  385. $physical_memory = `sysctl -n hw.memsize` or memerror;
  386. $swap_memory =
  387. `sysctl -n vm.swapusage | awk '{print \$3}' | sed 's/\..*\$//'`
  388. or memerror;
  389. }
  390. elsif ( $os =~ /NetBSD|OpenBSD|FreeBSD/ ) {
  391. $physical_memory = `sysctl -n hw.physmem` or memerror;
  392. if ( $physical_memory < 0 ) {
  393. $physical_memory = `sysctl -n hw.physmem64` or memerror;
  394. }
  395. $swap_memory =
  396. `swapctl -l | grep '^/' | awk '{ s+= \$2 } END { print s }'`
  397. or memerror;
  398. }
  399. elsif ( $os =~ /BSD/ ) {
  400. $physical_memory = `sysctl -n hw.realmem` or memerror;
  401. $swap_memory =
  402. `swapinfo | grep '^/' | awk '{ s+= \$2 } END { print s }'`;
  403. }
  404. elsif ( $os =~ /SunOS/ ) {
  405. $physical_memory =
  406. `/usr/sbin/prtconf | grep Memory | cut -f 3 -d ' '`
  407. or memerror;
  408. chomp($physical_memory);
  409. $physical_memory = $physical_memory * 1024 * 1024;
  410. }
  411. elsif ( $os =~ /AIX/ ) {
  412. $physical_memory =
  413. `lsattr -El sys0 | grep realmem | awk '{print \$2}'`
  414. or memerror;
  415. chomp($physical_memory);
  416. $physical_memory = $physical_memory * 1024;
  417. $swap_memory = `lsps -as | awk -F"(MB| +)" '/MB /{print \$2}'`
  418. or memerror;
  419. chomp($swap_memory);
  420. $swap_memory = $swap_memory * 1024 * 1024;
  421. }
  422. elsif ( $os =~ /windows/i ) {
  423. $physical_memory =
  424. `wmic ComputerSystem get TotalPhysicalMemory | perl -ne "chomp; print if /[0-9]+/;"`
  425. or memerror;
  426. $swap_memory =
  427. `wmic OS get FreeVirtualMemory | perl -ne "chomp; print if /[0-9]+/;"`
  428. or memerror;
  429. }
  430. }
  431. debugprint "Physical Memory: $physical_memory";
  432. debugprint "Swap Memory: $swap_memory";
  433. chomp($physical_memory);
  434. chomp($swap_memory);
  435. chomp($os);
  436. $result{'OS'}{'OS Type'} = $os;
  437. $result{'OS'}{'Physical Memory'}{'bytes'} = $physical_memory;
  438. $result{'OS'}{'Physical Memory'}{'pretty'} = hr_bytes($physical_memory);
  439. $result{'OS'}{'Swap Memory'}{'bytes'} = $swap_memory;
  440. $result{'OS'}{'Swap Memory'}{'pretty'} = hr_bytes($swap_memory);
  441. $result{'OS'}{'Other Processes'}{'bytes'} = get_other_process_memory();
  442. $result{'OS'}{'Other Processes'}{'pretty'} =
  443. hr_bytes( get_other_process_memory() );
  444. }
  445. sub get_http_cli {
  446. my $httpcli = which( "curl", $ENV{'PATH'} );
  447. chomp($httpcli);
  448. if ($httpcli) {
  449. return $httpcli;
  450. }
  451. $httpcli = which( "wget", $ENV{'PATH'} );
  452. chomp($httpcli);
  453. if ($httpcli) {
  454. return $httpcli;
  455. }
  456. return "";
  457. }
  458. # Checks for updates to MySQLTuner
  459. sub validate_tuner_version {
  460. if ( $opt{'checkversion'} eq 0 and $opt{'updateversion'} eq 0 ) {
  461. print "\n" unless ( $opt{'silent'} or $opt{'json'} );
  462. infoprint "Skipped version check for MySQLTuner script";
  463. return;
  464. }
  465. my $update;
  466. my $url =
  467. "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl";
  468. my $httpcli = get_http_cli();
  469. if ( $httpcli =~ /curl$/ ) {
  470. debugprint "$httpcli is available.";
  471. debugprint
  472. "$httpcli -m 3 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2";
  473. $update =
  474. `$httpcli -m 3 -silent '$url' 2>/dev/null | grep 'my \$tunerversion'| cut -d\\\" -f2`;
  475. chomp($update);
  476. debugprint "VERSION: $update";
  477. compare_tuner_version($update);
  478. return;
  479. }
  480. if ( $httpcli =~ /wget$/ ) {
  481. debugprint "$httpcli is available.";
  482. debugprint
  483. "$httpcli -e timestamping=off -t 1 -T 3 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2";
  484. $update =
  485. `$httpcli -e timestamping=off -t 1 -T 3 -O - '$url' 2>$devnull| grep 'my \$tunerversion'| cut -d\\\" -f2`;
  486. chomp($update);
  487. compare_tuner_version($update);
  488. return;
  489. }
  490. debugprint "curl and wget are not available.";
  491. infoprint "Unable to check for the latest MySQLTuner version";
  492. infoprint
  493. "Using --pass and --password option is insecure during MySQLTuner execution(Password disclosure)"
  494. if ( defined( $opt{'pass'} ) );
  495. }
  496. # Checks for updates to MySQLTuner
  497. sub update_tuner_version {
  498. if ( $opt{'updateversion'} eq 0 ) {
  499. badprint "Skipped version update for MySQLTuner script";
  500. print "\n" unless ( $opt{'silent'} or $opt{'json'} );
  501. return;
  502. }
  503. my $update;
  504. my $url = "https://raw.githubusercontent.com/major/MySQLTuner-perl/master/";
  505. my @scripts =
  506. ( "mysqltuner.pl", "basic_passwords.txt", "vulnerabilities.csv" );
  507. my $totalScripts = scalar(@scripts);
  508. my $receivedScripts = 0;
  509. my $httpcli = get_http_cli();
  510. foreach my $script (@scripts) {
  511. if ( $httpcli =~ /curl$/ ) {
  512. debugprint "$httpcli is available.";
  513. debugprint
  514. "$httpcli --connect-timeout 3 '$url$script' 2>$devnull > $script";
  515. $update =
  516. `$httpcli --connect-timeout 3 '$url$script' 2>$devnull > $script`;
  517. chomp($update);
  518. debugprint "$script updated: $update";
  519. if ( -s $script eq 0 ) {
  520. badprint "Couldn't update $script";
  521. }
  522. else {
  523. ++$receivedScripts;
  524. debugprint "$script updated: $update";
  525. }
  526. }
  527. elsif ( $httpcli =~ /wget$/ ) {
  528. debugprint "$httpcli is available.";
  529. debugprint
  530. "$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'";
  531. $update =
  532. `$httpcli -qe timestamping=off -t 1 -T 3 -O $script '$url$script'`;
  533. chomp($update);
  534. if ( -s $script eq 0 ) {
  535. badprint "Couldn't update $script";
  536. }
  537. else {
  538. ++$receivedScripts;
  539. debugprint "$script updated: $update";
  540. }
  541. }
  542. else {
  543. debugprint "curl and wget are not available.";
  544. infoprint "Unable to check for the latest MySQLTuner version";
  545. }
  546. }
  547. if ( $receivedScripts eq $totalScripts ) {
  548. goodprint "Successfully updated MySQLTuner script";
  549. }
  550. else {
  551. badprint "Couldn't update MySQLTuner script";
  552. }
  553. #exit 0;
  554. }
  555. sub compare_tuner_version {
  556. my $remoteversion = shift;
  557. debugprint "Remote data: $remoteversion";
  558. #exit 0;
  559. if ( $remoteversion ne $tunerversion ) {
  560. badprint
  561. "There is a new version of MySQLTuner available($remoteversion)";
  562. update_tuner_version();
  563. return;
  564. }
  565. goodprint "You have the latest version of MySQLTuner($tunerversion)";
  566. return;
  567. }
  568. # Checks to see if a MySQL login is possible
  569. my ( $mysqllogin, $doremote, $remotestring, $mysqlcmd, $mysqladmincmd );
  570. my $osname = $^O;
  571. if ( $osname eq 'MSWin32' ) {
  572. eval { require Win32; } or last;
  573. $osname = Win32::GetOSName();
  574. infoprint "* Windows OS($osname) is not fully supported.\n";
  575. #exit 1;
  576. }
  577. sub mysql_setup {
  578. $doremote = 0;
  579. $remotestring = '';
  580. if ( $opt{mysqladmin} ) {
  581. $mysqladmincmd = $opt{mysqladmin};
  582. }
  583. else {
  584. $mysqladmincmd = which( "mysqladmin", $ENV{'PATH'} );
  585. }
  586. chomp($mysqladmincmd);
  587. if ( !-e $mysqladmincmd && $opt{mysqladmin} ) {
  588. badprint "Unable to find the mysqladmin command you specified: "
  589. . $mysqladmincmd . "";
  590. exit 1;
  591. }
  592. elsif ( !-e $mysqladmincmd ) {
  593. badprint "Couldn't find mysqladmin in your \$PATH. Is MySQL installed?";
  594. exit 1;
  595. }
  596. if ( $opt{mysqlcmd} ) {
  597. $mysqlcmd = $opt{mysqlcmd};
  598. }
  599. else {
  600. $mysqlcmd = which( "mysql", $ENV{'PATH'} );
  601. }
  602. chomp($mysqlcmd);
  603. if ( !-e $mysqlcmd && $opt{mysqlcmd} ) {
  604. badprint "Unable to find the mysql command you specified: "
  605. . $mysqlcmd . "";
  606. exit 1;
  607. }
  608. elsif ( !-e $mysqlcmd ) {
  609. badprint "Couldn't find mysql in your \$PATH. Is MySQL installed?";
  610. exit 1;
  611. }
  612. $mysqlcmd =~ s/\n$//g;
  613. my $mysqlclidefaults = `$mysqlcmd --print-defaults`;
  614. debugprint "MySQL Client: $mysqlclidefaults";
  615. if ( $mysqlclidefaults =~ /auto-vertical-output/ ) {
  616. badprint
  617. "Avoid auto-vertical-output in configuration file(s) for MySQL like";
  618. exit 1;
  619. }
  620. debugprint "MySQL Client: $mysqlcmd";
  621. $opt{port} = ( $opt{port} eq 0 ) ? 3306 : $opt{port};
  622. # Are we being asked to connect via a socket?
  623. if ( $opt{socket} ne 0 ) {
  624. $remotestring = " -S $opt{socket} -P $opt{port}";
  625. }
  626. # Are we being asked to connect to a remote server?
  627. if ( $opt{host} ne 0 ) {
  628. chomp( $opt{host} );
  629. # If we're doing a remote connection, but forcemem wasn't specified, we need to exit
  630. if ( $opt{'forcemem'} eq 0
  631. && ( $opt{host} ne "127.0.0.1" )
  632. && ( $opt{host} ne "localhost" ) )
  633. {
  634. badprint "The --forcemem option is required for remote connections";
  635. exit 1;
  636. }
  637. infoprint "Performing tests on $opt{host}:$opt{port}";
  638. $remotestring = " -h $opt{host} -P $opt{port}";
  639. if ( ( $opt{host} ne "127.0.0.1" ) && ( $opt{host} ne "localhost" ) ) {
  640. $doremote = 1;
  641. }
  642. }
  643. else {
  644. $opt{host} = '127.0.0.1';
  645. }
  646. if ( $opt{'ssl-ca'} ne 0 ) {
  647. if ( -e -r -f $opt{'ssl-ca'} ) {
  648. $remotestring .= " --ssl-ca=$opt{'ssl-ca'}";
  649. infoprint
  650. "Will connect using ssl public key passed on the command line";
  651. return 1;
  652. }
  653. else {
  654. badprint
  655. "Attempted to use passed ssl public key, but it was not found or could not be read";
  656. exit 1;
  657. }
  658. }
  659. # Did we already get a username without password on the command line?
  660. if ( $opt{user} ne 0 and $opt{pass} eq 0 ) {
  661. $mysqllogin = "-u $opt{user} " . $remotestring;
  662. my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
  663. if ( $loginstatus =~ /mysqld is alive/ ) {
  664. goodprint "Logged in using credentials passed on the command line";
  665. return 1;
  666. }
  667. else {
  668. badprint
  669. "Attempted to use login credentials, but they were invalid";
  670. exit 1;
  671. }
  672. }
  673. # Did we already get a username and password passed on the command line?
  674. if ( $opt{user} ne 0 and $opt{pass} ne 0 ) {
  675. $mysqllogin = "-u $opt{user} -p'$opt{pass}'" . $remotestring;
  676. my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
  677. if ( $loginstatus =~ /mysqld is alive/ ) {
  678. goodprint "Logged in using credentials passed on the command line";
  679. return 1;
  680. }
  681. else {
  682. badprint
  683. "Attempted to use login credentials, but they were invalid";
  684. exit 1;
  685. }
  686. }
  687. my $svcprop = which( "svcprop", $ENV{'PATH'} );
  688. if ( substr( $svcprop, 0, 1 ) =~ "/" ) {
  689. # We are on solaris
  690. ( my $mysql_login =
  691. `svcprop -p quickbackup/username svc:/network/mysql-quickbackup:default`
  692. ) =~ s/\s+$//;
  693. ( my $mysql_pass =
  694. `svcprop -p quickbackup/password svc:/network/mysql-quickbackup:default`
  695. ) =~ s/\s+$//;
  696. if ( substr( $mysql_login, 0, 7 ) ne "svcprop" ) {
  697. # mysql-quickbackup is installed
  698. $mysqllogin = "-u $mysql_login -p$mysql_pass";
  699. my $loginstatus = `mysqladmin $mysqllogin ping 2>&1`;
  700. if ( $loginstatus =~ /mysqld is alive/ ) {
  701. goodprint "Logged in using credentials from mysql-quickbackup.";
  702. return 1;
  703. }
  704. else {
  705. badprint
  706. "Attempted to use login credentials from mysql-quickbackup, but they failed.";
  707. exit 1;
  708. }
  709. }
  710. }
  711. elsif ( -r "/etc/psa/.psa.shadow" and $doremote == 0 ) {
  712. # It's a Plesk box, use the available credentials
  713. $mysqllogin = "-u admin -p`cat /etc/psa/.psa.shadow`";
  714. my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
  715. unless ( $loginstatus =~ /mysqld is alive/ ) {
  716. # Plesk 10+
  717. $mysqllogin =
  718. "-u admin -p`/usr/local/psa/bin/admin --show-password`";
  719. $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
  720. unless ( $loginstatus =~ /mysqld is alive/ ) {
  721. badprint
  722. "Attempted to use login credentials from Plesk and Plesk 10+, but they failed.";
  723. exit 1;
  724. }
  725. }
  726. }
  727. elsif ( -r "/usr/local/directadmin/conf/mysql.conf" and $doremote == 0 ) {
  728. # It's a DirectAdmin box, use the available credentials
  729. my $mysqluser =
  730. `cat /usr/local/directadmin/conf/mysql.conf | egrep '^user=.*'`;
  731. my $mysqlpass =
  732. `cat /usr/local/directadmin/conf/mysql.conf | egrep '^passwd=.*'`;
  733. $mysqluser =~ s/user=//;
  734. $mysqluser =~ s/[\r\n]//;
  735. $mysqlpass =~ s/passwd=//;
  736. $mysqlpass =~ s/[\r\n]//;
  737. $mysqllogin = "-u $mysqluser -p$mysqlpass";
  738. my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`;
  739. unless ( $loginstatus =~ /mysqld is alive/ ) {
  740. badprint
  741. "Attempted to use login credentials from DirectAdmin, but they failed.";
  742. exit 1;
  743. }
  744. }
  745. elsif ( -r "/etc/mysql/debian.cnf"
  746. and $doremote == 0
  747. and $opt{'defaults-file'} eq '' )
  748. {
  749. # We have a Debian maintenance account, use it
  750. $mysqllogin = "--defaults-file=/etc/mysql/debian.cnf";
  751. my $loginstatus = `$mysqladmincmd $mysqllogin ping 2>&1`;
  752. if ( $loginstatus =~ /mysqld is alive/ ) {
  753. goodprint
  754. "Logged in using credentials from Debian maintenance account.";
  755. return 1;
  756. }
  757. else {
  758. badprint "Attempted to use login credentials from Debian maintenance account, but they failed.";
  759. exit 1;
  760. }
  761. }
  762. elsif ( $opt{'defaults-file'} ne '' and -r "$opt{'defaults-file'}" ) {
  763. # defaults-file
  764. debugprint "defaults file detected: $opt{'defaults-file'}";
  765. my $mysqlclidefaults = `$mysqlcmd --print-defaults`;
  766. debugprint "MySQL Client Default File: $opt{'defaults-file'}";
  767. $mysqllogin = "--defaults-file=" . $opt{'defaults-file'};
  768. my $loginstatus = `$mysqladmincmd $mysqllogin ping 2>&1`;
  769. if ( $loginstatus =~ /mysqld is alive/ ) {
  770. goodprint "Logged in using credentials from defaults file account.";
  771. return 1;
  772. }
  773. }
  774. else {
  775. # It's not Plesk or Debian, we should try a login
  776. debugprint "$mysqladmincmd $remotestring ping 2>&1";
  777. my $loginstatus = `$mysqladmincmd $remotestring ping 2>&1`;
  778. if ( $loginstatus =~ /mysqld is alive/ ) {
  779. # Login went just fine
  780. $mysqllogin = " $remotestring ";
  781. # Did this go well because of a .my.cnf file or is there no password set?
  782. my $userpath = `printenv HOME`;
  783. if ( length($userpath) > 0 ) {
  784. chomp($userpath);
  785. }
  786. unless ( -e "${userpath}/.my.cnf" or -e "${userpath}/.mylogin.cnf" )
  787. {
  788. badprint
  789. "Successfully authenticated with no password - SECURITY RISK!";
  790. }
  791. return 1;
  792. }
  793. else {
  794. if ( $opt{'noask'} == 1 ) {
  795. badprint
  796. "Attempted to use login credentials, but they were invalid";
  797. exit 1;
  798. }
  799. my ( $name, $password );
  800. # If --user is defined no need to ask for username
  801. if ( $opt{user} ne 0 ) {
  802. $name = $opt{user};
  803. }
  804. else {
  805. print STDERR "Please enter your MySQL administrative login: ";
  806. $name = <STDIN>;
  807. }
  808. # If --pass is defined no need to ask for password
  809. if ( $opt{pass} ne 0 ) {
  810. $password = $opt{pass};
  811. }
  812. else {
  813. print STDERR
  814. "Please enter your MySQL administrative password: ";
  815. system("stty -echo >$devnull 2>&1");
  816. $password = <STDIN>;
  817. system("stty echo >$devnull 2>&1");
  818. }
  819. chomp($password);
  820. chomp($name);
  821. $mysqllogin = "-u $name";
  822. if ( length($password) > 0 ) {
  823. $mysqllogin .= " -p'$password'";
  824. }
  825. $mysqllogin .= $remotestring;
  826. my $loginstatus = `$mysqladmincmd ping $mysqllogin 2>&1`;
  827. if ( $loginstatus =~ /mysqld is alive/ ) {
  828. print STDERR "";
  829. if ( !length($password) ) {
  830. # Did this go well because of a .my.cnf file or is there no password set?
  831. my $userpath = `printenv HOME`;
  832. chomp($userpath);
  833. unless ( -e "$userpath/.my.cnf" ) {
  834. badprint
  835. "Successfully authenticated with no password - SECURITY RISK!";
  836. }
  837. }
  838. return 1;
  839. }
  840. else {
  841. badprint
  842. "Attempted to use login credentials, but they were invalid.";
  843. exit 1;
  844. }
  845. exit 1;
  846. }
  847. }
  848. }
  849. # MySQL Request Array
  850. sub select_array {
  851. my $req = shift;
  852. debugprint "PERFORM: $req ";
  853. my @result = `$mysqlcmd $mysqllogin -Bse "\\w$req" 2>>/dev/null`;
  854. if ( $? != 0 ) {
  855. badprint "failed to execute: $req";
  856. badprint "FAIL Execute SQL / return code: $?";
  857. debugprint "CMD : $mysqlcmd";
  858. debugprint "OPTIONS: $mysqllogin";
  859. debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`;
  860. #exit $?;
  861. }
  862. debugprint "select_array: return code : $?";
  863. chomp(@result);
  864. return @result;
  865. }
  866. sub human_size {
  867. my( $size, $n ) =( shift, 0 );
  868. ++$n and $size /= 1024 until $size < 1024;
  869. return sprintf "%.2f %s",
  870. $size, ( qw[ bytes KB MB GB ] )[ $n ];
  871. }
  872. # MySQL Request one
  873. sub select_one {
  874. my $req = shift;
  875. debugprint "PERFORM: $req ";
  876. my $result = `$mysqlcmd $mysqllogin -Bse "\\w$req" 2>>/dev/null`;
  877. if ( $? != 0 ) {
  878. badprint "failed to execute: $req";
  879. badprint "FAIL Execute SQL / return code: $?";
  880. debugprint "CMD : $mysqlcmd";
  881. debugprint "OPTIONS: $mysqllogin";
  882. debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`;
  883. #exit $?;
  884. }
  885. debugprint "select_array: return code : $?";
  886. chomp($result);
  887. return $result;
  888. }
  889. # MySQL Request one
  890. sub select_one_g {
  891. my $pattern = shift;
  892. my $req = shift;
  893. debugprint "PERFORM: $req ";
  894. my @result = `$mysqlcmd $mysqllogin -re "\\w$req\\G" 2>>/dev/null`;
  895. if ( $? != 0 ) {
  896. badprint "failed to execute: $req";
  897. badprint "FAIL Execute SQL / return code: $?";
  898. debugprint "CMD : $mysqlcmd";
  899. debugprint "OPTIONS: $mysqllogin";
  900. debugprint `$mysqlcmd $mysqllogin -Bse "$req" 2>&1`;
  901. #exit $?;
  902. }
  903. debugprint "select_array: return code : $?";
  904. chomp(@result);
  905. return ( grep { /$pattern/ } @result )[0];
  906. }
  907. sub select_str_g {
  908. my $pattern = shift;
  909. my $req = shift;
  910. my $str = select_one_g $pattern, $req;
  911. return () unless defined $str;
  912. my @val = split /:/, $str;
  913. shift @val;
  914. return trim(@val);
  915. }
  916. sub get_tuning_info {
  917. my @infoconn = select_array "\\s";
  918. my ( $tkey, $tval );
  919. @infoconn =
  920. grep { !/Threads:/ and !/Connection id:/ and !/pager:/ and !/Using/ }
  921. @infoconn;
  922. foreach my $line (@infoconn) {
  923. if ( $line =~ /\s*(.*):\s*(.*)/ ) {
  924. debugprint "$1 => $2";
  925. $tkey = $1;
  926. $tval = $2;
  927. chomp($tkey);
  928. chomp($tval);
  929. $result{'MySQL Client'}{$tkey} = $tval;
  930. }
  931. }
  932. $result{'MySQL Client'}{'Client Path'} = $mysqlcmd;
  933. $result{'MySQL Client'}{'Admin Path'} = $mysqladmincmd;
  934. $result{'MySQL Client'}{'Authentication Info'} = $mysqllogin;
  935. }
  936. # Populates all of the variable and status hashes
  937. my ( %mystat, %myvar, $dummyselect, %myrepl, %myslaves );
  938. sub arr2hash {
  939. my $href = shift;
  940. my $harr = shift;
  941. my $sep = shift;
  942. $sep = '\s' unless defined($sep);
  943. foreach my $line (@$harr) {
  944. next if ( $line =~ m/^\*\*\*\*\*\*\*/ );
  945. $line =~ /([a-zA-Z_]*)\s*$sep\s*(.*)/;
  946. $$href{$1} = $2;
  947. debugprint "V: $1 = $2";
  948. }
  949. }
  950. sub get_all_vars {
  951. # We need to initiate at least one query so that our data is useable
  952. $dummyselect = select_one "SELECT VERSION()";
  953. if ( not defined($dummyselect) or $dummyselect eq "" ) {
  954. badprint
  955. "You probably did not get enough privileges for running MySQLTuner ...";
  956. exit(256);
  957. }
  958. $dummyselect =~ s/(.*?)\-.*/$1/;
  959. debugprint "VERSION: " . $dummyselect . "";
  960. $result{'MySQL Client'}{'Version'} = $dummyselect;
  961. my @mysqlvarlist = select_array("SHOW VARIABLES");
  962. push( @mysqlvarlist, select_array("SHOW GLOBAL VARIABLES") );
  963. arr2hash( \%myvar, \@mysqlvarlist );
  964. $result{'Variables'} = \%myvar;
  965. my @mysqlstatlist = select_array("SHOW STATUS");
  966. push( @mysqlstatlist, select_array("SHOW GLOBAL STATUS") );
  967. arr2hash( \%mystat, \@mysqlstatlist );
  968. $result{'Status'} = \%mystat;
  969. unless( defined ($myvar{'innodb_support_xa'}) ) {
  970. $myvar{'innodb_support_xa'}='ON';
  971. }
  972. $myvar{'have_galera'} = "NO";
  973. if ( defined( $myvar{'wsrep_provider_options'} )
  974. && $myvar{'wsrep_provider_options'} ne ""
  975. && $myvar{'wsrep_on'} ne "OFF" )
  976. {
  977. $myvar{'have_galera'} = "YES";
  978. debugprint "Galera options: " . $myvar{'wsrep_provider_options'};
  979. }
  980. # Workaround for MySQL bug #59393 wrt. ignore-builtin-innodb
  981. if ( ( $myvar{'ignore_builtin_innodb'} || "" ) eq "ON" ) {
  982. $myvar{'have_innodb'} = "NO";
  983. }
  984. # Support GTID MODE FOR MARIADB
  985. # Issue MariaDB GTID mode #272
  986. $myvar{'gtid_mode'} = $myvar{'gtid_strict_mode'}
  987. if ( defined( $myvar{'gtid_strict_mode'} ) );
  988. $myvar{'have_threadpool'} = "NO";
  989. if ( defined( $myvar{'thread_pool_size'} )
  990. and $myvar{'thread_pool_size'} > 0 )
  991. {
  992. $myvar{'have_threadpool'} = "YES";
  993. }
  994. # have_* for engines is deprecated and will be removed in MySQL 5.6;
  995. # check SHOW ENGINES and set corresponding old style variables.
  996. # Also works around MySQL bug #59393 wrt. skip-innodb
  997. my @mysqlenginelist = select_array "SHOW ENGINES";
  998. foreach my $line (@mysqlenginelist) {
  999. if ( $line =~ /^([a-zA-Z_]+)\s+(\S+)/ ) {
  1000. my $engine = lc($1);
  1001. if ( $engine eq "federated" || $engine eq "blackhole" ) {
  1002. $engine .= "_engine";
  1003. }
  1004. elsif ( $engine eq "berkeleydb" ) {
  1005. $engine = "bdb";
  1006. }
  1007. my $val = ( $2 eq "DEFAULT" ) ? "YES" : $2;
  1008. $myvar{"have_$engine"} = $val;
  1009. $result{'Storage Engines'}{$engine} = $2;
  1010. }
  1011. }
  1012. debugprint Dumper(@mysqlenginelist);
  1013. my @mysqlslave = select_array("SHOW SLAVE STATUS\\G");
  1014. arr2hash( \%myrepl, \@mysqlslave, ':' );
  1015. $result{'Replication'}{'Status'} = \%myrepl;
  1016. my @mysqlslaves = select_array "SHOW SLAVE HOSTS";
  1017. my @lineitems = ();
  1018. foreach my $line (@mysqlslaves) {
  1019. debugprint "L: $line ";
  1020. @lineitems = split /\s+/, $line;
  1021. $myslaves{ $lineitems[0] } = $line;
  1022. $result{'Replication'}{'Slaves'}{ $lineitems[0] } = $lineitems[4];
  1023. }
  1024. }
  1025. sub remove_cr {
  1026. return map {
  1027. my $line = $_;
  1028. $line =~ s/\n$//g;
  1029. $line =~ s/^\s+$//g;
  1030. $line;
  1031. } @_;
  1032. }
  1033. sub remove_empty {
  1034. grep { $_ ne '' } @_;
  1035. }
  1036. sub grep_file_contents {
  1037. my $file = shift;
  1038. my $patt;
  1039. }
  1040. sub get_file_contents {
  1041. my $file = shift;
  1042. open( my $fh, "<", $file ) or die "Can't open $file for read: $!";
  1043. my @lines = <$fh>;
  1044. close $fh or die "Cannot close $file: $!";
  1045. @lines = remove_cr @lines;
  1046. return @lines;
  1047. }
  1048. sub get_basic_passwords {
  1049. return get_file_contents(shift);
  1050. }
  1051. sub get_log_file_real_path {
  1052. my $file = shift;
  1053. my $hostname = shift;
  1054. my $datadir = shift;
  1055. if ( -f "$file" ) {
  1056. return $file;
  1057. }
  1058. elsif ( -f "$hostname.err" ) {
  1059. return "$hostname.err";
  1060. }
  1061. elsif ( $datadir ne "" ) {
  1062. return "$datadir$hostname.err";
  1063. }
  1064. else {
  1065. return $file;
  1066. }
  1067. }
  1068. sub log_file_recommendations {
  1069. $myvar{'log_error'} =
  1070. get_log_file_real_path( $myvar{'log_error'}, $myvar{'hostname'},
  1071. $myvar{'datadir'} );
  1072. subheaderprint "Log file Recommendations";
  1073. infoprint "Log file: "
  1074. . $myvar{'log_error'} . "("
  1075. . hr_bytes_rnd( ( stat $myvar{'log_error'} )[7] ) . ")";
  1076. if ( -f "$myvar{'log_error'}" ) {
  1077. goodprint "Log file $myvar{'log_error'} exists";
  1078. }
  1079. else {
  1080. badprint "Log file $myvar{'log_error'} doesn't exist";
  1081. }
  1082. if ( -r "$myvar{'log_error'}" ) {
  1083. goodprint "Log file $myvar{'log_error'} is readable.";
  1084. }
  1085. else {
  1086. badprint "Log file $myvar{'log_error'} isn't readable.";
  1087. return;
  1088. }
  1089. if ( ( stat $myvar{'log_error'} )[7] > 0 ) {
  1090. goodprint "Log file $myvar{'log_error'} is not empty";
  1091. }
  1092. else {
  1093. badprint "Log file $myvar{'log_error'} is empty";
  1094. }
  1095. if ( ( stat $myvar{'log_error'} )[7] < 32 * 1024 * 1024 ) {
  1096. goodprint "Log file $myvar{'log_error'} is smaller than 32 Mb";
  1097. }
  1098. else {
  1099. badprint "Log file $myvar{'log_error'} is bigger than 32 Mb";
  1100. push @generalrec,
  1101. $myvar{'log_error'}
  1102. . " is > 32Mb, you should analyze why or implement a rotation log strategy such as logrotate!";
  1103. }
  1104. my $numLi = 0;
  1105. my $nbWarnLog = 0;
  1106. my $nbErrLog = 0;
  1107. my @lastShutdowns;
  1108. my @lastStarts;
  1109. open( my $fh, '<', $myvar{'log_error'} )
  1110. or die "Can't open $myvar{'log_error'} for read: $!";
  1111. while ( my $logLi = <$fh> ) {
  1112. chomp $logLi;
  1113. $numLi++;
  1114. debugprint "$numLi: $logLi" if $logLi =~ /warning|error/i;
  1115. $nbErrLog++ if $logLi =~ /error/i;
  1116. $nbWarnLog++ if $logLi =~ /warning/i;
  1117. push @lastShutdowns, $logLi
  1118. if $logLi =~ /Shutdown complete/ and $logLi !~ /Innodb/i;
  1119. push @lastStarts, $logLi if $logLi =~ /ready for connections/;
  1120. }
  1121. close $fh;
  1122. if ( $nbWarnLog > 0 ) {
  1123. badprint "$myvar{'log_error'} contains $nbWarnLog warning(s).";
  1124. push @generalrec,
  1125. "Control warning line(s) into $myvar{'log_error'} file";
  1126. }
  1127. else {
  1128. goodprint "$myvar{'log_error'} doesn't contain any warning.";
  1129. }
  1130. if ( $nbErrLog > 0 ) {
  1131. badprint "$myvar{'log_error'} contains $nbErrLog error(s).";
  1132. push @generalrec, "Control error line(s) into $myvar{'log_error'} file";
  1133. }
  1134. else {
  1135. goodprint "$myvar{'log_error'} doesn't contain any error.";
  1136. }
  1137. infoprint scalar @lastStarts . " start(s) detected in $myvar{'log_error'}";
  1138. my $nStart = 0;
  1139. my $nEnd = 10;
  1140. if ( scalar @lastStarts < $nEnd ) {
  1141. $nEnd = scalar @lastStarts;
  1142. }
  1143. for my $startd ( reverse @lastStarts[ -$nEnd .. -1 ] ) {
  1144. $nStart++;
  1145. infoprint "$nStart) $startd";
  1146. }
  1147. infoprint scalar @lastShutdowns
  1148. . " shutdown(s) detected in $myvar{'log_error'}";
  1149. $nStart = 0;
  1150. $nEnd = 10;
  1151. if ( scalar @lastShutdowns < $nEnd ) {
  1152. $nEnd = scalar @lastShutdowns;
  1153. }
  1154. for my $shutd ( reverse @lastShutdowns[ -$nEnd .. -1 ] ) {
  1155. $nStart++;
  1156. infoprint "$nStart) $shutd";
  1157. }
  1158. #exit 0;
  1159. }
  1160. sub cve_recommendations {
  1161. subheaderprint "CVE Security Recommendations";
  1162. unless ( defined( $opt{cvefile} ) && -f "$opt{cvefile}" ) {
  1163. infoprint "Skipped due to --cvefile option undefined";
  1164. return;
  1165. }
  1166. #$mysqlvermajor=10;
  1167. #$mysqlverminor=1;
  1168. #$mysqlvermicro=17;
  1169. #prettyprint "Look for related CVE for $myvar{'version'} or lower in $opt{cvefile}";
  1170. my $cvefound = 0;
  1171. open( my $fh, "<", $opt{cvefile} )
  1172. or die "Can't open $opt{cvefile} for read: $!";
  1173. while ( my $cveline = <$fh> ) {
  1174. my @cve = split( ';', $cveline );
  1175. debugprint
  1176. "Comparing $mysqlvermajor\.$mysqlverminor\.$mysqlvermicro with $cve[1]\.$cve[2]\.$cve[3] : "
  1177. . ( mysql_version_le( $cve[1], $cve[2], $cve[3] ) ? '<=' : '>' );
  1178. # Avoid not major/minor version corresponding CVEs
  1179. next
  1180. unless ( int( $cve[1] ) == $mysqlvermajor
  1181. && int( $cve[2] ) == $mysqlverminor );
  1182. if ( int( $cve[3] ) >= $mysqlvermicro ) {
  1183. badprint "$cve[4](<= $cve[1]\.$cve[2]\.$cve[3]) : $cve[6]";
  1184. $result{'CVE'}{'List'}{$cvefound} =
  1185. "$cve[4](<= $cve[1]\.$cve[2]\.$cve[3]) : $cve[6]";
  1186. $cvefound++;
  1187. }
  1188. }
  1189. close $fh or die "Cannot close $opt{cvefile}: $!";
  1190. $result{'CVE'}{'nb'} = $cvefound;
  1191. my $cve_warning_notes = "";
  1192. if ( $cvefound == 0 ) {
  1193. goodprint "NO SECURITY CVE FOUND FOR YOUR VERSION";
  1194. return;
  1195. }
  1196. if ( $mysqlvermajor eq 5 and $mysqlverminor eq 5 ) {
  1197. infoprint
  1198. "False positive CVE(s) for MySQL and MariaDB 5.5.x can be found.";
  1199. infoprint "Check careful each CVE for those particular versions";
  1200. }
  1201. badprint $cvefound . " CVE(s) found for your MySQL release.";
  1202. push( @generalrec,
  1203. $cvefound
  1204. . " CVE(s) found for your MySQL release. Consider upgrading your version !"
  1205. );
  1206. }
  1207. sub get_opened_ports {
  1208. my @opened_ports = `netstat -ltn`;
  1209. @opened_ports = map {
  1210. my $v = $_;
  1211. $v =~ s/.*:(\d+)\s.*$/$1/;
  1212. $v =~ s/\D//g;
  1213. $v;
  1214. } @opened_ports;
  1215. @opened_ports = sort { $a <=> $b } grep { !/^$/ } @opened_ports;
  1216. debugprint Dumper \@opened_ports;
  1217. $result{'Network'}{'TCP Opened'} = \@opened_ports;
  1218. return @opened_ports;
  1219. }
  1220. sub is_open_port {
  1221. my $port = shift;
  1222. if ( grep { /^$port$/ } get_opened_ports ) {
  1223. return 1;
  1224. }
  1225. return 0;
  1226. }
  1227. sub get_process_memory {
  1228. my $pid = shift;
  1229. my @mem = `ps -p $pid -o rss`;
  1230. return 0 if scalar @mem != 2;
  1231. return $mem[1] * 1024;
  1232. }
  1233. sub get_other_process_memory {
  1234. my @procs = `ps eaxo pid,command`;
  1235. @procs = map {
  1236. my $v = $_;
  1237. $v =~ s/.*PID.*//;
  1238. $v =~ s/.*mysqld.*//;
  1239. $v =~ s/.*\[.*\].*//;
  1240. $v =~ s/^\s+$//g;
  1241. $v =~ s/.*PID.*CMD.*//;
  1242. $v =~ s/.*systemd.*//;
  1243. $v =~ s/\s*?(\d+)\s*.*/$1/g;
  1244. $v;
  1245. } @procs;
  1246. @procs = remove_cr @procs;
  1247. @procs = remove_empty @procs;
  1248. my $totalMemOther = 0;
  1249. map { $totalMemOther += get_process_memory($_); } @procs;
  1250. return $totalMemOther;
  1251. }
  1252. sub get_os_release {
  1253. if ( -f "/etc/lsb-release" ) {
  1254. my @info_release = get_file_contents "/etc/lsb-release";
  1255. my $os_release = $info_release[3];
  1256. $os_release =~ s/.*="//;
  1257. $os_release =~ s/"$//;
  1258. return $os_release;
  1259. }
  1260. if ( -f "/etc/system-release" ) {
  1261. my @info_release = get_file_contents "/etc/system-release";
  1262. return $info_release[0];
  1263. }
  1264. if ( -f "/etc/os-release" ) {
  1265. my @info_release = get_file_contents "/etc/os-release";
  1266. my $os_release = $info_release[0];
  1267. $os_release =~ s/.*="//;
  1268. $os_release =~ s/"$//;
  1269. return $os_release;
  1270. }
  1271. if ( -f "/etc/issue" ) {
  1272. my @info_release = get_file_contents "/etc/issue";
  1273. my $os_release = $info_release[0];
  1274. $os_release =~ s/\s+\\n.*//;
  1275. return $os_release;
  1276. }
  1277. return "Unknown OS release";
  1278. }
  1279. sub get_fs_info {
  1280. my @sinfo = `df -P | grep '%'`;
  1281. my @iinfo = `df -Pi| grep '%'`;
  1282. shift @iinfo;
  1283. @sinfo = map {
  1284. my $v = $_;
  1285. $v =~ s/.*\s(\d+)%\s+(.*)/$1\t$2/g;
  1286. $v;
  1287. } @sinfo;
  1288. foreach my $info (@sinfo) {
  1289. next if $info =~ m{(\d+)\t/(run|dev|sys|proc)($|/)};
  1290. if ( $info =~ /(\d+)\t(.*)/ ) {
  1291. if ( $1 > 85 ) {
  1292. badprint "mount point $2 is using $1 % total space";
  1293. push( @generalrec, "Add some space to $2 mountpoint." );
  1294. }
  1295. else {
  1296. infoprint "mount point $2 is using $1 % of total space";
  1297. }
  1298. $result{'Filesystem'}{'Space Pct'}{$2} = $1;
  1299. }
  1300. }
  1301. @iinfo = map {
  1302. my $v = $_;
  1303. $v =~ s/.*\s(\d+)%\s+(.*)/$1\t$2/g;
  1304. $v;
  1305. } @iinfo;
  1306. foreach my $info (@iinfo) {
  1307. next if $info =~ m{(\d+)\t/(run|dev|sys|proc)($|/)};
  1308. if ( $info =~ /(\d+)\t(.*)/ ) {
  1309. if ( $1 > 85 ) {
  1310. badprint "mount point $2 is using $1 % of max allowed inodes";
  1311. push( @generalrec,
  1312. "Cleanup files from $2 mountpoint or reformat you filesystem."
  1313. );
  1314. }
  1315. else {
  1316. infoprint "mount point $2 is using $1 % of max allowed inodes";
  1317. }
  1318. $result{'Filesystem'}{'Inode Pct'}{$2} = $1;
  1319. }
  1320. }
  1321. }
  1322. sub merge_hash {
  1323. my $h1 = shift;
  1324. my $h2 = shift;
  1325. my %result = {};
  1326. foreach my $substanceref ( $h1, $h2 ) {
  1327. while ( my ( $k, $v ) = each %$substanceref ) {
  1328. next if ( exists $result{$k} );
  1329. $result{$k} = $v;
  1330. }
  1331. }
  1332. return \%result;
  1333. }
  1334. sub is_virtual_machine {
  1335. my $isVm = `grep -Ec '^flags.*\ hypervisor\ ' /proc/cpuinfo`;
  1336. return ( $isVm == 0 ? 0 : 1 );
  1337. }
  1338. sub infocmd {
  1339. my $cmd = "@_";
  1340. debugprint "CMD: $cmd";
  1341. my @result = `$cmd`;
  1342. @result = remove_cr @result;
  1343. for my $l (@result) {
  1344. infoprint "$l";
  1345. }
  1346. }
  1347. sub infocmd_tab {
  1348. my $cmd = "@_";
  1349. debugprint "CMD: $cmd";
  1350. my @result = `$cmd`;
  1351. @result = remove_cr @result;
  1352. for my $l (@result) {
  1353. infoprint "\t$l";
  1354. }
  1355. }
  1356. sub infocmd_one {
  1357. my $cmd = "@_";
  1358. my @result = `$cmd 2>&1`;
  1359. @result = remove_cr @result;
  1360. return join ', ', @result;
  1361. }
  1362. sub get_kernel_info {
  1363. my @params = (
  1364. 'fs.aio-max-nr', 'fs.aio-nr',
  1365. 'fs.file-max', 'sunrpc.tcp_fin_timeout',
  1366. 'sunrpc.tcp_max_slot_table_entries', 'sunrpc.tcp_slot_table_entries',
  1367. 'vm.swappiness'
  1368. );
  1369. infoprint "Information about kernel tuning:";
  1370. foreach my $param (@params) {
  1371. infocmd_tab("sysctl $param 2>/dev/null");
  1372. $result{'OS'}{'Config'}{$param} = `sysctl -n $param 2>/dev/null`;
  1373. }
  1374. if ( `sysctl -n vm.swappiness` > 10 ) {
  1375. badprint
  1376. "Swappiness is > 10, please consider having a value lower than 10";
  1377. push @generalrec, "setup swappiness lower or equals to 10";
  1378. push @adjvars,
  1379. 'vm.swappiness <= 10 (echo 10 > /proc/sys/vm/swappiness)';
  1380. }
  1381. else {
  1382. infoprint "Swappiness is < 10.";
  1383. }
  1384. # only if /proc/sys/sunrpc exists
  1385. my $tcp_slot_entries =
  1386. `sysctl -n sunrpc.tcp_slot_table_entries 2>/dev/null`;
  1387. if ( -f "/proc/sys/sunrpc"
  1388. and ( $tcp_slot_entries eq '' or $tcp_slot_entries < 100 ) )
  1389. {
  1390. badprint
  1391. "Initial TCP slot entries is < 1M, please consider having a value greater than 100";
  1392. push @generalrec, "setup Initial TCP slot entries greater than 100";
  1393. push @adjvars,
  1394. 'sunrpc.tcp_slot_table_entries > 100 (echo 128 > /proc/sys/sunrpc/tcp_slot_table_entries)';
  1395. }
  1396. else {
  1397. infoprint "TCP slot entries is > 100.";
  1398. }
  1399. if ( `sysctl -n fs.aio-max-nr` < 1000000 ) {
  1400. badprint
  1401. "Max running total of the number of events is < 1M, please consider having a value greater than 1M";
  1402. push @generalrec, "setup Max running number events greater than 1M";
  1403. push @adjvars,
  1404. 'fs.aio-max-nr > 1M (echo 1048576 > /proc/sys/fs/aio-max-nr)';
  1405. }
  1406. else {
  1407. infoprint "Max Number of AIO events is > 1M.";
  1408. }
  1409. }
  1410. sub get_system_info {
  1411. $result{'OS'}{'Release'} = get_os_release();
  1412. infoprint get_os_release;
  1413. if (is_virtual_machine) {
  1414. infoprint "Machine type : Virtual machine";
  1415. $result{'OS'}{'Virtual Machine'} = 'YES';
  1416. }
  1417. else {
  1418. infoprint "Machine type : Physical machine";
  1419. $result{'OS'}{'Virtual Machine'} = 'NO';
  1420. }
  1421. $result{'Network'}{'Connected'} = 'NO';
  1422. `ping -c 1 ipecho.net &>/dev/null`;
  1423. my $isConnected = $?;
  1424. if ( $? == 0 ) {
  1425. infoprint "Internet : Connected";
  1426. $result{'Network'}{'Connected'} = 'YES';
  1427. }
  1428. else {
  1429. badprint "Internet : Disconnected";
  1430. }
  1431. $result{'OS'}{'NbCore'} = cpu_cores;
  1432. infoprint "Number of Core CPU : " . cpu_cores;
  1433. $result{'OS'}{'Type'} = `uname -o`;
  1434. infoprint "Operating System Type : " . infocmd_one "uname -o";
  1435. $result{'OS'}{'Kernel'} = `uname -r`;
  1436. infoprint "Kernel Release : " . infocmd_one "uname -r";
  1437. $result{'OS'}{'Hostname'} = `hostname`;
  1438. $result{'Network'}{'Internal Ip'} = `hostname -I`;
  1439. infoprint "Hostname : " . infocmd_one "hostname";
  1440. infoprint "Network Cards : ";
  1441. infocmd_tab "ifconfig| grep -A1 mtu";
  1442. infoprint "Internal IP : " . infocmd_one "hostname -I";
  1443. $result{'Network'}{'Internal Ip'} = `ifconfig| grep -A1 mtu`;
  1444. my $httpcli = get_http_cli();
  1445. infoprint "HTTP client found: $httpcli" if defined $httpcli;
  1446. my $ext_ip = "";
  1447. if ( $httpcli =~ /curl$/ ) {
  1448. $ext_ip = infocmd_one "$httpcli -m 3 ipecho.net/plain";
  1449. }
  1450. elsif ( $httpcli =~ /wget$/ ) {
  1451. $ext_ip = infocmd_one "$httpcli -t 1 -T 3 -q -O - ipecho.net/plain";
  1452. }
  1453. infoprint "External IP : " . $ext_ip;
  1454. $result{'Network'}{'External Ip'} = $ext_ip;
  1455. badprint
  1456. "External IP : Can't check because of Internet connectivity"
  1457. unless defined($httpcli);
  1458. infoprint "Name Servers : "
  1459. . infocmd_one "grep 'nameserver' /etc/resolv.conf \| awk '{print \$2}'";
  1460. infoprint "Logged In users : ";
  1461. infocmd_tab "who";
  1462. $result{'OS'}{'Logged users'} = `who`;
  1463. infoprint "Ram Usages in Mb : ";
  1464. infocmd_tab "free -m | grep -v +";
  1465. $result{'OS'}{'Free Memory RAM'} = `free -m | grep -v +`;
  1466. infoprint "Load Average : ";
  1467. infocmd_tab "top -n 1 -b | grep 'load average:'";
  1468. $result{'OS'}{'Load Average'} = `top -n 1 -b | grep 'load average:'`;
  1469. infoprint "System Uptime : ";
  1470. infocmd_tab "uptime";
  1471. $result{'OS'}{'Uptime'}= `uptime`;
  1472. }
  1473. sub system_recommendations {
  1474. return if ( $opt{sysstat} == 0 );
  1475. subheaderprint "System Linux Recommendations";
  1476. my $os = `uname`;
  1477. unless ( $os =~ /Linux/i ) {
  1478. infoprint "Skipped due to non Linux server";
  1479. return;
  1480. }
  1481. prettyprint "Look for related Linux system recommendations";
  1482. #prettyprint '-'x78;
  1483. get_system_info();
  1484. my $omem = get_other_process_memory;
  1485. infoprint "User process except mysqld used "
  1486. . hr_bytes_rnd($omem) . " RAM.";
  1487. if ( ( 0.15 * $physical_memory ) < $omem ) {
  1488. badprint
  1489. "Other user process except mysqld used more than 15% of total physical memory "
  1490. . percentage( $omem, $physical_memory ) . "% ("
  1491. . hr_bytes_rnd($omem) . " / "
  1492. . hr_bytes_rnd($physical_memory) . ")";
  1493. push( @generalrec,
  1494. "Consider stopping or dedicate server for additional process other than mysqld."
  1495. );
  1496. push( @adjvars,
  1497. "DON'T APPLY SETTINGS BECAUSE THERE ARE TOO MANY PROCESSES RUNNING ON THIS SERVER. OOM KILL CAN OCCUR!"
  1498. );
  1499. }
  1500. else {
  1501. infoprint
  1502. "Other user process except mysqld used less than 15% of total physical memory "
  1503. . percentage( $omem, $physical_memory ) . "% ("
  1504. . hr_bytes_rnd($omem) . " / "
  1505. . hr_bytes_rnd($physical_memory) . ")";
  1506. }
  1507. if ( $opt{'maxportallowed'} > 0 ) {
  1508. my @opened_ports = get_opened_ports;
  1509. infoprint "There is "
  1510. . scalar @opened_ports
  1511. . " listening port(s) on this server.";
  1512. if ( scalar(@opened_ports) > $opt{'maxportallowed'} ) {
  1513. badprint "There is too many listening ports: "
  1514. . scalar(@opened_ports)
  1515. . " opened > "
  1516. . $opt{'maxportallowed'}
  1517. . "allowed.";
  1518. push( @generalrec,
  1519. "Consider dedicating a server for your database installation with less services running on !"
  1520. );
  1521. }
  1522. else {
  1523. goodprint "There is less than "
  1524. . $opt{'maxportallowed'}
  1525. . " opened ports on this server.";
  1526. }
  1527. }
  1528. foreach my $banport (@banned_ports) {
  1529. if ( is_open_port($banport) ) {
  1530. badprint "Banned port: $banport is opened..";
  1531. push( @generalrec,
  1532. "Port $banport is opened. Consider stopping program handling this port."
  1533. );
  1534. }
  1535. else {
  1536. goodprint "$banport is not opened.";
  1537. }
  1538. }
  1539. get_fs_info;
  1540. get_kernel_info;
  1541. }
  1542. sub security_recommendations {
  1543. subheaderprint "Security Recommendations";
  1544. if ( mysql_version_eq(8) ) {
  1545. infoprint "Skipped due to unsupported feature for MySQL 8";
  1546. return;
  1547. }
  1548. #exit 0;
  1549. if ( $opt{skippassword} eq 1 ) {
  1550. infoprint "Skipped due to --skippassword option";
  1551. return;
  1552. }
  1553. my $PASS_COLUMN_NAME = 'password';
  1554. if ( $myvar{'version'} =~ /5\.7|10\..*MariaDB*/ ) {
  1555. $PASS_COLUMN_NAME =
  1556. "IF(plugin='mysql_native_password', authentication_string, 'password')";
  1557. }
  1558. debugprint "Password column = $PASS_COLUMN_NAME";
  1559. # Looking for Anonymous users
  1560. my @mysqlstatlist = select_array
  1561. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE TRIM(USER) = '' OR USER IS NULL";
  1562. debugprint Dumper \@mysqlstatlist;
  1563. #exit 0;
  1564. if (@mysqlstatlist) {
  1565. foreach my $line ( sort @mysqlstatlist ) {
  1566. chomp($line);
  1567. badprint "User '" . $line . "' is an anonymous account.";
  1568. }
  1569. push( @generalrec,
  1570. "Remove Anonymous User accounts - there are "
  1571. . scalar(@mysqlstatlist)
  1572. . " anonymous accounts." );
  1573. }
  1574. else {
  1575. goodprint "There are no anonymous accounts for any database users";
  1576. }
  1577. if ( mysql_version_le( 5, 1 ) ) {
  1578. badprint "No more password checks for MySQL version <=5.1";
  1579. badprint "MySQL version <=5.1 are deprecated and end of support.";
  1580. return;
  1581. }
  1582. # Looking for Empty Password
  1583. if ( mysql_version_ge( 5, 5 ) ) {
  1584. @mysqlstatlist = select_array
  1585. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE ($PASS_COLUMN_NAME = '' OR $PASS_COLUMN_NAME IS NULL) AND plugin NOT IN ('unix_socket', 'win_socket', 'auth_pam_compat')";
  1586. }
  1587. else {
  1588. @mysqlstatlist = select_array
  1589. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE ($PASS_COLUMN_NAME = '' OR $PASS_COLUMN_NAME IS NULL)";
  1590. }
  1591. if (@mysqlstatlist) {
  1592. foreach my $line ( sort @mysqlstatlist ) {
  1593. chomp($line);
  1594. badprint "User '" . $line . "' has no password set.";
  1595. }
  1596. push( @generalrec,
  1597. "Set up a Password for user with the following SQL statement ( SET PASSWORD FOR 'user'\@'SpecificDNSorIp' = PASSWORD('secure_password'); )"
  1598. );
  1599. }
  1600. else {
  1601. goodprint "All database users have passwords assigned";
  1602. }
  1603. if ( mysql_version_ge( 5, 7 ) ) {
  1604. my $valPlugin = select_one(
  1605. "select count(*) from information_schema.plugins where PLUGIN_NAME='validate_password' AND PLUGIN_STATUS='ACTIVE'"
  1606. );
  1607. if ( $valPlugin >= 1 ) {
  1608. infoprint
  1609. "Bug #80860 MySQL 5.7: Avoid testing password when validate_password is activated";
  1610. return;
  1611. }
  1612. }
  1613. # Looking for User with user/ uppercase /capitalise user as password
  1614. @mysqlstatlist = select_array
  1615. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(user) OR CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(UPPER(user)) OR CAST($PASS_COLUMN_NAME as Binary) = PASSWORD(CONCAT(UPPER(LEFT(User, 1)), SUBSTRING(User, 2, LENGTH(User))))";
  1616. if (@mysqlstatlist) {
  1617. foreach my $line ( sort @mysqlstatlist ) {
  1618. chomp($line);
  1619. badprint "User '" . $line . "' has user name as password.";
  1620. }
  1621. push( @generalrec,
  1622. "Set up a Secure Password for user\@host ( SET PASSWORD FOR 'user'\@'SpecificDNSorIp' = PASSWORD('secure_password'); )"
  1623. );
  1624. }
  1625. @mysqlstatlist = select_array
  1626. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE HOST='%'";
  1627. if (@mysqlstatlist) {
  1628. foreach my $line ( sort @mysqlstatlist ) {
  1629. chomp($line);
  1630. badprint "User '" . $line
  1631. . "' does not specify hostname restrictions.";
  1632. }
  1633. push( @generalrec,
  1634. "Restrict Host for user\@% to user\@SpecificDNSorIp" );
  1635. }
  1636. unless ( -f $basic_password_files ) {
  1637. badprint "There is no basic password file list!";
  1638. return;
  1639. }
  1640. my @passwords = get_basic_passwords $basic_password_files;
  1641. infoprint "There are "
  1642. . scalar(@passwords)
  1643. . " basic passwords in the list.";
  1644. my $nbins = 0;
  1645. my $passreq;
  1646. if (@passwords) {
  1647. my $nbInterPass = 0;
  1648. foreach my $pass (@passwords) {
  1649. $nbInterPass++;
  1650. $pass =~ s/\s//g;
  1651. $pass =~ s/\'/\\\'/g;
  1652. chomp($pass);
  1653. # Looking for User with user/ uppercase /capitalise weak password
  1654. @mysqlstatlist =
  1655. select_array
  1656. "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE $PASS_COLUMN_NAME = PASSWORD('"
  1657. . $pass
  1658. . "') OR $PASS_COLUMN_NAME = PASSWORD(UPPER('"
  1659. . $pass
  1660. . "')) OR $PASS_COLUMN_NAME = PASSWORD(CONCAT(UPPER(LEFT('"
  1661. . $pass
  1662. . "', 1)), SUBSTRING('"
  1663. . $pass
  1664. . "', 2, LENGTH('"
  1665. . $pass . "'))))";
  1666. debugprint "There is " . scalar(@mysqlstatlist) . " items.";
  1667. if (@mysqlstatlist) {
  1668. foreach my $line (@mysqlstatlist) {
  1669. chomp($line);
  1670. badprint "User '" . $line
  1671. . "' is using weak password: $pass in a lower, upper or capitalize derivative version.";
  1672. $nbins++;
  1673. }
  1674. }
  1675. debugprint "$nbInterPass / " . scalar(@passwords)
  1676. if ( $nbInterPass % 1000 == 0 );
  1677. }
  1678. }
  1679. if ( $nbins > 0 ) {
  1680. push( @generalrec, $nbins . " user(s) used basic or weak password." );
  1681. }
  1682. }
  1683. sub get_replication_status {
  1684. subheaderprint "Replication Metrics";
  1685. infoprint "Galera Synchronous replication: " . $myvar{'have_galera'};
  1686. if ( scalar( keys %myslaves ) == 0 ) {
  1687. infoprint "No replication slave(s) for this server.";
  1688. }
  1689. else {
  1690. infoprint "This server is acting as master for "
  1691. . scalar( keys %myslaves )
  1692. . " server(s).";
  1693. }
  1694. infoprint "Binlog format: " . $myvar{'binlog_format'};
  1695. infoprint "XA support enabled: " . $myvar{'innodb_support_xa'};
  1696. infoprint "Semi synchronous replication Master: "
  1697. . (
  1698. defined( $myvar{'rpl_semi_sync_master_enabled'} )
  1699. ? $myvar{'rpl_semi_sync_master_enabled'}
  1700. : 'Not Activated'
  1701. );
  1702. infoprint "Semi synchronous replication Slave: "
  1703. . (
  1704. defined( $myvar{'rpl_semi_sync_slave_enabled'} )
  1705. ? $myvar{'rpl_semi_sync_slave_enabled'}
  1706. : 'Not Activated'
  1707. );
  1708. if ( scalar( keys %myrepl ) == 0 and scalar( keys %myslaves ) == 0 ) {
  1709. infoprint "This is a standalone server";
  1710. return;
  1711. }
  1712. if ( scalar( keys %myrepl ) == 0 ) {
  1713. infoprint
  1714. "No replication setup for this server or replication not started.";
  1715. return;
  1716. }
  1717. $result{'Replication'}{'status'} = \%myrepl;
  1718. my ($io_running) = $myrepl{'Slave_IO_Running'};
  1719. debugprint "IO RUNNING: $io_running ";
  1720. my ($sql_running) = $myrepl{'Slave_SQL_Running'};
  1721. debugprint "SQL RUNNING: $sql_running ";
  1722. my ($seconds_behind_master) = $myrepl{'Seconds_Behind_Master'};
  1723. debugprint "SECONDS : $seconds_behind_master ";
  1724. if ( defined($io_running)
  1725. and ( $io_running !~ /yes/i or $sql_running !~ /yes/i ) )
  1726. {
  1727. badprint
  1728. "This replication slave is not running but seems to be configured.";
  1729. }
  1730. if ( defined($io_running)
  1731. && $io_running =~ /yes/i
  1732. && $sql_running =~ /yes/i )
  1733. {
  1734. if ( $myvar{'read_only'} eq 'OFF' ) {
  1735. badprint
  1736. "This replication slave is running with the read_only option disabled.";
  1737. }
  1738. else {
  1739. goodprint
  1740. "This replication slave is running with the read_only option enabled.";
  1741. }
  1742. if ( $seconds_behind_master > 0 ) {
  1743. badprint
  1744. "This replication slave is lagging and slave has $seconds_behind_master second(s) behind master host.";
  1745. }
  1746. else {
  1747. goodprint "This replication slave is up to date with master.";
  1748. }
  1749. }
  1750. }
  1751. sub validate_mysql_version {
  1752. ( $mysqlvermajor, $mysqlverminor, $mysqlvermicro ) =
  1753. $myvar{'version'} =~ /^(\d+)(?:\.(\d+)|)(?:\.(\d+)|)/;
  1754. $mysqlverminor ||= 0;
  1755. $mysqlvermicro ||= 0;
  1756. if ( !mysql_version_ge( 5, 1 ) ) {
  1757. badprint "Your MySQL version "
  1758. . $myvar{'version'}
  1759. . " is EOL software! Upgrade soon!";
  1760. }
  1761. elsif ( ( mysql_version_ge(6) and mysql_version_le(9) )
  1762. or mysql_version_ge(12) )
  1763. {
  1764. badprint "Currently running unsupported MySQL version "
  1765. . $myvar{'version'} . "";
  1766. }
  1767. else {
  1768. goodprint "Currently running supported MySQL version "
  1769. . $myvar{'version'} . "";
  1770. }
  1771. }
  1772. # Checks if MySQL version is equal to (major, minor, micro)
  1773. sub mysql_version_eq {
  1774. my ( $maj, $min, $mic ) = @_;
  1775. return int($mysqlvermajor) == int($maj) if ( !defined($min) && !defined($mic));
  1776. return int($mysqlvermajor) == int($maj)&& int($mysqlverminor) == int($min) if ( !defined($mic));
  1777. return ( int($mysqlvermajor) == int($maj)
  1778. && int($mysqlverminor) == int($min)
  1779. && int($mysqlvermicro) == int($mic) );
  1780. }
  1781. # Checks if MySQL version is greater than equal to (major, minor, micro)
  1782. sub mysql_version_ge {
  1783. my ( $maj, $min, $mic ) = @_;
  1784. $min ||= 0;
  1785. $mic ||= 0;
  1786. return
  1787. int($mysqlvermajor) > int($maj)
  1788. || ( int($mysqlvermajor) == int($maj) && int($mysqlverminor) > int($min) )
  1789. || ( int($mysqlvermajor) == int($maj)
  1790. && int($mysqlverminor) == int($min)
  1791. && int($mysqlvermicro) >= int($mic) );
  1792. }
  1793. # Checks if MySQL version is lower than equal to (major, minor, micro)
  1794. sub mysql_version_le {
  1795. my ( $maj, $min, $mic ) = @_;
  1796. $min ||= 0;
  1797. $mic ||= 0;
  1798. return
  1799. int($mysqlvermajor) < int($maj)
  1800. || ( int($mysqlvermajor) == int($maj) && int($mysqlverminor) < int($min) )
  1801. || ( int($mysqlvermajor) == int($maj)
  1802. && int($mysqlverminor) == int($min)
  1803. && int($mysqlvermicro) <= int($mic) );
  1804. }
  1805. # Checks if MySQL micro version is lower than equal to (major, minor, micro)
  1806. sub mysql_micro_version_le {
  1807. my ( $maj, $min, $mic ) = @_;
  1808. return $mysqlvermajor == $maj
  1809. && ( $mysqlverminor == $min
  1810. && $mysqlvermicro <= $mic );
  1811. }
  1812. # Checks for 32-bit boxes with more than 2GB of RAM
  1813. my ($arch);
  1814. sub check_architecture {
  1815. if ( $doremote eq 1 ) { return; }
  1816. if ( `uname` =~ /SunOS/ && `isainfo -b` =~ /64/ ) {
  1817. $arch = 64;
  1818. goodprint "Operating on 64-bit architecture";
  1819. }
  1820. elsif ( `uname` !~ /SunOS/ && `uname -m` =~ /(64|s390x)/ ) {
  1821. $arch = 64;
  1822. goodprint "Operating on 64-bit architecture";
  1823. }
  1824. elsif ( `uname` =~ /AIX/ && `bootinfo -K` =~ /64/ ) {
  1825. $arch = 64;
  1826. goodprint "Operating on 64-bit architecture";
  1827. }
  1828. elsif ( `uname` =~ /NetBSD|OpenBSD/ && `sysctl -b hw.machine` =~ /64/ ) {
  1829. $arch = 64;
  1830. goodprint "Operating on 64-bit architecture";
  1831. }
  1832. elsif ( `uname` =~ /FreeBSD/ && `sysctl -b hw.machine_arch` =~ /64/ ) {
  1833. $arch = 64;
  1834. goodprint "Operating on 64-bit architecture";
  1835. }
  1836. elsif ( `uname` =~ /Darwin/ && `uname -m` =~ /Power Macintosh/ ) {
  1837. # Darwin box.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu1228.15.4~1/RELEASE_PPC Power Macintosh
  1838. $arch = 64;
  1839. goodprint "Operating on 64-bit architecture";
  1840. }
  1841. elsif ( `uname` =~ /Darwin/ && `uname -m` =~ /x86_64/ ) {
  1842. # Darwin gibas.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64
  1843. $arch = 64;
  1844. goodprint "Operating on 64-bit architecture";
  1845. }
  1846. else {
  1847. $arch = 32;
  1848. if ( $physical_memory > 2147483648 ) {
  1849. badprint
  1850. "Switch to 64-bit OS - MySQL cannot currently use all of your RAM";
  1851. }
  1852. else {
  1853. goodprint "Operating on 32-bit architecture with less than 2GB RAM";
  1854. }
  1855. }
  1856. $result{'OS'}{'Architecture'} = "$arch bits";
  1857. }
  1858. # Start up a ton of storage engine counts/statistics
  1859. my ( %enginestats, %enginecount, $fragtables );
  1860. sub check_storage_engines {
  1861. if ( $opt{skipsize} eq 1 ) {
  1862. subheaderprint "Storage Engine Statistics";
  1863. infoprint "Skipped due to --skipsize option";
  1864. return;
  1865. }
  1866. subheaderprint "Storage Engine Statistics";
  1867. my $engines;
  1868. if ( mysql_version_ge( 5, 5 ) ) {
  1869. my @engineresults = select_array
  1870. "SELECT ENGINE,SUPPORT FROM information_schema.ENGINES ORDER BY ENGINE ASC";
  1871. foreach my $line (@engineresults) {
  1872. my ( $engine, $engineenabled );
  1873. ( $engine, $engineenabled ) = $line =~ /([a-zA-Z_]*)\s+([a-zA-Z]+)/;
  1874. $result{'Engine'}{$engine}{'Enabled'} = $engineenabled;
  1875. $engines .=
  1876. ( $engineenabled eq "YES" || $engineenabled eq "DEFAULT" )
  1877. ? greenwrap "+" . $engine . " "
  1878. : redwrap "-" . $engine . " ";
  1879. }
  1880. }
  1881. elsif ( mysql_version_ge( 5, 1, 5 ) ) {
  1882. my @engineresults = select_array
  1883. "SELECT ENGINE,SUPPORT FROM information_schema.ENGINES WHERE ENGINE NOT IN ('performance_schema','MyISAM','MERGE','MEMORY') ORDER BY ENGINE ASC";
  1884. foreach my $line (@engineresults) {
  1885. my ( $engine, $engineenabled );
  1886. ( $engine, $engineenabled ) = $line =~ /([a-zA-Z_]*)\s+([a-zA-Z]+)/;
  1887. $result{'Engine'}{$engine}{'Enabled'} = $engineenabled;
  1888. $engines .=
  1889. ( $engineenabled eq "YES" || $engineenabled eq "DEFAULT" )
  1890. ? greenwrap "+" . $engine . " "
  1891. : redwrap "-" . $engine . " ";
  1892. }
  1893. }
  1894. else {
  1895. $engines .=
  1896. ( defined $myvar{'have_archive'} && $myvar{'have_archive'} eq "YES" )
  1897. ? greenwrap "+Archive "
  1898. : redwrap "-Archive ";
  1899. $engines .=
  1900. ( defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES" )
  1901. ? greenwrap "+BDB "
  1902. : redwrap "-BDB ";
  1903. $engines .=
  1904. ( defined $myvar{'have_federated_engine'}
  1905. && $myvar{'have_federated_engine'} eq "YES" )
  1906. ? greenwrap "+Federated "
  1907. : redwrap "-Federated ";
  1908. $engines .=
  1909. ( defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES" )
  1910. ? greenwrap "+InnoDB "
  1911. : redwrap "-InnoDB ";
  1912. $engines .=
  1913. ( defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES" )
  1914. ? greenwrap "+ISAM "
  1915. : redwrap "-ISAM ";
  1916. $engines .=
  1917. ( defined $myvar{'have_ndbcluster'}
  1918. && $myvar{'have_ndbcluster'} eq "YES" )
  1919. ? greenwrap "+NDBCluster "
  1920. : redwrap "-NDBCluster ";
  1921. }
  1922. my @dblist = grep { $_ ne 'lost+found' } select_array "SHOW DATABASES";
  1923. $result{'Databases'}{'List'} = [@dblist];
  1924. infoprint "Status: $engines";
  1925. if ( mysql_version_ge( 5, 1, 5 ) ) {
  1926. # MySQL 5 servers can have table sizes calculated quickly from information schema
  1927. my @templist = select_array
  1928. "SELECT ENGINE,SUM(DATA_LENGTH+INDEX_LENGTH),COUNT(ENGINE),SUM(DATA_LENGTH),SUM(INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;";
  1929. my ( $engine, $size, $count, $dsize, $isize );
  1930. foreach my $line (@templist) {
  1931. ( $engine, $size, $count, $dsize, $isize ) =
  1932. $line =~ /([a-zA-Z_]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/;
  1933. debugprint "Engine Found: $engine";
  1934. next unless ( defined($engine) );
  1935. $size = 0 unless defined($size);
  1936. $isize = 0 unless defined($isize);
  1937. $dsize = 0 unless defined($dsize);
  1938. $count = 0 unless defined($count);
  1939. $enginestats{$engine} = $size;
  1940. $enginecount{$engine} = $count;
  1941. $result{'Engine'}{$engine}{'Table Number'} = $count;
  1942. $result{'Engine'}{$engine}{'Total Size'} = $size;
  1943. $result{'Engine'}{$engine}{'Data Size'} = $dsize;
  1944. $result{'Engine'}{$engine}{'Index Size'} = $isize;
  1945. }
  1946. my $not_innodb = '';
  1947. if ( not defined $result{'Variables'}{'innodb_file_per_table'} ) {
  1948. $not_innodb = "AND NOT ENGINE='InnoDB'";
  1949. }
  1950. elsif ( $result{'Variables'}{'innodb_file_per_table'} eq 'OFF' ) {
  1951. $not_innodb = "AND NOT ENGINE='InnoDB'";
  1952. }
  1953. $result{'Tables'}{'Fragmented tables'} =
  1954. [ select_array
  1955. "SELECT CONCAT(CONCAT(TABLE_SCHEMA, '.'), TABLE_NAME),DATA_FREE FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','performance_schema', 'mysql') AND DATA_LENGTH/1024/1024>100 AND DATA_FREE*100/(DATA_LENGTH+INDEX_LENGTH+DATA_FREE) > 10 AND NOT ENGINE='MEMORY' $not_innodb"
  1956. ];
  1957. $fragtables = scalar @{ $result{'Tables'}{'Fragmented tables'} };
  1958. }
  1959. else {
  1960. # MySQL < 5 servers take a lot of work to get table sizes
  1961. my @tblist;
  1962. # Now we build a database list, and loop through it to get storage engine stats for tables
  1963. foreach my $db (@dblist) {
  1964. chomp($db);
  1965. if ( $db eq "information_schema"
  1966. or $db eq "performance_schema"
  1967. or $db eq "mysql"
  1968. or $db eq "lost+found" )
  1969. {
  1970. next;
  1971. }
  1972. my @ixs = ( 1, 6, 9 );
  1973. if ( !mysql_version_ge( 4, 1 ) ) {
  1974. # MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
  1975. @ixs = ( 1, 5, 8 );
  1976. }
  1977. push( @tblist,
  1978. map { [ (split)[@ixs] ] }
  1979. select_array "SHOW TABLE STATUS FROM \\\`$db\\\`" );
  1980. }
  1981. # Parse through the table list to generate storage engine counts/statistics
  1982. $fragtables = 0;
  1983. foreach my $tbl (@tblist) {
  1984. debugprint "Data dump " . Dumper(@$tbl);
  1985. my ( $engine, $size, $datafree ) = @$tbl;
  1986. next if $engine eq 'NULL';
  1987. $size = 0 if $size eq 'NULL';
  1988. $datafree = 0 if $datafree eq 'NULL';
  1989. if ( defined $enginestats{$engine} ) {
  1990. $enginestats{$engine} += $size;
  1991. $enginecount{$engine} += 1;
  1992. }
  1993. else {
  1994. $enginestats{$engine} = $size;
  1995. $enginecount{$engine} = 1;
  1996. }
  1997. if ( $datafree > 0 ) {
  1998. $fragtables++;
  1999. }
  2000. }
  2001. }
  2002. while ( my ( $engine, $size ) = each(%enginestats) ) {
  2003. infoprint "Data in $engine tables: "
  2004. . hr_bytes($size)
  2005. . " (Tables: "
  2006. . $enginecount{$engine} . ")" . "";
  2007. }
  2008. # If the storage engine isn't being used, recommend it to be disabled
  2009. if ( !defined $enginestats{'InnoDB'}
  2010. && defined $myvar{'have_innodb'}
  2011. && $myvar{'have_innodb'} eq "YES" )
  2012. {
  2013. badprint "InnoDB is enabled but isn't being used";
  2014. push( @generalrec,
  2015. "Add skip-innodb to MySQL configuration to disable InnoDB" );
  2016. }
  2017. if ( !defined $enginestats{'BerkeleyDB'}
  2018. && defined $myvar{'have_bdb'}
  2019. && $myvar{'have_bdb'} eq "YES" )
  2020. {
  2021. badprint "BDB is enabled but isn't being used";
  2022. push( @generalrec,
  2023. "Add skip-bdb to MySQL configuration to disable BDB" );
  2024. }
  2025. if ( !defined $enginestats{'ISAM'}
  2026. && defined $myvar{'have_isam'}
  2027. && $myvar{'have_isam'} eq "YES" )
  2028. {
  2029. badprint "MYISAM is enabled but isn't being used";
  2030. push( @generalrec,
  2031. "Add skip-isam to MySQL configuration to disable ISAM (MySQL > 4.1.0)"
  2032. );
  2033. }
  2034. # Fragmented tables
  2035. if ( $fragtables > 0 ) {
  2036. badprint "Total fragmented tables: $fragtables";
  2037. push( @generalrec,
  2038. "Run OPTIMIZE TABLE to defragment tables for better performance" );
  2039. my $total_free = 0;
  2040. foreach my $table_line ( @{ $result{'Tables'}{'Fragmented tables'} } ) {
  2041. my ( $full_table_name, $data_free ) = split( /\s+/, $table_line );
  2042. $data_free = 0 if ( !defined($data_free) or $data_free eq '' );
  2043. $data_free = $data_free / 1024 / 1024;
  2044. $total_free += $data_free;
  2045. my ( $table_schema, $table_name ) = split( /\./, $full_table_name );
  2046. push( @generalrec,
  2047. " OPTIMIZE TABLE `$table_schema`.`$table_name`; -- can free $data_free MB"
  2048. );
  2049. }
  2050. push( @generalrec,
  2051. "Total freed space after theses OPTIMIZE TABLE : $total_free Mb" );
  2052. }
  2053. else {
  2054. goodprint "Total fragmented tables: $fragtables";
  2055. }
  2056. # Auto increments
  2057. my %tblist;
  2058. # Find the maximum integer
  2059. my $maxint = select_one "SELECT ~0";
  2060. $result{'MaxInt'} = $maxint;
  2061. # Now we use a database list, and loop through it to get storage engine stats for tables
  2062. foreach my $db (@dblist) {
  2063. chomp($db);
  2064. if ( !$tblist{$db} ) {
  2065. $tblist{$db} = ();
  2066. }
  2067. if ( $db eq "information_schema" ) { next; }
  2068. my @ia = ( 0, 10 );
  2069. if ( !mysql_version_ge( 4, 1 ) ) {
  2070. # MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column
  2071. @ia = ( 0, 9 );
  2072. }
  2073. push(
  2074. @{ $tblist{$db} },
  2075. map { [ (split)[@ia] ] }
  2076. select_array "SHOW TABLE STATUS FROM \\\`$db\\\`"
  2077. );
  2078. }
  2079. my @dbnames = keys %tblist;
  2080. foreach my $db (@dbnames) {
  2081. foreach my $tbl ( @{ $tblist{$db} } ) {
  2082. my ( $name, $autoincrement ) = @$tbl;
  2083. if ( $autoincrement =~ /^\d+?$/ ) {
  2084. my $percent = percentage( $autoincrement, $maxint );
  2085. $result{'PctAutoIncrement'}{"$db.$name"} = $percent;
  2086. if ( $percent >= 75 ) {
  2087. badprint
  2088. "Table '$db.$name' has an autoincrement value near max capacity ($percent%)";
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. my %mycalc;
  2095. sub calculations {
  2096. if ( $mystat{'Questions'} < 1 ) {
  2097. badprint
  2098. "Your server has not answered any queries - cannot continue...";
  2099. exit 2;
  2100. }
  2101. # Per-thread memory
  2102. if ( mysql_version_ge(4) ) {
  2103. $mycalc{'per_thread_buffers'} =
  2104. $myvar{'read_buffer_size'} +
  2105. $myvar{'read_rnd_buffer_size'} +
  2106. $myvar{'sort_buffer_size'} +
  2107. $myvar{'thread_stack'} +
  2108. $myvar{'join_buffer_size'};
  2109. }
  2110. else {
  2111. $mycalc{'per_thread_buffers'} =
  2112. $myvar{'record_buffer'} +
  2113. $myvar{'record_rnd_buffer'} +
  2114. $myvar{'sort_buffer'} +
  2115. $myvar{'thread_stack'} +
  2116. $myvar{'join_buffer_size'};
  2117. }
  2118. $mycalc{'total_per_thread_buffers'} =
  2119. $mycalc{'per_thread_buffers'} * $myvar{'max_connections'};
  2120. $mycalc{'max_total_per_thread_buffers'} =
  2121. $mycalc{'per_thread_buffers'} * $mystat{'Max_used_connections'};
  2122. # Server-wide memory
  2123. $mycalc{'max_tmp_table_size'} =
  2124. ( $myvar{'tmp_table_size'} > $myvar{'max_heap_table_size'} )
  2125. ? $myvar{'max_heap_table_size'}
  2126. : $myvar{'tmp_table_size'};
  2127. $mycalc{'server_buffers'} =
  2128. $myvar{'key_buffer_size'} + $mycalc{'max_tmp_table_size'};
  2129. $mycalc{'server_buffers'} +=
  2130. ( defined $myvar{'innodb_buffer_pool_size'} )
  2131. ? $myvar{'innodb_buffer_pool_size'}
  2132. : 0;
  2133. $mycalc{'server_buffers'} +=
  2134. ( defined $myvar{'innodb_additional_mem_pool_size'} )
  2135. ? $myvar{'innodb_additional_mem_pool_size'}
  2136. : 0;
  2137. $mycalc{'server_buffers'} +=
  2138. ( defined $myvar{'innodb_log_buffer_size'} )
  2139. ? $myvar{'innodb_log_buffer_size'}
  2140. : 0;
  2141. $mycalc{'server_buffers'} +=
  2142. ( defined $myvar{'query_cache_size'} ) ? $myvar{'query_cache_size'} : 0;
  2143. $mycalc{'server_buffers'} +=
  2144. ( defined $myvar{'aria_pagecache_buffer_size'} )
  2145. ? $myvar{'aria_pagecache_buffer_size'}
  2146. : 0;
  2147. # Global memory
  2148. # Max used memory is memory used by MySQL based on Max_used_connections
  2149. # This is the max memory used theoretically calculated with the max concurrent connection number reached by mysql
  2150. $mycalc{'max_used_memory'} =
  2151. $mycalc{'server_buffers'} +
  2152. $mycalc{"max_total_per_thread_buffers"} +
  2153. get_pf_memory();
  2154. # + get_gcache_memory();
  2155. $mycalc{'pct_max_used_memory'} =
  2156. percentage( $mycalc{'max_used_memory'}, $physical_memory );
  2157. # Total possible memory is memory needed by MySQL based on max_connections
  2158. # This is the max memory MySQL can theoretically used if all connections allowed has opened by mysql
  2159. $mycalc{'max_peak_memory'} =
  2160. $mycalc{'server_buffers'} +
  2161. $mycalc{'total_per_thread_buffers'} +
  2162. get_pf_memory();
  2163. # + get_gcache_memory();
  2164. $mycalc{'pct_max_physical_memory'} =
  2165. percentage( $mycalc{'max_peak_memory'}, $physical_memory );
  2166. debugprint "Max Used Memory: "
  2167. . hr_bytes( $mycalc{'max_used_memory'} ) . "";
  2168. debugprint "Max Used Percentage RAM: "
  2169. . $mycalc{'pct_max_used_memory'} . "%";
  2170. debugprint "Max Peak Memory: "
  2171. . hr_bytes( $mycalc{'max_peak_memory'} ) . "";
  2172. debugprint "Max Peak Percentage RAM: "
  2173. . $mycalc{'pct_max_physical_memory'} . "%";
  2174. # Slow queries
  2175. $mycalc{'pct_slow_queries'} =
  2176. int( ( $mystat{'Slow_queries'} / $mystat{'Questions'} ) * 100 );
  2177. # Connections
  2178. $mycalc{'pct_connections_used'} = int(
  2179. ( $mystat{'Max_used_connections'} / $myvar{'max_connections'} ) * 100 );
  2180. $mycalc{'pct_connections_used'} =
  2181. ( $mycalc{'pct_connections_used'} > 100 )
  2182. ? 100
  2183. : $mycalc{'pct_connections_used'};
  2184. # Aborted Connections
  2185. $mycalc{'pct_connections_aborted'} =
  2186. percentage( $mystat{'Aborted_connects'}, $mystat{'Connections'} );
  2187. debugprint "Aborted_connects: " . $mystat{'Aborted_connects'} . "";
  2188. debugprint "Connections: " . $mystat{'Connections'} . "";
  2189. debugprint "pct_connections_aborted: "
  2190. . $mycalc{'pct_connections_aborted'} . "";
  2191. # Key buffers
  2192. if ( mysql_version_ge( 4, 1 ) && $myvar{'key_buffer_size'} > 0 ) {
  2193. $mycalc{'pct_key_buffer_used'} = sprintf(
  2194. "%.1f",
  2195. (
  2196. 1 - (
  2197. (
  2198. $mystat{'Key_blocks_unused'} *
  2199. $myvar{'key_cache_block_size'}
  2200. ) / $myvar{'key_buffer_size'}
  2201. )
  2202. ) * 100
  2203. );
  2204. }
  2205. else {
  2206. $mycalc{'pct_key_buffer_used'} = 0;
  2207. }
  2208. if ( $mystat{'Key_read_requests'} > 0 ) {
  2209. $mycalc{'pct_keys_from_mem'} = sprintf(
  2210. "%.1f",
  2211. (
  2212. 100 - (
  2213. ( $mystat{'Key_reads'} / $mystat{'Key_read_requests'} ) *
  2214. 100
  2215. )
  2216. )
  2217. );
  2218. }
  2219. else {
  2220. $mycalc{'pct_keys_from_mem'} = 0;
  2221. }
  2222. if ( defined $mystat{'Aria_pagecache_read_requests'}
  2223. && $mystat{'Aria_pagecache_read_requests'} > 0 )
  2224. {
  2225. $mycalc{'pct_aria_keys_from_mem'} = sprintf(
  2226. "%.1f",
  2227. (
  2228. 100 - (
  2229. (
  2230. $mystat{'Aria_pagecache_reads'} /
  2231. $mystat{'Aria_pagecache_read_requests'}
  2232. ) * 100
  2233. )
  2234. )
  2235. );
  2236. }
  2237. else {
  2238. $mycalc{'pct_aria_keys_from_mem'} = 0;
  2239. }
  2240. if ( $mystat{'Key_write_requests'} > 0 ) {
  2241. $mycalc{'pct_wkeys_from_mem'} = sprintf( "%.1f",
  2242. ( ( $mystat{'Key_writes'} / $mystat{'Key_write_requests'} ) * 100 )
  2243. );
  2244. }
  2245. else {
  2246. $mycalc{'pct_wkeys_from_mem'} = 0;
  2247. }
  2248. if ( $doremote eq 0 and !mysql_version_ge(5) ) {
  2249. my $size = 0;
  2250. $size += (split)[0]
  2251. for
  2252. `find $myvar{'datadir'} -name "*.MYI" 2>&1 | xargs du -L $duflags 2>&1`;
  2253. $mycalc{'total_myisam_indexes'} = $size;
  2254. $mycalc{'total_aria_indexes'} = 0;
  2255. }
  2256. elsif ( mysql_version_ge(5) ) {
  2257. $mycalc{'total_myisam_indexes'} = select_one
  2258. "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';";
  2259. $mycalc{'total_aria_indexes'} = select_one
  2260. "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'Aria';";
  2261. }
  2262. if ( defined $mycalc{'total_myisam_indexes'}
  2263. and $mycalc{'total_myisam_indexes'} == 0 )
  2264. {
  2265. $mycalc{'total_myisam_indexes'} = "fail";
  2266. }
  2267. elsif ( defined $mycalc{'total_myisam_indexes'} ) {
  2268. chomp( $mycalc{'total_myisam_indexes'} );
  2269. }
  2270. if ( defined $mycalc{'total_aria_indexes'}
  2271. and $mycalc{'total_aria_indexes'} == 0 )
  2272. {
  2273. $mycalc{'total_aria_indexes'} = 1;
  2274. }
  2275. elsif ( defined $mycalc{'total_aria_indexes'} ) {
  2276. chomp( $mycalc{'total_aria_indexes'} );
  2277. }
  2278. # Query cache
  2279. if ( mysql_version_ge(8) and mysql_version_le(10) ) {
  2280. $mycalc{'query_cache_efficiency'} = 0;
  2281. } elsif ( mysql_version_ge(4) ) {
  2282. $mycalc{'query_cache_efficiency'} = sprintf(
  2283. "%.1f",
  2284. (
  2285. $mystat{'Qcache_hits'} /
  2286. ( $mystat{'Com_select'} + $mystat{'Qcache_hits'} )
  2287. ) * 100
  2288. );
  2289. if ( $myvar{'query_cache_size'} ) {
  2290. $mycalc{'pct_query_cache_used'} = sprintf(
  2291. "%.1f",
  2292. 100 - (
  2293. $mystat{'Qcache_free_memory'} / $myvar{'query_cache_size'}
  2294. ) * 100
  2295. );
  2296. }
  2297. if ( $mystat{'Qcache_lowmem_prunes'} == 0 ) {
  2298. $mycalc{'query_cache_prunes_per_day'} = 0;
  2299. }
  2300. else {
  2301. $mycalc{'query_cache_prunes_per_day'} = int(
  2302. $mystat{'Qcache_lowmem_prunes'} / ( $mystat{'Uptime'} / 86400 )
  2303. );
  2304. }
  2305. }
  2306. # Sorting
  2307. $mycalc{'total_sorts'} = $mystat{'Sort_scan'} + $mystat{'Sort_range'};
  2308. if ( $mycalc{'total_sorts'} > 0 ) {
  2309. $mycalc{'pct_temp_sort_table'} = int(
  2310. ( $mystat{'Sort_merge_passes'} / $mycalc{'total_sorts'} ) * 100 );
  2311. }
  2312. # Joins
  2313. $mycalc{'joins_without_indexes'} =
  2314. $mystat{'Select_range_check'} + $mystat{'Select_full_join'};
  2315. $mycalc{'joins_without_indexes_per_day'} =
  2316. int( $mycalc{'joins_without_indexes'} / ( $mystat{'Uptime'} / 86400 ) );
  2317. # Temporary tables
  2318. if ( $mystat{'Created_tmp_tables'} > 0 ) {
  2319. if ( $mystat{'Created_tmp_disk_tables'} > 0 ) {
  2320. $mycalc{'pct_temp_disk'} = int(
  2321. (
  2322. $mystat{'Created_tmp_disk_tables'} /
  2323. $mystat{'Created_tmp_tables'}
  2324. ) * 100
  2325. );
  2326. }
  2327. else {
  2328. $mycalc{'pct_temp_disk'} = 0;
  2329. }
  2330. }
  2331. # Table cache
  2332. if ( $mystat{'Opened_tables'} > 0 ) {
  2333. $mycalc{'table_cache_hit_rate'} =
  2334. int( $mystat{'Open_tables'} * 100 / $mystat{'Opened_tables'} );
  2335. }
  2336. else {
  2337. $mycalc{'table_cache_hit_rate'} = 100;
  2338. }
  2339. # Open files
  2340. if ( $myvar{'open_files_limit'} > 0 ) {
  2341. $mycalc{'pct_files_open'} =
  2342. int( $mystat{'Open_files'} * 100 / $myvar{'open_files_limit'} );
  2343. }
  2344. # Table locks
  2345. if ( $mystat{'Table_locks_immediate'} > 0 ) {
  2346. if ( $mystat{'Table_locks_waited'} == 0 ) {
  2347. $mycalc{'pct_table_locks_immediate'} = 100;
  2348. }
  2349. else {
  2350. $mycalc{'pct_table_locks_immediate'} = int(
  2351. $mystat{'Table_locks_immediate'} * 100 / (
  2352. $mystat{'Table_locks_waited'} +
  2353. $mystat{'Table_locks_immediate'}
  2354. )
  2355. );
  2356. }
  2357. }
  2358. # Thread cache
  2359. $mycalc{'thread_cache_hit_rate'} =
  2360. int( 100 -
  2361. ( ( $mystat{'Threads_created'} / $mystat{'Connections'} ) * 100 ) );
  2362. # Other
  2363. if ( $mystat{'Connections'} > 0 ) {
  2364. $mycalc{'pct_aborted_connections'} =
  2365. int( ( $mystat{'Aborted_connects'} / $mystat{'Connections'} ) * 100 );
  2366. }
  2367. if ( $mystat{'Questions'} > 0 ) {
  2368. $mycalc{'total_reads'} = $mystat{'Com_select'};
  2369. $mycalc{'total_writes'} =
  2370. $mystat{'Com_delete'} +
  2371. $mystat{'Com_insert'} +
  2372. $mystat{'Com_update'} +
  2373. $mystat{'Com_replace'};
  2374. if ( $mycalc{'total_reads'} == 0 ) {
  2375. $mycalc{'pct_reads'} = 0;
  2376. $mycalc{'pct_writes'} = 100;
  2377. }
  2378. else {
  2379. $mycalc{'pct_reads'} = int(
  2380. (
  2381. $mycalc{'total_reads'} /
  2382. ( $mycalc{'total_reads'} + $mycalc{'total_writes'} )
  2383. ) * 100
  2384. );
  2385. $mycalc{'pct_writes'} = 100 - $mycalc{'pct_reads'};
  2386. }
  2387. }
  2388. # InnoDB
  2389. if ( $myvar{'have_innodb'} eq "YES" ) {
  2390. $mycalc{'innodb_log_size_pct'} =
  2391. ( $myvar{'innodb_log_file_size'} *
  2392. $myvar{'innodb_log_files_in_group'} * 100 /
  2393. $myvar{'innodb_buffer_pool_size'} );
  2394. }
  2395. # InnoDB Buffer pool read cache efficiency
  2396. (
  2397. $mystat{'Innodb_buffer_pool_read_requests'},
  2398. $mystat{'Innodb_buffer_pool_reads'}
  2399. )
  2400. = ( 1, 1 )
  2401. unless defined $mystat{'Innodb_buffer_pool_reads'};
  2402. $mycalc{'pct_read_efficiency'} = percentage(
  2403. (
  2404. $mystat{'Innodb_buffer_pool_read_requests'} -
  2405. $mystat{'Innodb_buffer_pool_reads'}
  2406. ),
  2407. $mystat{'Innodb_buffer_pool_read_requests'}
  2408. ) if defined $mystat{'Innodb_buffer_pool_read_requests'};
  2409. debugprint "pct_read_efficiency: " . $mycalc{'pct_read_efficiency'} . "";
  2410. debugprint "Innodb_buffer_pool_reads: "
  2411. . $mystat{'Innodb_buffer_pool_reads'} . "";
  2412. debugprint "Innodb_buffer_pool_read_requests: "
  2413. . $mystat{'Innodb_buffer_pool_read_requests'} . "";
  2414. # InnoDB log write cache efficiency
  2415. ( $mystat{'Innodb_log_write_requests'}, $mystat{'Innodb_log_writes'} ) =
  2416. ( 1, 1 )
  2417. unless defined $mystat{'Innodb_log_writes'};
  2418. $mycalc{'pct_write_efficiency'} = percentage(
  2419. ( $mystat{'Innodb_log_write_requests'} - $mystat{'Innodb_log_writes'} ),
  2420. $mystat{'Innodb_log_write_requests'}
  2421. ) if defined $mystat{'Innodb_log_write_requests'};
  2422. debugprint "pct_write_efficiency: " . $mycalc{'pct_write_efficiency'} . "";
  2423. debugprint "Innodb_log_writes: " . $mystat{'Innodb_log_writes'} . "";
  2424. debugprint "Innodb_log_write_requests: "
  2425. . $mystat{'Innodb_log_write_requests'} . "";
  2426. $mycalc{'pct_innodb_buffer_used'} = percentage(
  2427. (
  2428. $mystat{'Innodb_buffer_pool_pages_total'} -
  2429. $mystat{'Innodb_buffer_pool_pages_free'}
  2430. ),
  2431. $mystat{'Innodb_buffer_pool_pages_total'}
  2432. ) if defined $mystat{'Innodb_buffer_pool_pages_total'};
  2433. # Binlog Cache
  2434. if ( $myvar{'log_bin'} ne 'OFF' ) {
  2435. $mycalc{'pct_binlog_cache'} = percentage(
  2436. $mystat{'Binlog_cache_use'} - $mystat{'Binlog_cache_disk_use'},
  2437. $mystat{'Binlog_cache_use'} );
  2438. }
  2439. }
  2440. sub mysql_stats {
  2441. subheaderprint "Performance Metrics";
  2442. # Show uptime, queries per second, connections, traffic stats
  2443. my $qps;
  2444. if ( $mystat{'Uptime'} > 0 ) {
  2445. $qps = sprintf( "%.3f", $mystat{'Questions'} / $mystat{'Uptime'} );
  2446. }
  2447. push( @generalrec,
  2448. "MySQL was started within the last 24 hours - recommendations may be inaccurate"
  2449. ) if ( $mystat{'Uptime'} < 86400 );
  2450. infoprint "Up for: "
  2451. . pretty_uptime( $mystat{'Uptime'} ) . " ("
  2452. . hr_num( $mystat{'Questions'} ) . " q ["
  2453. . hr_num($qps)
  2454. . " qps], "
  2455. . hr_num( $mystat{'Connections'} )
  2456. . " conn," . " TX: "
  2457. . hr_bytes_rnd( $mystat{'Bytes_sent'} )
  2458. . ", RX: "
  2459. . hr_bytes_rnd( $mystat{'Bytes_received'} ) . ")";
  2460. infoprint "Reads / Writes: "
  2461. . $mycalc{'pct_reads'} . "% / "
  2462. . $mycalc{'pct_writes'} . "%";
  2463. # Binlog Cache
  2464. if ( $myvar{'log_bin'} eq 'OFF' ) {
  2465. infoprint "Binary logging is disabled";
  2466. }
  2467. else {
  2468. infoprint "Binary logging is enabled (GTID MODE: "
  2469. . ( defined( $myvar{'gtid_mode'} ) ? $myvar{'gtid_mode'} : "OFF" )
  2470. . ")";
  2471. }
  2472. # Memory usage
  2473. infoprint "Physical Memory : " . hr_bytes($physical_memory);
  2474. infoprint "Max MySQL memory : " . hr_bytes( $mycalc{'max_peak_memory'} );
  2475. infoprint "Other process memory: " . hr_bytes( get_other_process_memory() );
  2476. #print hr_bytes( $mycalc{'server_buffers'} );
  2477. infoprint "Total buffers: "
  2478. . hr_bytes( $mycalc{'server_buffers'} )
  2479. . " global + "
  2480. . hr_bytes( $mycalc{'per_thread_buffers'} )
  2481. . " per thread ($myvar{'max_connections'} max threads)";
  2482. infoprint "P_S Max memory usage: " . hr_bytes_rnd( get_pf_memory() );
  2483. $result{'P_S'}{'memory'} = get_other_process_memory();
  2484. $result{'P_S'}{'pretty_memory'} =
  2485. hr_bytes_rnd( get_other_process_memory() );
  2486. infoprint "Galera GCache Max memory usage: "
  2487. . hr_bytes_rnd( get_gcache_memory() );
  2488. $result{'Galera'}{'GCache'}{'memory'} = get_gcache_memory();
  2489. $result{'Galera'}{'GCache'}{'pretty_memory'} =
  2490. hr_bytes_rnd( get_gcache_memory() );
  2491. if ( $opt{buffers} ne 0 ) {
  2492. infoprint "Global Buffers";
  2493. infoprint " +-- Key Buffer: "
  2494. . hr_bytes( $myvar{'key_buffer_size'} ) . "";
  2495. infoprint " +-- Max Tmp Table: "
  2496. . hr_bytes( $mycalc{'max_tmp_table_size'} ) . "";
  2497. if ( defined $myvar{'query_cache_type'} ) {
  2498. infoprint "Query Cache Buffers";
  2499. infoprint " +-- Query Cache: "
  2500. . $myvar{'query_cache_type'} . " - "
  2501. . (
  2502. $myvar{'query_cache_type'} eq 0 |
  2503. $myvar{'query_cache_type'} eq 'OFF' ? "DISABLED"
  2504. : (
  2505. $myvar{'query_cache_type'} eq 1 ? "ALL REQUESTS"
  2506. : "ON DEMAND"
  2507. )
  2508. ) . "";
  2509. infoprint " +-- Query Cache Size: "
  2510. . hr_bytes( $myvar{'query_cache_size'} ) . "";
  2511. }
  2512. infoprint "Per Thread Buffers";
  2513. infoprint " +-- Read Buffer: "
  2514. . hr_bytes( $myvar{'read_buffer_size'} ) . "";
  2515. infoprint " +-- Read RND Buffer: "
  2516. . hr_bytes( $myvar{'read_rnd_buffer_size'} ) . "";
  2517. infoprint " +-- Sort Buffer: "
  2518. . hr_bytes( $myvar{'sort_buffer_size'} ) . "";
  2519. infoprint " +-- Thread stack: "
  2520. . hr_bytes( $myvar{'thread_stack'} ) . "";
  2521. infoprint " +-- Join Buffer: "
  2522. . hr_bytes( $myvar{'join_buffer_size'} ) . "";
  2523. if ( $myvar{'log_bin'} ne 'OFF' ) {
  2524. infoprint "Binlog Cache Buffers";
  2525. infoprint " +-- Binlog Cache: "
  2526. . hr_bytes( $myvar{'binlog_cache_size'} ) . "";
  2527. }
  2528. }
  2529. if ( $arch
  2530. && $arch == 32
  2531. && $mycalc{'max_used_memory'} > 2 * 1024 * 1024 * 1024 )
  2532. {
  2533. badprint
  2534. "Allocating > 2GB RAM on 32-bit systems can cause system instability";
  2535. badprint "Maximum reached memory usage: "
  2536. . hr_bytes( $mycalc{'max_used_memory'} )
  2537. . " ($mycalc{'pct_max_used_memory'}% of installed RAM)";
  2538. }
  2539. elsif ( $mycalc{'pct_max_used_memory'} > 85 ) {
  2540. badprint "Maximum reached memory usage: "
  2541. . hr_bytes( $mycalc{'max_used_memory'} )
  2542. . " ($mycalc{'pct_max_used_memory'}% of installed RAM)";
  2543. }
  2544. else {
  2545. goodprint "Maximum reached memory usage: "
  2546. . hr_bytes( $mycalc{'max_used_memory'} )
  2547. . " ($mycalc{'pct_max_used_memory'}% of installed RAM)";
  2548. }
  2549. if ( $mycalc{'pct_max_physical_memory'} > 85 ) {
  2550. badprint "Maximum possible memory usage: "
  2551. . hr_bytes( $mycalc{'max_peak_memory'} )
  2552. . " ($mycalc{'pct_max_physical_memory'}% of installed RAM)";
  2553. push( @generalrec,
  2554. "Reduce your overall MySQL memory footprint for system stability" );
  2555. }
  2556. else {
  2557. goodprint "Maximum possible memory usage: "
  2558. . hr_bytes( $mycalc{'max_peak_memory'} )
  2559. . " ($mycalc{'pct_max_physical_memory'}% of installed RAM)";
  2560. }
  2561. if ( $physical_memory <
  2562. ( $mycalc{'max_peak_memory'} + get_other_process_memory() ) )
  2563. {
  2564. badprint
  2565. "Overall possible memory usage with other process exceeded memory";
  2566. push( @generalrec,
  2567. "Dedicate this server to your database for highest performance." );
  2568. }
  2569. else {
  2570. goodprint
  2571. "Overall possible memory usage with other process is compatible with memory available";
  2572. }
  2573. # Slow queries
  2574. if ( $mycalc{'pct_slow_queries'} > 5 ) {
  2575. badprint "Slow queries: $mycalc{'pct_slow_queries'}% ("
  2576. . hr_num( $mystat{'Slow_queries'} ) . "/"
  2577. . hr_num( $mystat{'Questions'} ) . ")";
  2578. }
  2579. else {
  2580. goodprint "Slow queries: $mycalc{'pct_slow_queries'}% ("
  2581. . hr_num( $mystat{'Slow_queries'} ) . "/"
  2582. . hr_num( $mystat{'Questions'} ) . ")";
  2583. }
  2584. if ( $myvar{'long_query_time'} > 10 ) {
  2585. push( @adjvars, "long_query_time (<= 10)" );
  2586. }
  2587. if ( defined( $myvar{'log_slow_queries'} ) ) {
  2588. if ( $myvar{'log_slow_queries'} eq "OFF" ) {
  2589. push( @generalrec,
  2590. "Enable the slow query log to troubleshoot bad queries" );
  2591. }
  2592. }
  2593. # Connections
  2594. if ( $mycalc{'pct_connections_used'} > 85 ) {
  2595. badprint
  2596. "Highest connection usage: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})";
  2597. push( @adjvars,
  2598. "max_connections (> " . $myvar{'max_connections'} . ")" );
  2599. push( @adjvars,
  2600. "wait_timeout (< " . $myvar{'wait_timeout'} . ")",
  2601. "interactive_timeout (< " . $myvar{'interactive_timeout'} . ")" );
  2602. push( @generalrec,
  2603. "Reduce or eliminate persistent connections to reduce connection usage"
  2604. );
  2605. }
  2606. else {
  2607. goodprint
  2608. "Highest usage of available connections: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})";
  2609. }
  2610. # Aborted Connections
  2611. if ( $mycalc{'pct_connections_aborted'} > 3 ) {
  2612. badprint
  2613. "Aborted connections: $mycalc{'pct_connections_aborted'}% ($mystat{'Aborted_connects'}/$mystat{'Connections'})";
  2614. push( @generalrec,
  2615. "Reduce or eliminate unclosed connections and network issues" );
  2616. }
  2617. else {
  2618. goodprint
  2619. "Aborted connections: $mycalc{'pct_connections_aborted'}% ($mystat{'Aborted_connects'}/$mystat{'Connections'})";
  2620. }
  2621. # name resolution
  2622. if ( defined( $result{'Variables'}{'skip_networking'} )
  2623. && $result{'Variables'}{'skip_networking'} eq 'ON' )
  2624. {
  2625. infoprint
  2626. "Skipped name resolution test due to skip_networking=ON in system variables.";
  2627. }
  2628. elsif ( not defined( $result{'Variables'}{'skip_name_resolve'} ) ) {
  2629. infoprint
  2630. "Skipped name resolution test due to missing skip_name_resolve in system variables.";
  2631. }
  2632. elsif ( $result{'Variables'}{'skip_name_resolve'} eq 'OFF' ) {
  2633. badprint
  2634. "name resolution is active : a reverse name resolution is made for each new connection and can reduce performance";
  2635. push( @generalrec,
  2636. "Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1"
  2637. );
  2638. }
  2639. # Query cache
  2640. if ( !mysql_version_ge(4) ) {
  2641. # MySQL versions < 4.01 don't support query caching
  2642. push( @generalrec,
  2643. "Upgrade MySQL to version 4+ to utilize query caching" );
  2644. }
  2645. elsif (mysql_version_eq(8)) {
  2646. infoprint "Query cache have been removed in MySQL 8";
  2647. #return;
  2648. }
  2649. elsif ( $myvar{'query_cache_size'} < 1
  2650. and $myvar{'query_cache_type'} eq "OFF" )
  2651. {
  2652. goodprint
  2653. "Query cache is disabled by default due to mutex contention on multiprocessor machines.";
  2654. }
  2655. elsif ( $mystat{'Com_select'} == 0 ) {
  2656. badprint
  2657. "Query cache cannot be analyzed - no SELECT statements executed";
  2658. }
  2659. else {
  2660. badprint
  2661. "Query cache may be disabled by default due to mutex contention.";
  2662. push( @adjvars, "query_cache_size (=0)" );
  2663. push( @adjvars, "query_cache_type (=0)" );
  2664. if ( $mycalc{'query_cache_efficiency'} < 20 ) {
  2665. badprint
  2666. "Query cache efficiency: $mycalc{'query_cache_efficiency'}% ("
  2667. . hr_num( $mystat{'Qcache_hits'} )
  2668. . " cached / "
  2669. . hr_num( $mystat{'Qcache_hits'} + $mystat{'Com_select'} )
  2670. . " selects)";
  2671. push( @adjvars,
  2672. "query_cache_limit (> "
  2673. . hr_bytes_rnd( $myvar{'query_cache_limit'} )
  2674. . ", or use smaller result sets)" );
  2675. }
  2676. else {
  2677. goodprint
  2678. "Query cache efficiency: $mycalc{'query_cache_efficiency'}% ("
  2679. . hr_num( $mystat{'Qcache_hits'} )
  2680. . " cached / "
  2681. . hr_num( $mystat{'Qcache_hits'} + $mystat{'Com_select'} )
  2682. . " selects)";
  2683. }
  2684. if ( $mycalc{'query_cache_prunes_per_day'} > 98 ) {
  2685. badprint
  2686. "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}";
  2687. if ( $myvar{'query_cache_size'} >= 128 * 1024 * 1024 ) {
  2688. push( @generalrec,
  2689. "Increasing the query_cache size over 128M may reduce performance"
  2690. );
  2691. push( @adjvars,
  2692. "query_cache_size (> "
  2693. . hr_bytes_rnd( $myvar{'query_cache_size'} )
  2694. . ") [see warning above]" );
  2695. }
  2696. else {
  2697. push( @adjvars,
  2698. "query_cache_size (> "
  2699. . hr_bytes_rnd( $myvar{'query_cache_size'} )
  2700. . ")" );
  2701. }
  2702. }
  2703. else {
  2704. goodprint
  2705. "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}";
  2706. }
  2707. }
  2708. # Sorting
  2709. if ( $mycalc{'total_sorts'} == 0 ) {
  2710. goodprint "No Sort requiring temporary tables";
  2711. }
  2712. elsif ( $mycalc{'pct_temp_sort_table'} > 10 ) {
  2713. badprint
  2714. "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% ("
  2715. . hr_num( $mystat{'Sort_merge_passes'} )
  2716. . " temp sorts / "
  2717. . hr_num( $mycalc{'total_sorts'} )
  2718. . " sorts)";
  2719. push( @adjvars,
  2720. "sort_buffer_size (> "
  2721. . hr_bytes_rnd( $myvar{'sort_buffer_size'} )
  2722. . ")" );
  2723. push( @adjvars,
  2724. "read_rnd_buffer_size (> "
  2725. . hr_bytes_rnd( $myvar{'read_rnd_buffer_size'} )
  2726. . ")" );
  2727. }
  2728. else {
  2729. goodprint
  2730. "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% ("
  2731. . hr_num( $mystat{'Sort_merge_passes'} )
  2732. . " temp sorts / "
  2733. . hr_num( $mycalc{'total_sorts'} )
  2734. . " sorts)";
  2735. }
  2736. # Joins
  2737. if ( $mycalc{'joins_without_indexes_per_day'} > 250 ) {
  2738. badprint
  2739. "Joins performed without indexes: $mycalc{'joins_without_indexes'}";
  2740. push( @adjvars,
  2741. "join_buffer_size (> "
  2742. . hr_bytes( $myvar{'join_buffer_size'} )
  2743. . ", or always use indexes with JOINs)" );
  2744. push( @generalrec,
  2745. "Adjust your join queries to always utilize indexes" );
  2746. }
  2747. else {
  2748. goodprint "No joins without indexes";
  2749. # No joins have run without indexes
  2750. }
  2751. # Temporary tables
  2752. if ( $mystat{'Created_tmp_tables'} > 0 ) {
  2753. if ( $mycalc{'pct_temp_disk'} > 25
  2754. && $mycalc{'max_tmp_table_size'} < 256 * 1024 * 1024 )
  2755. {
  2756. badprint
  2757. "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% ("
  2758. . hr_num( $mystat{'Created_tmp_disk_tables'} )
  2759. . " on disk / "
  2760. . hr_num( $mystat{'Created_tmp_tables'} )
  2761. . " total)";
  2762. push( @adjvars,
  2763. "tmp_table_size (> "
  2764. . hr_bytes_rnd( $myvar{'tmp_table_size'} )
  2765. . ")" );
  2766. push( @adjvars,
  2767. "max_heap_table_size (> "
  2768. . hr_bytes_rnd( $myvar{'max_heap_table_size'} )
  2769. . ")" );
  2770. push( @generalrec,
  2771. "When making adjustments, make tmp_table_size/max_heap_table_size equal"
  2772. );
  2773. push( @generalrec,
  2774. "Reduce your SELECT DISTINCT queries which have no LIMIT clause"
  2775. );
  2776. }
  2777. elsif ($mycalc{'pct_temp_disk'} > 25
  2778. && $mycalc{'max_tmp_table_size'} >= 256 * 1024 * 1024 )
  2779. {
  2780. badprint
  2781. "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% ("
  2782. . hr_num( $mystat{'Created_tmp_disk_tables'} )
  2783. . " on disk / "
  2784. . hr_num( $mystat{'Created_tmp_tables'} )
  2785. . " total)";
  2786. push( @generalrec,
  2787. "Temporary table size is already large - reduce result set size"
  2788. );
  2789. push( @generalrec,
  2790. "Reduce your SELECT DISTINCT queries without LIMIT clauses" );
  2791. }
  2792. else {
  2793. goodprint
  2794. "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% ("
  2795. . hr_num( $mystat{'Created_tmp_disk_tables'} )
  2796. . " on disk / "
  2797. . hr_num( $mystat{'Created_tmp_tables'} )
  2798. . " total)";
  2799. }
  2800. }
  2801. else {
  2802. goodprint "No tmp tables created on disk";
  2803. }
  2804. # Thread cache
  2805. if ( defined( $myvar{'thread_handling'} )
  2806. and $myvar{'thread_handling'} eq 'pool-of-threads' )
  2807. {
  2808. # https://www.percona.com/doc/percona-server/LATEST/performance/threadpool.html
  2809. # When thread pool is enabled, the value of the thread_cache_size variable
  2810. # is ignored. The Threads_cached status variable contains 0 in this case.
  2811. infoprint "Thread cache not used with thread_handling=pool-of-threads";
  2812. }
  2813. else {
  2814. if ( $myvar{'thread_cache_size'} eq 0 ) {
  2815. badprint "Thread cache is disabled";
  2816. push( @generalrec, "Set thread_cache_size to 4 as a starting value" );
  2817. push( @adjvars, "thread_cache_size (start at 4)" );
  2818. }
  2819. else {
  2820. if ( $mycalc{'thread_cache_hit_rate'} <= 50 ) {
  2821. badprint
  2822. "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% ("
  2823. . hr_num( $mystat{'Threads_created'} )
  2824. . " created / "
  2825. . hr_num( $mystat{'Connections'} )
  2826. . " connections)";
  2827. push( @adjvars,
  2828. "thread_cache_size (> $myvar{'thread_cache_size'})" );
  2829. }
  2830. else {
  2831. goodprint
  2832. "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% ("
  2833. . hr_num( $mystat{'Threads_created'} )
  2834. . " created / "
  2835. . hr_num( $mystat{'Connections'} )
  2836. . " connections)";
  2837. }
  2838. }
  2839. }
  2840. # Table cache
  2841. my $table_cache_var = "";
  2842. if ( $mystat{'Open_tables'} > 0 ) {
  2843. if ( $mycalc{'table_cache_hit_rate'} < 20 ) {
  2844. badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% ("
  2845. . hr_num( $mystat{'Open_tables'} )
  2846. . " open / "
  2847. . hr_num( $mystat{'Opened_tables'} )
  2848. . " opened)";
  2849. if ( mysql_version_ge( 5, 1 ) ) {
  2850. $table_cache_var = "table_open_cache";
  2851. }
  2852. else {
  2853. $table_cache_var = "table_cache";
  2854. }
  2855. push( @adjvars,
  2856. $table_cache_var . " (> " . $myvar{$table_cache_var} . ")" );
  2857. push( @generalrec,
  2858. "Increase "
  2859. . $table_cache_var
  2860. . " gradually to avoid file descriptor limits" );
  2861. push( @generalrec,
  2862. "Read this before increasing "
  2863. . $table_cache_var
  2864. . " over 64: http://bit.ly/1mi7c4C" );
  2865. push( @generalrec,
  2866. "Read this before increasing for MariaDB"
  2867. . " https://mariadb.com/kb/en/library/optimizing-table_open_cache/");
  2868. push( @generalrec,
  2869. "This is MyISAM only table_cache scalability problem, InnoDB not affected."
  2870. );
  2871. push( @generalrec,
  2872. "See more details here: https://bugs.mysql.com/bug.php?id=49177"
  2873. );
  2874. push( @generalrec,
  2875. "This bug already fixed in MySQL 5.7.9 and newer MySQL versions."
  2876. );
  2877. push( @generalrec,
  2878. "Beware that open_files_limit ("
  2879. . $myvar{'open_files_limit'}
  2880. . ") variable " );
  2881. push( @generalrec,
  2882. "should be greater than $table_cache_var ("
  2883. . $myvar{$table_cache_var}
  2884. . ")" );
  2885. }
  2886. else {
  2887. goodprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% ("
  2888. . hr_num( $mystat{'Open_tables'} )
  2889. . " open / "
  2890. . hr_num( $mystat{'Opened_tables'} )
  2891. . " opened)";
  2892. }
  2893. }
  2894. # Open files
  2895. if ( defined $mycalc{'pct_files_open'} ) {
  2896. if ( $mycalc{'pct_files_open'} > 85 ) {
  2897. badprint "Open file limit used: $mycalc{'pct_files_open'}% ("
  2898. . hr_num( $mystat{'Open_files'} ) . "/"
  2899. . hr_num( $myvar{'open_files_limit'} ) . ")";
  2900. push( @adjvars,
  2901. "open_files_limit (> " . $myvar{'open_files_limit'} . ")" );
  2902. }
  2903. else {
  2904. goodprint "Open file limit used: $mycalc{'pct_files_open'}% ("
  2905. . hr_num( $mystat{'Open_files'} ) . "/"
  2906. . hr_num( $myvar{'open_files_limit'} ) . ")";
  2907. }
  2908. }
  2909. # Table locks
  2910. if ( defined $mycalc{'pct_table_locks_immediate'} ) {
  2911. if ( $mycalc{'pct_table_locks_immediate'} < 95 ) {
  2912. badprint
  2913. "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}%";
  2914. push( @generalrec,
  2915. "Optimize queries and/or use InnoDB to reduce lock wait" );
  2916. }
  2917. else {
  2918. goodprint
  2919. "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}% ("
  2920. . hr_num( $mystat{'Table_locks_immediate'} )
  2921. . " immediate / "
  2922. . hr_num( $mystat{'Table_locks_waited'} +
  2923. $mystat{'Table_locks_immediate'} )
  2924. . " locks)";
  2925. }
  2926. }
  2927. # Binlog cache
  2928. if ( defined $mycalc{'pct_binlog_cache'} ) {
  2929. if ( $mycalc{'pct_binlog_cache'} < 90
  2930. && $mystat{'Binlog_cache_use'} > 0 )
  2931. {
  2932. badprint "Binlog cache memory access: "
  2933. . $mycalc{'pct_binlog_cache'} . "% ("
  2934. . (
  2935. $mystat{'Binlog_cache_use'} - $mystat{'Binlog_cache_disk_use'} )
  2936. . " Memory / "
  2937. . $mystat{'Binlog_cache_use'}
  2938. . " Total)";
  2939. push( @generalrec,
  2940. "Increase binlog_cache_size (Actual value: "
  2941. . $myvar{'binlog_cache_size'}
  2942. . ")" );
  2943. push( @adjvars,
  2944. "binlog_cache_size ("
  2945. . hr_bytes( $myvar{'binlog_cache_size'} + 16 * 1024 * 1024 )
  2946. . ")" );
  2947. }
  2948. else {
  2949. goodprint "Binlog cache memory access: "
  2950. . $mycalc{'pct_binlog_cache'} . "% ("
  2951. . (
  2952. $mystat{'Binlog_cache_use'} - $mystat{'Binlog_cache_disk_use'} )
  2953. . " Memory / "
  2954. . $mystat{'Binlog_cache_use'}
  2955. . " Total)";
  2956. debugprint "Not enough data to validate binlog cache size\n"
  2957. if $mystat{'Binlog_cache_use'} < 10;
  2958. }
  2959. }
  2960. # Performance options
  2961. if ( !mysql_version_ge( 5, 1 ) ) {
  2962. push( @generalrec, "Upgrade to MySQL 5.5+ to use asynchronous write" );
  2963. }
  2964. elsif ( $myvar{'concurrent_insert'} eq "OFF" ) {
  2965. push( @generalrec, "Enable concurrent_insert by setting it to 'ON'" );
  2966. }
  2967. elsif ( $myvar{'concurrent_insert'} eq 0 ) {
  2968. push( @generalrec, "Enable concurrent_insert by setting it to 1" );
  2969. }
  2970. }
  2971. # Recommendations for MyISAM
  2972. sub mysql_myisam {
  2973. subheaderprint "MyISAM Metrics";
  2974. # Key buffer usage
  2975. if ( defined( $mycalc{'pct_key_buffer_used'} ) ) {
  2976. if ( $mycalc{'pct_key_buffer_used'} < 90 ) {
  2977. badprint "Key buffer used: $mycalc{'pct_key_buffer_used'}% ("
  2978. . hr_num( $myvar{'key_buffer_size'} *
  2979. $mycalc{'pct_key_buffer_used'} /
  2980. 100 )
  2981. . " used / "
  2982. . hr_num( $myvar{'key_buffer_size'} )
  2983. . " cache)";
  2984. #push(@adjvars,"key_buffer_size (\~ ".hr_num( $myvar{'key_buffer_size'} * $mycalc{'pct_key_buffer_used'} / 100).")");
  2985. }
  2986. else {
  2987. goodprint "Key buffer used: $mycalc{'pct_key_buffer_used'}% ("
  2988. . hr_num( $myvar{'key_buffer_size'} *
  2989. $mycalc{'pct_key_buffer_used'} /
  2990. 100 )
  2991. . " used / "
  2992. . hr_num( $myvar{'key_buffer_size'} )
  2993. . " cache)";
  2994. }
  2995. }
  2996. else {
  2997. # No queries have run that would use keys
  2998. debugprint "Key buffer used: $mycalc{'pct_key_buffer_used'}% ("
  2999. . hr_num(
  3000. $myvar{'key_buffer_size'} * $mycalc{'pct_key_buffer_used'} / 100 )
  3001. . " used / "
  3002. . hr_num( $myvar{'key_buffer_size'} )
  3003. . " cache)";
  3004. }
  3005. # Key buffer
  3006. if ( !defined( $mycalc{'total_myisam_indexes'} ) and $doremote == 1 ) {
  3007. push( @generalrec,
  3008. "Unable to calculate MyISAM indexes on remote MySQL server < 5.0.0"
  3009. );
  3010. }
  3011. elsif ( $mycalc{'total_myisam_indexes'} =~ /^fail$/ ) {
  3012. badprint
  3013. "Cannot calculate MyISAM index size - re-run script as root user";
  3014. }
  3015. elsif ( $mycalc{'total_myisam_indexes'} == "0" ) {
  3016. badprint
  3017. "None of your MyISAM tables are indexed - add indexes immediately";
  3018. }
  3019. else {
  3020. if ( $myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'}
  3021. && $mycalc{'pct_keys_from_mem'} < 95 )
  3022. {
  3023. badprint "Key buffer size / total MyISAM indexes: "
  3024. . hr_bytes( $myvar{'key_buffer_size'} ) . "/"
  3025. . hr_bytes( $mycalc{'total_myisam_indexes'} ) . "";
  3026. push( @adjvars,
  3027. "key_buffer_size (> "
  3028. . hr_bytes( $mycalc{'total_myisam_indexes'} )
  3029. . ")" );
  3030. }
  3031. else {
  3032. goodprint "Key buffer size / total MyISAM indexes: "
  3033. . hr_bytes( $myvar{'key_buffer_size'} ) . "/"
  3034. . hr_bytes( $mycalc{'total_myisam_indexes'} ) . "";
  3035. }
  3036. if ( $mystat{'Key_read_requests'} > 0 ) {
  3037. if ( $mycalc{'pct_keys_from_mem'} < 95 ) {
  3038. badprint
  3039. "Read Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% ("
  3040. . hr_num( $mystat{'Key_read_requests'} )
  3041. . " cached / "
  3042. . hr_num( $mystat{'Key_reads'} )
  3043. . " reads)";
  3044. }
  3045. else {
  3046. goodprint
  3047. "Read Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% ("
  3048. . hr_num( $mystat{'Key_read_requests'} )
  3049. . " cached / "
  3050. . hr_num( $mystat{'Key_reads'} )
  3051. . " reads)";
  3052. }
  3053. }
  3054. else {
  3055. # No queries have run that would use keys
  3056. debugprint "Key buffer size / total MyISAM indexes: "
  3057. . hr_bytes( $myvar{'key_buffer_size'} ) . "/"
  3058. . hr_bytes( $mycalc{'total_myisam_indexes'} ) . "";
  3059. }
  3060. if ( $mystat{'Key_write_requests'} > 0 ) {
  3061. if ( $mycalc{'pct_wkeys_from_mem'} < 95 ) {
  3062. badprint
  3063. "Write Key buffer hit rate: $mycalc{'pct_wkeys_from_mem'}% ("
  3064. . hr_num( $mystat{'Key_write_requests'} )
  3065. . " cached / "
  3066. . hr_num( $mystat{'Key_writes'} )
  3067. . " writes)";
  3068. }
  3069. else {
  3070. goodprint
  3071. "Write Key buffer hit rate: $mycalc{'pct_wkeys_from_mem'}% ("
  3072. . hr_num( $mystat{'Key_write_requests'} )
  3073. . " cached / "
  3074. . hr_num( $mystat{'Key_writes'} )
  3075. . " writes)";
  3076. }
  3077. }
  3078. else {
  3079. # No queries have run that would use keys
  3080. debugprint
  3081. "Write Key buffer hit rate: $mycalc{'pct_wkeys_from_mem'}% ("
  3082. . hr_num( $mystat{'Key_write_requests'} )
  3083. . " cached / "
  3084. . hr_num( $mystat{'Key_writes'} )
  3085. . " writes)";
  3086. }
  3087. }
  3088. }
  3089. # Recommendations for ThreadPool
  3090. sub mariadb_threadpool {
  3091. subheaderprint "ThreadPool Metrics";
  3092. # AriaDB
  3093. unless ( defined $myvar{'have_threadpool'}
  3094. && $myvar{'have_threadpool'} eq "YES" )
  3095. {
  3096. infoprint "ThreadPool stat is disabled.";
  3097. return;
  3098. }
  3099. infoprint "ThreadPool stat is enabled.";
  3100. infoprint "Thread Pool Size: " . $myvar{'thread_pool_size'} . " thread(s).";
  3101. if ( $myvar{'version'} =~ /mariadb|percona/i ) {
  3102. infoprint "Using default value is good enough for your version ("
  3103. . $myvar{'version'} . ")";
  3104. return;
  3105. }
  3106. if ( $myvar{'have_innodb'} eq 'YES' ) {
  3107. if ( $myvar{'thread_pool_size'} < 16
  3108. or $myvar{'thread_pool_size'} > 36 )
  3109. {
  3110. badprint
  3111. "thread_pool_size between 16 and 36 when using InnoDB storage engine.";
  3112. push( @generalrec,
  3113. "Thread pool size for InnoDB usage ("
  3114. . $myvar{'thread_pool_size'}
  3115. . ")" );
  3116. push( @adjvars,
  3117. "thread_pool_size between 16 and 36 for InnoDB usage" );
  3118. }
  3119. else {
  3120. goodprint
  3121. "thread_pool_size between 16 and 36 when using InnoDB storage engine.";
  3122. }
  3123. return;
  3124. }
  3125. if ( $myvar{'have_isam'} eq 'YES' ) {
  3126. if ( $myvar{'thread_pool_size'} < 4 or $myvar{'thread_pool_size'} > 8 )
  3127. {
  3128. badprint
  3129. "thread_pool_size between 4 and 8 when using MyIsam storage engine.";
  3130. push( @generalrec,
  3131. "Thread pool size for MyIsam usage ("
  3132. . $myvar{'thread_pool_size'}
  3133. . ")" );
  3134. push( @adjvars,
  3135. "thread_pool_size between 4 and 8 for MyIsam usage" );
  3136. }
  3137. else {
  3138. goodprint
  3139. "thread_pool_size between 4 and 8 when using MyISAM storage engine.";
  3140. }
  3141. }
  3142. }
  3143. sub get_pf_memory {
  3144. # Performance Schema
  3145. return 0 unless defined $myvar{'performance_schema'};
  3146. return 0 if $myvar{'performance_schema'} eq 'OFF';
  3147. my @infoPFSMemory = grep /performance_schema.memory/,
  3148. select_array("SHOW ENGINE PERFORMANCE_SCHEMA STATUS");
  3149. return 0 if scalar(@infoPFSMemory) == 0;
  3150. $infoPFSMemory[0] =~ s/.*\s+(\d+)$/$1/g;
  3151. return $infoPFSMemory[0];
  3152. }
  3153. # Recommendations for Performance Schema
  3154. sub mysqsl_pfs {
  3155. subheaderprint "Performance schema";
  3156. # Performance Schema
  3157. $myvar{'performance_schema'} = 'OFF'
  3158. unless defined( $myvar{'performance_schema'} );
  3159. unless ( $myvar{'performance_schema'} eq 'ON' ) {
  3160. infoprint "Performance schema is disabled.";
  3161. if ( mysql_version_ge( 5, 6 ) ) {
  3162. push( @generalrec,
  3163. "Performance schema should be activated for better diagnostics"
  3164. );
  3165. push( @adjvars, "performance_schema = ON enable PFS" );
  3166. }
  3167. }
  3168. else {
  3169. if ( mysql_version_le( 5, 5 ) ) {
  3170. push( @generalrec,
  3171. "Performance schema shouldn't be activated for MySQL and MariaDB 5.5 and lower version"
  3172. );
  3173. push( @adjvars, "performance_schema = OFF disable PFS" );
  3174. }
  3175. }
  3176. debugprint "Performance schema is " . $myvar{'performance_schema'};
  3177. infoprint "Memory used by P_S: " . hr_bytes( get_pf_memory() );
  3178. if ( mysql_version_eq( 10, 0 ) ) {
  3179. push( @generalrec,
  3180. "Performance schema shouldn't be activated for MariaDB 10.0 for performance issue"
  3181. );
  3182. push( @adjvars, "performance_schema = OFF disable PFS" );
  3183. return;
  3184. }
  3185. unless ( grep /^sys$/, select_array("SHOW DATABASES") ) {
  3186. infoprint "Sys schema isn't installed.";
  3187. push( @generalrec,
  3188. "Consider installing Sys schema from https://github.com/mysql/mysql-sys"
  3189. ) unless ( mysql_version_le( 5, 5 ) );
  3190. return;
  3191. }
  3192. else {
  3193. infoprint "Sys schema is installed.";
  3194. }
  3195. return if ( $opt{pfstat} == 0 or $myvar{'performance_schema'} ne 'ON' );
  3196. infoprint "Sys schema Version: "
  3197. . select_one("select sys_version from sys.version");
  3198. # Top user per connection
  3199. subheaderprint "Performance schema: Top 5 user per connection";
  3200. my $nbL = 1;
  3201. for my $lQuery (
  3202. select_array(
  3203. 'select user, total_connections from sys.user_summary order by total_connections desc LIMIT 5'
  3204. )
  3205. )
  3206. {
  3207. infoprint " +-- $nbL: $lQuery conn(s)";
  3208. $nbL++;
  3209. }
  3210. infoprint "No information found or indicators deactivated."
  3211. if ( $nbL == 1 );
  3212. # Top user per statement
  3213. subheaderprint "Performance schema: Top 5 user per statement";
  3214. $nbL = 1;
  3215. for my $lQuery (
  3216. select_array(
  3217. 'select user, statements from sys.user_summary order by statements desc LIMIT 5'
  3218. )
  3219. )
  3220. {
  3221. infoprint " +-- $nbL: $lQuery stmt(s)";
  3222. $nbL++;
  3223. }
  3224. infoprint "No information found or indicators deactivated."
  3225. if ( $nbL == 1 );
  3226. # Top user per statement latency
  3227. subheaderprint "Performance schema: Top 5 user per statement latency";
  3228. $nbL = 1;
  3229. for my $lQuery (
  3230. select_array(
  3231. 'select user, statement_avg_latency from sys.x\\$user_summary order by statement_avg_latency desc LIMIT 5'
  3232. )
  3233. )
  3234. {
  3235. infoprint " +-- $nbL: $lQuery";
  3236. $nbL++;
  3237. }
  3238. infoprint "No information found or indicators deactivated."
  3239. if ( $nbL == 1 );
  3240. # Top user per lock latency
  3241. subheaderprint "Performance schema: Top 5 user per lock latency";
  3242. $nbL = 1;
  3243. for my $lQuery (
  3244. select_array(
  3245. 'select user, lock_latency from sys.x\\$user_summary_by_statement_latency order by lock_latency desc LIMIT 5'
  3246. )
  3247. )
  3248. {
  3249. infoprint " +-- $nbL: $lQuery";
  3250. $nbL++;
  3251. }
  3252. infoprint "No information found or indicators deactivated."
  3253. if ( $nbL == 1 );
  3254. # Top user per full scans
  3255. subheaderprint "Performance schema: Top 5 user per nb full scans";
  3256. $nbL = 1;
  3257. for my $lQuery (
  3258. select_array(
  3259. 'select user, full_scans from sys.x\\$user_summary_by_statement_latency order by full_scans desc LIMIT 5'
  3260. )
  3261. )
  3262. {
  3263. infoprint " +-- $nbL: $lQuery";
  3264. $nbL++;
  3265. }
  3266. infoprint "No information found or indicators deactivated."
  3267. if ( $nbL == 1 );
  3268. # Top user per row_sent
  3269. subheaderprint "Performance schema: Top 5 user per rows sent";
  3270. $nbL = 1;
  3271. for my $lQuery (
  3272. select_array(
  3273. 'select user, rows_sent from sys.x\\$user_summary_by_statement_latency order by rows_sent desc LIMIT 5'
  3274. )
  3275. )
  3276. {
  3277. infoprint " +-- $nbL: $lQuery";
  3278. $nbL++;
  3279. }
  3280. infoprint "No information found or indicators deactivated."
  3281. if ( $nbL == 1 );
  3282. # Top user per row modified
  3283. subheaderprint "Performance schema: Top 5 user per rows modified";
  3284. $nbL = 1;
  3285. for my $lQuery (
  3286. select_array(
  3287. 'select user, rows_affected from sys.x\\$user_summary_by_statement_latency order by rows_affected desc LIMIT 5'
  3288. )
  3289. )
  3290. {
  3291. infoprint " +-- $nbL: $lQuery";
  3292. $nbL++;
  3293. }
  3294. infoprint "No information found or indicators deactivated."
  3295. if ( $nbL == 1 );
  3296. # Top user per io
  3297. subheaderprint "Performance schema: Top 5 user per io";
  3298. $nbL = 1;
  3299. for my $lQuery (
  3300. select_array(
  3301. 'select user, file_ios from sys.x\\$user_summary order by file_ios desc LIMIT 5'
  3302. )
  3303. )
  3304. {
  3305. infoprint " +-- $nbL: $lQuery";
  3306. $nbL++;
  3307. }
  3308. infoprint "No information found or indicators deactivated."
  3309. if ( $nbL == 1 );
  3310. # Top user per io latency
  3311. subheaderprint "Performance schema: Top 5 user per io latency";
  3312. $nbL = 1;
  3313. for my $lQuery (
  3314. select_array(
  3315. 'select user, file_io_latency from sys.x\\$user_summary order by file_io_latency desc LIMIT 5'
  3316. )
  3317. )
  3318. {
  3319. infoprint " +-- $nbL: $lQuery";
  3320. $nbL++;
  3321. }
  3322. infoprint "No information found or indicators deactivated."
  3323. if ( $nbL == 1 );
  3324. # Top host per connection
  3325. subheaderprint "Performance schema: Top 5 host per connection";
  3326. $nbL = 1;
  3327. for my $lQuery (
  3328. select_array(
  3329. 'select host, total_connections from sys.x\\$host_summary order by total_connections desc LIMIT 5'
  3330. )
  3331. )
  3332. {
  3333. infoprint " +-- $nbL: $lQuery conn(s)";
  3334. $nbL++;
  3335. }
  3336. infoprint "No information found or indicators deactivated."
  3337. if ( $nbL == 1 );
  3338. # Top host per statement
  3339. subheaderprint "Performance schema: Top 5 host per statement";
  3340. $nbL = 1;
  3341. for my $lQuery (
  3342. select_array(
  3343. 'select host, statements from sys.x\\$host_summary order by statements desc LIMIT 5'
  3344. )
  3345. )
  3346. {
  3347. infoprint " +-- $nbL: $lQuery stmt(s)";
  3348. $nbL++;
  3349. }
  3350. infoprint "No information found or indicators deactivated."
  3351. if ( $nbL == 1 );
  3352. # Top host per statement latency
  3353. subheaderprint "Performance schema: Top 5 host per statement latency";
  3354. $nbL = 1;
  3355. for my $lQuery (
  3356. select_array(
  3357. 'select host, statement_avg_latency from sys.x\\$host_summary order by statement_avg_latency desc LIMIT 5'
  3358. )
  3359. )
  3360. {
  3361. infoprint " +-- $nbL: $lQuery";
  3362. $nbL++;
  3363. }
  3364. infoprint "No information found or indicators deactivated."
  3365. if ( $nbL == 1 );
  3366. # Top host per lock latency
  3367. subheaderprint "Performance schema: Top 5 host per lock latency";
  3368. $nbL = 1;
  3369. for my $lQuery (
  3370. select_array(
  3371. 'select host, lock_latency from sys.x\\$host_summary_by_statement_latency order by lock_latency desc LIMIT 5'
  3372. )
  3373. )
  3374. {
  3375. infoprint " +-- $nbL: $lQuery";
  3376. $nbL++;
  3377. }
  3378. infoprint "No information found or indicators deactivated."
  3379. if ( $nbL == 1 );
  3380. # Top host per full scans
  3381. subheaderprint "Performance schema: Top 5 host per nb full scans";
  3382. $nbL = 1;
  3383. for my $lQuery (
  3384. select_array(
  3385. 'select host, full_scans from sys.x\\$host_summary_by_statement_latency order by full_scans desc LIMIT 5'
  3386. )
  3387. )
  3388. {
  3389. infoprint " +-- $nbL: $lQuery";
  3390. $nbL++;
  3391. }
  3392. infoprint "No information found or indicators deactivated."
  3393. if ( $nbL == 1 );
  3394. # Top host per rows sent
  3395. subheaderprint "Performance schema: Top 5 host per rows sent";
  3396. $nbL = 1;
  3397. for my $lQuery (
  3398. select_array(
  3399. 'select host, rows_sent from sys.x\\$host_summary_by_statement_latency order by rows_sent desc LIMIT 5'
  3400. )
  3401. )
  3402. {
  3403. infoprint " +-- $nbL: $lQuery";
  3404. $nbL++;
  3405. }
  3406. infoprint "No information found or indicators deactivated."
  3407. if ( $nbL == 1 );
  3408. # Top host per rows modified
  3409. subheaderprint "Performance schema: Top 5 host per rows modified";
  3410. $nbL = 1;
  3411. for my $lQuery (
  3412. select_array(
  3413. 'select host, rows_affected from sys.x\\$host_summary_by_statement_latency order by rows_affected desc LIMIT 5'
  3414. )
  3415. )
  3416. {
  3417. infoprint " +-- $nbL: $lQuery";
  3418. $nbL++;
  3419. }
  3420. infoprint "No information found or indicators deactivated."
  3421. if ( $nbL == 1 );
  3422. # Top host per io
  3423. subheaderprint "Performance schema: Top 5 host per io";
  3424. $nbL = 1;
  3425. for my $lQuery (
  3426. select_array(
  3427. 'select host, file_ios from sys.x\\$host_summary order by file_ios desc LIMIT 5'
  3428. )
  3429. )
  3430. {
  3431. infoprint " +-- $nbL: $lQuery";
  3432. $nbL++;
  3433. }
  3434. infoprint "No information found or indicators deactivated."
  3435. if ( $nbL == 1 );
  3436. # Top 5 host per io latency
  3437. subheaderprint "Performance schema: Top 5 host per io latency";
  3438. $nbL = 1;
  3439. for my $lQuery (
  3440. select_array(
  3441. 'select host, file_io_latency from sys.x\\$host_summary order by file_io_latency desc LIMIT 5'
  3442. )
  3443. )
  3444. {
  3445. infoprint " +-- $nbL: $lQuery";
  3446. $nbL++;
  3447. }
  3448. infoprint "No information found or indicators deactivated."
  3449. if ( $nbL == 1 );
  3450. # Top IO type order by total io
  3451. subheaderprint "Performance schema: Top IO type order by total io";
  3452. $nbL = 1;
  3453. for my $lQuery (
  3454. select_array(
  3455. 'use sys;select substring(event_name,14), SUM(total)AS total from sys.x\\$host_summary_by_file_io_type GROUP BY substring(event_name,14) ORDER BY total DESC;'
  3456. )
  3457. )
  3458. {
  3459. infoprint " +-- $nbL: $lQuery i/o";
  3460. $nbL++;
  3461. }
  3462. infoprint "No information found or indicators deactivated."
  3463. if ( $nbL == 1 );
  3464. # Top IO type order by total latency
  3465. subheaderprint "Performance schema: Top IO type order by total latency";
  3466. $nbL = 1;
  3467. for my $lQuery (
  3468. select_array(
  3469. 'select substring(event_name,14), ROUND(SUM(total_latency),1) AS total_latency from sys.x\\$host_summary_by_file_io_type GROUP BY substring(event_name,14) ORDER BY total_latency DESC;'
  3470. )
  3471. )
  3472. {
  3473. infoprint " +-- $nbL: $lQuery";
  3474. $nbL++;
  3475. }
  3476. infoprint "No information found or indicators deactivated."
  3477. if ( $nbL == 1 );
  3478. # Top IO type order by max latency
  3479. subheaderprint "Performance schema: Top IO type order by max latency";
  3480. $nbL = 1;
  3481. for my $lQuery (
  3482. select_array(
  3483. 'use sys;select substring(event_name,14), MAX(max_latency) as max_latency from sys.x\\$host_summary_by_file_io_type GROUP BY substring(event_name,14) ORDER BY max_latency DESC;'
  3484. )
  3485. )
  3486. {
  3487. infoprint " +-- $nbL: $lQuery";
  3488. $nbL++;
  3489. }
  3490. infoprint "No information found or indicators deactivated."
  3491. if ( $nbL == 1 );
  3492. # Top Stages order by total io
  3493. subheaderprint "Performance schema: Top Stages order by total io";
  3494. $nbL = 1;
  3495. for my $lQuery (
  3496. select_array(
  3497. 'use sys;select substring(event_name,7), SUM(total)AS total from sys.x\\$host_summary_by_stages GROUP BY substring(event_name,7) ORDER BY total DESC;'
  3498. )
  3499. )
  3500. {
  3501. infoprint " +-- $nbL: $lQuery i/o";
  3502. $nbL++;
  3503. }
  3504. infoprint "No information found or indicators deactivated."
  3505. if ( $nbL == 1 );
  3506. # Top Stages order by total latency
  3507. subheaderprint "Performance schema: Top Stages order by total latency";
  3508. $nbL = 1;
  3509. for my $lQuery (
  3510. select_array(
  3511. 'use sys;select substring(event_name,7), ROUND(SUM(total_latency),1) AS total_latency from sys.x\\$host_summary_by_stages GROUP BY substring(event_name,7) ORDER BY total_latency DESC;'
  3512. )
  3513. )
  3514. {
  3515. infoprint " +-- $nbL: $lQuery";
  3516. $nbL++;
  3517. }
  3518. infoprint "No information found or indicators deactivated."
  3519. if ( $nbL == 1 );
  3520. # Top Stages order by avg latency
  3521. subheaderprint "Performance schema: Top Stages order by avg latency";
  3522. $nbL = 1;
  3523. for my $lQuery (
  3524. select_array(
  3525. 'use sys;select substring(event_name,7), MAX(avg_latency) as avg_latency from sys.x\\$host_summary_by_stages GROUP BY substring(event_name,7) ORDER BY avg_latency DESC;'
  3526. )
  3527. )
  3528. {
  3529. infoprint " +-- $nbL: $lQuery";
  3530. $nbL++;
  3531. }
  3532. infoprint "No information found or indicators deactivated."
  3533. if ( $nbL == 1 );
  3534. # Top host per table scans
  3535. subheaderprint "Performance schema: Top 5 host per table scans";
  3536. $nbL = 1;
  3537. for my $lQuery (
  3538. select_array(
  3539. 'select host, table_scans from sys.x\\$host_summary order by table_scans desc LIMIT 5'
  3540. )
  3541. )
  3542. {
  3543. infoprint " +-- $nbL: $lQuery";
  3544. $nbL++;
  3545. }
  3546. infoprint "No information found or indicators deactivated."
  3547. if ( $nbL == 1 );
  3548. # InnoDB Buffer Pool by schema
  3549. subheaderprint "Performance schema: InnoDB Buffer Pool by schema";
  3550. $nbL = 1;
  3551. for my $lQuery (
  3552. select_array(
  3553. 'select object_schema, allocated, data, pages from sys.x\\$innodb_buffer_stats_by_schema ORDER BY pages DESC'
  3554. )
  3555. )
  3556. {
  3557. infoprint " +-- $nbL: $lQuery page(s)";
  3558. $nbL++;
  3559. }
  3560. infoprint "No information found or indicators deactivated."
  3561. if ( $nbL == 1 );
  3562. # InnoDB Buffer Pool by table
  3563. subheaderprint "Performance schema: InnoDB Buffer Pool by table";
  3564. $nbL = 1;
  3565. for my $lQuery (
  3566. select_array(
  3567. 'select object_schema, object_name, allocated,data, pages from sys.x\\$innodb_buffer_stats_by_table ORDER BY pages DESC'
  3568. )
  3569. )
  3570. {
  3571. infoprint " +-- $nbL: $lQuery page(s)";
  3572. $nbL++;
  3573. }
  3574. infoprint "No information found or indicators deactivated."
  3575. if ( $nbL == 1 );
  3576. # Process per allocated memory
  3577. subheaderprint "Performance schema: Process per time";
  3578. $nbL = 1;
  3579. for my $lQuery (
  3580. select_array(
  3581. 'select user, Command AS PROC, time from sys.x\\$processlist ORDER BY time DESC;'
  3582. )
  3583. )
  3584. {
  3585. infoprint " +-- $nbL: $lQuery";
  3586. $nbL++;
  3587. }
  3588. infoprint "No information found or indicators deactivated."
  3589. if ( $nbL == 1 );
  3590. # InnoDB Lock Waits
  3591. subheaderprint "Performance schema: InnoDB Lock Waits";
  3592. $nbL = 1;
  3593. for my $lQuery (
  3594. select_array(
  3595. 'select wait_age_secs, locked_table, locked_type, waiting_query from sys.x\\$innodb_lock_waits order by wait_age_secs DESC;'
  3596. )
  3597. )
  3598. {
  3599. infoprint " +-- $nbL: $lQuery";
  3600. $nbL++;
  3601. }
  3602. infoprint "No information found or indicators deactivated."
  3603. if ( $nbL == 1 );
  3604. # Threads IO Latency
  3605. subheaderprint "Performance schema: Thread IO Latency";
  3606. $nbL = 1;
  3607. for my $lQuery (
  3608. select_array(
  3609. 'select user, total_latency, max_latency from sys.x\\$io_by_thread_by_latency order by total_latency DESC;'
  3610. )
  3611. )
  3612. {
  3613. infoprint " +-- $nbL: $lQuery";
  3614. $nbL++;
  3615. }
  3616. infoprint "No information found or indicators deactivated."
  3617. if ( $nbL == 1 );
  3618. # High Cost SQL statements
  3619. subheaderprint "Performance schema: Top 5 Most latency statements";
  3620. $nbL = 1;
  3621. for my $lQuery (
  3622. select_array(
  3623. 'select query, avg_latency from sys.x\\$statement_analysis order by avg_latency desc LIMIT 5'
  3624. )
  3625. )
  3626. {
  3627. infoprint " +-- $nbL: $lQuery";
  3628. $nbL++;
  3629. }
  3630. infoprint "No information found or indicators deactivated."
  3631. if ( $nbL == 1 );
  3632. # Top 5% slower queries
  3633. subheaderprint "Performance schema: Top 5 slower queries";
  3634. $nbL = 1;
  3635. for my $lQuery (
  3636. select_array(
  3637. 'select query, exec_count from sys.x\\$statements_with_runtimes_in_95th_percentile order by exec_count desc LIMIT 5'
  3638. )
  3639. )
  3640. {
  3641. infoprint " +-- $nbL: $lQuery s";
  3642. $nbL++;
  3643. }
  3644. infoprint "No information found or indicators deactivated."
  3645. if ( $nbL == 1 );
  3646. # Top 10 nb statement type
  3647. subheaderprint "Performance schema: Top 10 nb statement type";
  3648. $nbL = 1;
  3649. for my $lQuery (
  3650. select_array(
  3651. 'use sys;select statement, sum(total) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3652. )
  3653. )
  3654. {
  3655. infoprint " +-- $nbL: $lQuery";
  3656. $nbL++;
  3657. }
  3658. infoprint "No information found or indicators deactivated."
  3659. if ( $nbL == 1 );
  3660. # Top statement by total latency
  3661. subheaderprint "Performance schema: Top statement by total latency";
  3662. $nbL = 1;
  3663. for my $lQuery (
  3664. select_array(
  3665. 'use sys;select statement, sum(total_latency) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3666. )
  3667. )
  3668. {
  3669. infoprint " +-- $nbL: $lQuery";
  3670. $nbL++;
  3671. }
  3672. infoprint "No information found or indicators deactivated."
  3673. if ( $nbL == 1 );
  3674. # Top statement by lock latency
  3675. subheaderprint "Performance schema: Top statement by lock latency";
  3676. $nbL = 1;
  3677. for my $lQuery (
  3678. select_array(
  3679. 'use sys;select statement, sum(lock_latency) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3680. )
  3681. )
  3682. {
  3683. infoprint " +-- $nbL: $lQuery";
  3684. $nbL++;
  3685. }
  3686. infoprint "No information found or indicators deactivated."
  3687. if ( $nbL == 1 );
  3688. # Top statement by full scans
  3689. subheaderprint "Performance schema: Top statement by full scans";
  3690. $nbL = 1;
  3691. for my $lQuery (
  3692. select_array(
  3693. 'use sys;select statement, sum(full_scans) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3694. )
  3695. )
  3696. {
  3697. infoprint " +-- $nbL: $lQuery";
  3698. $nbL++;
  3699. }
  3700. infoprint "No information found or indicators deactivated."
  3701. if ( $nbL == 1 );
  3702. # Top statement by rows sent
  3703. subheaderprint "Performance schema: Top statement by rows sent";
  3704. $nbL = 1;
  3705. for my $lQuery (
  3706. select_array(
  3707. 'use sys;select statement, sum(rows_sent) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3708. )
  3709. )
  3710. {
  3711. infoprint " +-- $nbL: $lQuery";
  3712. $nbL++;
  3713. }
  3714. infoprint "No information found or indicators deactivated."
  3715. if ( $nbL == 1 );
  3716. # Top statement by rows modified
  3717. subheaderprint "Performance schema: Top statement by rows modified";
  3718. $nbL = 1;
  3719. for my $lQuery (
  3720. select_array(
  3721. 'use sys;select statement, sum(rows_affected) as total from sys.x\\$host_summary_by_statement_type group by statement order by total desc LIMIT 10;'
  3722. )
  3723. )
  3724. {
  3725. infoprint " +-- $nbL: $lQuery";
  3726. $nbL++;
  3727. }
  3728. infoprint "No information found or indicators deactivated."
  3729. if ( $nbL == 1 );
  3730. # Use temporary tables
  3731. subheaderprint "Performance schema: Some queries using temp table";
  3732. $nbL = 1;
  3733. for my $lQuery (
  3734. select_array(
  3735. 'use sys;select query from sys.x\\$statements_with_temp_tables LIMIT 20'
  3736. )
  3737. )
  3738. {
  3739. infoprint " +-- $nbL: $lQuery";
  3740. $nbL++;
  3741. }
  3742. infoprint "No information found or indicators deactivated."
  3743. if ( $nbL == 1 );
  3744. # Unused Indexes
  3745. subheaderprint "Performance schema: Unused indexes";
  3746. $nbL = 1;
  3747. for my $lQuery ( select_array('select * from sys.schema_unused_indexes') ) {
  3748. infoprint " +-- $nbL: $lQuery";
  3749. $nbL++;
  3750. }
  3751. infoprint "No information found or indicators deactivated."
  3752. if ( $nbL == 1 );
  3753. # Full table scans
  3754. subheaderprint "Performance schema: Tables with full table scans";
  3755. $nbL = 1;
  3756. for my $lQuery (
  3757. select_array(
  3758. 'select * from sys.x\\$schema_tables_with_full_table_scans order by rows_full_scanned DESC'
  3759. )
  3760. )
  3761. {
  3762. infoprint " +-- $nbL: $lQuery";
  3763. $nbL++;
  3764. }
  3765. infoprint "No information found or indicators deactivated."
  3766. if ( $nbL == 1 );
  3767. # Latest file IO by latency
  3768. subheaderprint "Performance schema: Latest FILE IO by latency";
  3769. $nbL = 1;
  3770. for my $lQuery (
  3771. select_array(
  3772. 'use sys;select thread, file, latency, operation from sys.x\\$latest_file_io ORDER BY latency LIMIT 10;'
  3773. )
  3774. )
  3775. {
  3776. infoprint " +-- $nbL: $lQuery";
  3777. $nbL++;
  3778. }
  3779. infoprint "No information found or indicators deactivated."
  3780. if ( $nbL == 1 );
  3781. # FILE by IO read bytes
  3782. subheaderprint "Performance schema: FILE by IO read bytes";
  3783. $nbL = 1;
  3784. for my $lQuery (
  3785. select_array(
  3786. 'select file, total_read from sys.x\\$io_global_by_file_by_bytes order by total_read DESC LIMIT 15;'
  3787. )
  3788. )
  3789. {
  3790. infoprint " +-- $nbL: $lQuery";
  3791. $nbL++;
  3792. }
  3793. infoprint "No information found or indicators deactivated."
  3794. if ( $nbL == 1 );
  3795. # FILE by IO written bytes
  3796. subheaderprint "Performance schema: FILE by IO written bytes";
  3797. $nbL = 1;
  3798. for my $lQuery (
  3799. select_array(
  3800. 'select file, total_written from sys.x\\$io_global_by_file_by_bytes order by total_written DESC LIMIT 15'
  3801. )
  3802. )
  3803. {
  3804. infoprint " +-- $nbL: $lQuery";
  3805. $nbL++;
  3806. }
  3807. infoprint "No information found or indicators deactivated."
  3808. if ( $nbL == 1 );
  3809. # file per IO total latency
  3810. subheaderprint "Performance schema: file per IO total latency";
  3811. $nbL = 1;
  3812. for my $lQuery (
  3813. select_array(
  3814. 'select file, total_latency from sys.x\\$io_global_by_file_by_latency ORDER BY total_latency DESC LIMIT 20;'
  3815. )
  3816. )
  3817. {
  3818. infoprint " +-- $nbL: $lQuery";
  3819. $nbL++;
  3820. }
  3821. infoprint "No information found or indicators deactivated."
  3822. if ( $nbL == 1 );
  3823. # file per IO read latency
  3824. subheaderprint "Performance schema: file per IO read latency";
  3825. $nbL = 1;
  3826. for my $lQuery (
  3827. select_array(
  3828. 'use sys;select file, read_latency from sys.x\\$io_global_by_file_by_latency ORDER BY read_latency DESC LIMIT 20;'
  3829. )
  3830. )
  3831. {
  3832. infoprint " +-- $nbL: $lQuery";
  3833. $nbL++;
  3834. }
  3835. infoprint "No information found or indicators deactivated."
  3836. if ( $nbL == 1 );
  3837. # file per IO write latency
  3838. subheaderprint "Performance schema: file per IO write latency";
  3839. $nbL = 1;
  3840. for my $lQuery (
  3841. select_array(
  3842. 'use sys;select file, write_latency from sys.x\\$io_global_by_file_by_latency ORDER BY write_latency DESC LIMIT 20;'
  3843. )
  3844. )
  3845. {
  3846. infoprint " +-- $nbL: $lQuery";
  3847. $nbL++;
  3848. }
  3849. infoprint "No information found or indicators deactivated."
  3850. if ( $nbL == 1 );
  3851. # Event Wait by read bytes
  3852. subheaderprint "Performance schema: Event Wait by read bytes";
  3853. $nbL = 1;
  3854. for my $lQuery (
  3855. select_array(
  3856. 'select event_name, total_read from sys.x\\$io_global_by_wait_by_bytes order by total_read DESC LIMIT 15;'
  3857. )
  3858. )
  3859. {
  3860. infoprint " +-- $nbL: $lQuery";
  3861. $nbL++;
  3862. }
  3863. infoprint "No information found or indicators deactivated."
  3864. if ( $nbL == 1 );
  3865. # Event Wait by write bytes
  3866. subheaderprint "Performance schema: Event Wait written bytes";
  3867. $nbL = 1;
  3868. for my $lQuery (
  3869. select_array(
  3870. 'select event_name, total_written from sys.x\\$io_global_by_wait_by_bytes order by total_written DESC LIMIT 15;'
  3871. )
  3872. )
  3873. {
  3874. infoprint " +-- $nbL: $lQuery";
  3875. $nbL++;
  3876. }
  3877. infoprint "No information found or indicators deactivated."
  3878. if ( $nbL == 1 );
  3879. # event per wait total latency
  3880. subheaderprint "Performance schema: event per wait total latency";
  3881. $nbL = 1;
  3882. for my $lQuery (
  3883. select_array(
  3884. 'use sys;select event_name, total_latency from sys.x\\$io_global_by_wait_by_latency ORDER BY total_latency DESC LIMIT 20;'
  3885. )
  3886. )
  3887. {
  3888. infoprint " +-- $nbL: $lQuery";
  3889. $nbL++;
  3890. }
  3891. infoprint "No information found or indicators deactivated."
  3892. if ( $nbL == 1 );
  3893. # event per wait read latency
  3894. subheaderprint "Performance schema: event per wait read latency";
  3895. $nbL = 1;
  3896. for my $lQuery (
  3897. select_array(
  3898. 'use sys;select event_name, read_latency from sys.x\\$io_global_by_wait_by_latency ORDER BY read_latency DESC LIMIT 20;'
  3899. )
  3900. )
  3901. {
  3902. infoprint " +-- $nbL: $lQuery";
  3903. $nbL++;
  3904. }
  3905. infoprint "No information found or indicators deactivated."
  3906. if ( $nbL == 1 );
  3907. # event per wait write latency
  3908. subheaderprint "Performance schema: event per wait write latency";
  3909. $nbL = 1;
  3910. for my $lQuery (
  3911. select_array(
  3912. 'use sys;select event_name, write_latency from sys.x\\$io_global_by_wait_by_latency ORDER BY write_latency DESC LIMIT 20;'
  3913. )
  3914. )
  3915. {
  3916. infoprint " +-- $nbL: $lQuery";
  3917. $nbL++;
  3918. }
  3919. infoprint "No information found or indicators deactivated."
  3920. if ( $nbL == 1 );
  3921. #schema_index_statistics
  3922. # TOP 15 most read index
  3923. subheaderprint "Performance schema: TOP 15 most read indexes";
  3924. $nbL = 1;
  3925. for my $lQuery (
  3926. select_array(
  3927. 'use sys;select table_schema, table_name,index_name, rows_selected from sys.x\\$schema_index_statistics ORDER BY ROWs_selected DESC LIMIT 15;'
  3928. )
  3929. )
  3930. {
  3931. infoprint " +-- $nbL: $lQuery";
  3932. $nbL++;
  3933. }
  3934. infoprint "No information found or indicators deactivated."
  3935. if ( $nbL == 1 );
  3936. # TOP 15 most used index
  3937. subheaderprint "Performance schema: TOP 15 most modified indexes";
  3938. $nbL = 1;
  3939. for my $lQuery (
  3940. select_array(
  3941. 'use sys;select table_schema, table_name,index_name, rows_inserted+rows_updated+rows_deleted AS changes from sys.x\\$schema_index_statistics ORDER BY rows_inserted+rows_updated+rows_deleted DESC LIMIT 15;'
  3942. )
  3943. )
  3944. {
  3945. infoprint " +-- $nbL: $lQuery";
  3946. $nbL++;
  3947. }
  3948. infoprint "No information found or indicators deactivated."
  3949. if ( $nbL == 1 );
  3950. # TOP 15 high read latency index
  3951. subheaderprint "Performance schema: TOP 15 high read latency index";
  3952. $nbL = 1;
  3953. for my $lQuery (
  3954. select_array(
  3955. 'use sys;select table_schema, table_name,index_name, select_latency from sys.x\\$schema_index_statistics ORDER BY select_latency DESC LIMIT 15;'
  3956. )
  3957. )
  3958. {
  3959. infoprint " +-- $nbL: $lQuery";
  3960. $nbL++;
  3961. }
  3962. infoprint "No information found or indicators deactivated."
  3963. if ( $nbL == 1 );
  3964. # TOP 15 high insert latency index
  3965. subheaderprint "Performance schema: TOP 15 most modified indexes";
  3966. $nbL = 1;
  3967. for my $lQuery (
  3968. select_array(
  3969. 'use sys;select table_schema, table_name,index_name, insert_latency from sys.x\\$schema_index_statistics ORDER BY insert_latency DESC LIMIT 15;'
  3970. )
  3971. )
  3972. {
  3973. infoprint " +-- $nbL: $lQuery";
  3974. $nbL++;
  3975. }
  3976. infoprint "No information found or indicators deactivated."
  3977. if ( $nbL == 1 );
  3978. # TOP 15 high update latency index
  3979. subheaderprint "Performance schema: TOP 15 high update latency index";
  3980. $nbL = 1;
  3981. for my $lQuery (
  3982. select_array(
  3983. 'use sys;select table_schema, table_name,index_name, update_latency from sys.x\\$schema_index_statistics ORDER BY update_latency DESC LIMIT 15;'
  3984. )
  3985. )
  3986. {
  3987. infoprint " +-- $nbL: $lQuery";
  3988. $nbL++;
  3989. }
  3990. infoprint "No information found or indicators deactivated."
  3991. if ( $nbL == 1 );
  3992. # TOP 15 high delete latency index
  3993. subheaderprint "Performance schema: TOP 15 high delete latency index";
  3994. $nbL = 1;
  3995. for my $lQuery (
  3996. select_array(
  3997. 'use sys;select table_schema, table_name,index_name, delete_latency from sys.x\\$schema_index_statistics ORDER BY delete_latency DESC LIMIT 15;'
  3998. )
  3999. )
  4000. {
  4001. infoprint " +-- $nbL: $lQuery";
  4002. $nbL++;
  4003. }
  4004. infoprint "No information found or indicators deactivated."
  4005. if ( $nbL == 1 );
  4006. # TOP 15 most read tables
  4007. subheaderprint "Performance schema: TOP 15 most read tables";
  4008. $nbL = 1;
  4009. for my $lQuery (
  4010. select_array(
  4011. 'use sys;select table_schema, table_name, rows_fetched from sys.x\\$schema_table_statistics ORDER BY ROWs_fetched DESC LIMIT 15;'
  4012. )
  4013. )
  4014. {
  4015. infoprint " +-- $nbL: $lQuery";
  4016. $nbL++;
  4017. }
  4018. infoprint "No information found or indicators deactivated."
  4019. if ( $nbL == 1 );
  4020. # TOP 15 most used tables
  4021. subheaderprint "Performance schema: TOP 15 most modified tables";
  4022. $nbL = 1;
  4023. for my $lQuery (
  4024. select_array(
  4025. 'use sys;select table_schema, table_name, rows_inserted+rows_updated+rows_deleted AS changes from sys.x\\$schema_table_statistics ORDER BY rows_inserted+rows_updated+rows_deleted DESC LIMIT 15;'
  4026. )
  4027. )
  4028. {
  4029. infoprint " +-- $nbL: $lQuery";
  4030. $nbL++;
  4031. }
  4032. infoprint "No information found or indicators deactivated."
  4033. if ( $nbL == 1 );
  4034. # TOP 15 high read latency tables
  4035. subheaderprint "Performance schema: TOP 15 high read latency tables";
  4036. $nbL = 1;
  4037. for my $lQuery (
  4038. select_array(
  4039. 'use sys;select table_schema, table_name, fetch_latency from sys.x\\$schema_table_statistics ORDER BY fetch_latency DESC LIMIT 15;'
  4040. )
  4041. )
  4042. {
  4043. infoprint " +-- $nbL: $lQuery";
  4044. $nbL++;
  4045. }
  4046. infoprint "No information found or indicators deactivated."
  4047. if ( $nbL == 1 );
  4048. # TOP 15 high insert latency tables
  4049. subheaderprint "Performance schema: TOP 15 high insert latency tables";
  4050. $nbL = 1;
  4051. for my $lQuery (
  4052. select_array(
  4053. 'use sys;select table_schema, table_name, insert_latency from sys.x\\$schema_table_statistics ORDER BY insert_latency DESC LIMIT 15;'
  4054. )
  4055. )
  4056. {
  4057. infoprint " +-- $nbL: $lQuery";
  4058. $nbL++;
  4059. }
  4060. infoprint "No information found or indicators deactivated."
  4061. if ( $nbL == 1 );
  4062. # TOP 15 high update latency tables
  4063. subheaderprint "Performance schema: TOP 15 high update latency tables";
  4064. $nbL = 1;
  4065. for my $lQuery (
  4066. select_array(
  4067. 'use sys;select table_schema, table_name, update_latency from sys.x\\$schema_table_statistics ORDER BY update_latency DESC LIMIT 15;'
  4068. )
  4069. )
  4070. {
  4071. infoprint " +-- $nbL: $lQuery";
  4072. $nbL++;
  4073. }
  4074. infoprint "No information found or indicators deactivated."
  4075. if ( $nbL == 1 );
  4076. # TOP 15 high delete latency tables
  4077. subheaderprint "Performance schema: TOP 15 high delete latency tables";
  4078. $nbL = 1;
  4079. for my $lQuery (
  4080. select_array(
  4081. 'use sys;select table_schema, table_name, delete_latency from sys.x\\$schema_table_statistics ORDER BY delete_latency DESC LIMIT 15;'
  4082. )
  4083. )
  4084. {
  4085. infoprint " +-- $nbL: $lQuery";
  4086. $nbL++;
  4087. }
  4088. infoprint "No information found or indicators deactivated."
  4089. if ( $nbL == 1 );
  4090. # Redundant indexes
  4091. subheaderprint "Performance schema: Redundant indexes";
  4092. $nbL = 1;
  4093. for my $lQuery (
  4094. select_array('use sys;select * from schema_redundant_indexes;') )
  4095. {
  4096. infoprint " +-- $nbL: $lQuery";
  4097. $nbL++;
  4098. }
  4099. infoprint "No information found or indicators deactivated."
  4100. if ( $nbL == 1 );
  4101. subheaderprint "Performance schema: Tables not using InnoDB buffer";
  4102. $nbL = 1;
  4103. for my $lQuery (
  4104. select_array(
  4105. ' Select table_schema, table_name from sys.x\\$schema_table_statistics_with_buffer where innodb_buffer_allocated IS NULL;'
  4106. )
  4107. )
  4108. {
  4109. infoprint " +-- $nbL: $lQuery";
  4110. $nbL++;
  4111. }
  4112. infoprint "No information found or indicators deactivated."
  4113. if ( $nbL == 1 );
  4114. subheaderprint "Performance schema: Table not using InnoDB buffer";
  4115. $nbL = 1;
  4116. for my $lQuery (
  4117. select_array(
  4118. ' Select table_schema, table_name from sys.x\\$schema_table_statistics_with_buffer where innodb_buffer_allocated IS NULL;'
  4119. )
  4120. )
  4121. {
  4122. infoprint " +-- $nbL: $lQuery";
  4123. $nbL++;
  4124. }
  4125. infoprint "No information found or indicators deactivated."
  4126. if ( $nbL == 1 );
  4127. subheaderprint "Performance schema: Table not using InnoDB buffer";
  4128. $nbL = 1;
  4129. for my $lQuery (
  4130. select_array(
  4131. ' Select table_schema, table_name from sys.x\\$schema_table_statistics_with_buffer where innodb_buffer_allocated IS NULL;'
  4132. )
  4133. )
  4134. {
  4135. infoprint " +-- $nbL: $lQuery";
  4136. $nbL++;
  4137. }
  4138. infoprint "No information found or indicators deactivated."
  4139. if ( $nbL == 1 );
  4140. subheaderprint "Performance schema: Top 15 Tables using InnoDB buffer";
  4141. $nbL = 1;
  4142. for my $lQuery (
  4143. select_array(
  4144. 'select table_schema,table_name,innodb_buffer_allocated from sys.x\\$schema_table_statistics_with_buffer where innodb_buffer_allocated IS NOT NULL ORDER BY innodb_buffer_allocated DESC LIMIT 15;'
  4145. )
  4146. )
  4147. {
  4148. infoprint " +-- $nbL: $lQuery";
  4149. $nbL++;
  4150. }
  4151. infoprint "No information found or indicators deactivated."
  4152. if ( $nbL == 1 );
  4153. subheaderprint "Performance schema: Top 15 Tables with InnoDB buffer free";
  4154. $nbL = 1;
  4155. for my $lQuery (
  4156. select_array(
  4157. 'select table_schema,table_name,innodb_buffer_free from sys.x\\$schema_table_statistics_with_buffer where innodb_buffer_allocated IS NOT NULL ORDER BY innodb_buffer_free DESC LIMIT 15;'
  4158. )
  4159. )
  4160. {
  4161. infoprint " +-- $nbL: $lQuery";
  4162. $nbL++;
  4163. }
  4164. infoprint "No information found or indicators deactivated."
  4165. if ( $nbL == 1 );
  4166. subheaderprint "Performance schema: Top 15 Most executed queries";
  4167. $nbL = 1;
  4168. for my $lQuery (
  4169. select_array(
  4170. 'select db, query, exec_count from sys.x\\$statement_analysis order by exec_count DESC LIMIT 15;'
  4171. )
  4172. )
  4173. {
  4174. infoprint " +-- $nbL: $lQuery";
  4175. $nbL++;
  4176. }
  4177. infoprint "No information found or indicators deactivated."
  4178. if ( $nbL == 1 );
  4179. subheaderprint
  4180. "Performance schema: Latest SQL queries in errors or warnings";
  4181. $nbL = 1;
  4182. for my $lQuery (
  4183. select_array(
  4184. 'select query, last_seen from sys.x\\$statements_with_errors_or_warnings ORDER BY last_seen LIMIT 100;'
  4185. )
  4186. )
  4187. {
  4188. infoprint " +-- $nbL: $lQuery";
  4189. $nbL++;
  4190. }
  4191. infoprint "No information found or indicators deactivated."
  4192. if ( $nbL == 1 );
  4193. subheaderprint "Performance schema: Top 20 queries with full table scans";
  4194. $nbL = 1;
  4195. for my $lQuery (
  4196. select_array(
  4197. 'select db, query, exec_count from sys.x\\$statements_with_full_table_scans order BY exec_count DESC LIMIT 20;'
  4198. )
  4199. )
  4200. {
  4201. infoprint " +-- $nbL: $lQuery";
  4202. $nbL++;
  4203. }
  4204. infoprint "No information found or indicators deactivated."
  4205. if ( $nbL == 1 );
  4206. subheaderprint "Performance schema: Last 50 queries with full table scans";
  4207. $nbL = 1;
  4208. for my $lQuery (
  4209. select_array(
  4210. 'select db, query, last_seen from sys.x\\$statements_with_full_table_scans order BY last_seen DESC LIMIT 50;'
  4211. )
  4212. )
  4213. {
  4214. infoprint " +-- $nbL: $lQuery";
  4215. $nbL++;
  4216. }
  4217. infoprint "No information found or indicators deactivated."
  4218. if ( $nbL == 1 );
  4219. subheaderprint "Performance schema: TOP 15 reader queries (95% percentile)";
  4220. $nbL = 1;
  4221. for my $lQuery (
  4222. select_array(
  4223. 'use sys;select db, query , rows_sent from sys.x\\$statements_with_runtimes_in_95th_percentile ORDER BY ROWs_sent DESC LIMIT 15;'
  4224. )
  4225. )
  4226. {
  4227. infoprint " +-- $nbL: $lQuery";
  4228. $nbL++;
  4229. }
  4230. infoprint "No information found or indicators deactivated."
  4231. if ( $nbL == 1 );
  4232. subheaderprint
  4233. "Performance schema: TOP 15 most row look queries (95% percentile)";
  4234. $nbL = 1;
  4235. for my $lQuery (
  4236. select_array(
  4237. 'use sys;select db, query, rows_examined AS search from sys.x\\$statements_with_runtimes_in_95th_percentile ORDER BY rows_examined DESC LIMIT 15;'
  4238. )
  4239. )
  4240. {
  4241. infoprint " +-- $nbL: $lQuery";
  4242. $nbL++;
  4243. }
  4244. infoprint "No information found or indicators deactivated."
  4245. if ( $nbL == 1 );
  4246. subheaderprint
  4247. "Performance schema: TOP 15 total latency queries (95% percentile)";
  4248. $nbL = 1;
  4249. for my $lQuery (
  4250. select_array(
  4251. 'use sys;select db, query, total_latency AS search from sys.x\\$statements_with_runtimes_in_95th_percentile ORDER BY total_latency DESC LIMIT 15;'
  4252. )
  4253. )
  4254. {
  4255. infoprint " +-- $nbL: $lQuery";
  4256. $nbL++;
  4257. }
  4258. infoprint "No information found or indicators deactivated."
  4259. if ( $nbL == 1 );
  4260. subheaderprint
  4261. "Performance schema: TOP 15 max latency queries (95% percentile)";
  4262. $nbL = 1;
  4263. for my $lQuery (
  4264. select_array(
  4265. 'use sys;select db, query, max_latency AS search from sys.x\\$statements_with_runtimes_in_95th_percentile ORDER BY max_latency DESC LIMIT 15;'
  4266. )
  4267. )
  4268. {
  4269. infoprint " +-- $nbL: $lQuery";
  4270. $nbL++;
  4271. }
  4272. infoprint "No information found or indicators deactivated."
  4273. if ( $nbL == 1 );
  4274. subheaderprint
  4275. "Performance schema: TOP 15 average latency queries (95% percentile)";
  4276. $nbL = 1;
  4277. for my $lQuery (
  4278. select_array(
  4279. 'use sys;select db, query, avg_latency AS search from sys.x\\$statements_with_runtimes_in_95th_percentile ORDER BY avg_latency DESC LIMIT 15;'
  4280. )
  4281. )
  4282. {
  4283. infoprint " +-- $nbL: $lQuery";
  4284. $nbL++;
  4285. }
  4286. infoprint "No information found or indicators deactivated."
  4287. if ( $nbL == 1 );
  4288. subheaderprint "Performance schema: Top 20 queries with sort";
  4289. $nbL = 1;
  4290. for my $lQuery (
  4291. select_array(
  4292. 'select db, query, exec_count from sys.x\\$statements_with_sorting order BY exec_count DESC LIMIT 20;'
  4293. )
  4294. )
  4295. {
  4296. infoprint " +-- $nbL: $lQuery";
  4297. $nbL++;
  4298. }
  4299. infoprint "No information found or indicators deactivated."
  4300. if ( $nbL == 1 );
  4301. subheaderprint "Performance schema: Last 50 queries with sort";
  4302. $nbL = 1;
  4303. for my $lQuery (
  4304. select_array(
  4305. 'select db, query, last_seen from sys.x\\$statements_with_sorting order BY last_seen DESC LIMIT 50;'
  4306. )
  4307. )
  4308. {
  4309. infoprint " +-- $nbL: $lQuery";
  4310. $nbL++;
  4311. }
  4312. infoprint "No information found or indicators deactivated."
  4313. if ( $nbL == 1 );
  4314. subheaderprint "Performance schema: TOP 15 row sorting queries with sort";
  4315. $nbL = 1;
  4316. for my $lQuery (
  4317. select_array(
  4318. 'use sys;select db, query , rows_sorted from sys.x\\$statements_with_sorting ORDER BY ROWs_sorted DESC LIMIT 15;'
  4319. )
  4320. )
  4321. {
  4322. infoprint " +-- $nbL: $lQuery";
  4323. $nbL++;
  4324. }
  4325. infoprint "No information found or indicators deactivated."
  4326. if ( $nbL == 1 );
  4327. subheaderprint "Performance schema: TOP 15 total latency queries with sort";
  4328. $nbL = 1;
  4329. for my $lQuery (
  4330. select_array(
  4331. 'use sys;select db, query, total_latency AS search from sys.x\\$statements_with_sorting ORDER BY total_latency DESC LIMIT 15;'
  4332. )
  4333. )
  4334. {
  4335. infoprint " +-- $nbL: $lQuery";
  4336. $nbL++;
  4337. }
  4338. infoprint "No information found or indicators deactivated."
  4339. if ( $nbL == 1 );
  4340. subheaderprint "Performance schema: TOP 15 merge queries with sort";
  4341. $nbL = 1;
  4342. for my $lQuery (
  4343. select_array(
  4344. 'use sys;select db, query, sort_merge_passes AS search from sys.x\\$statements_with_sorting ORDER BY sort_merge_passes DESC LIMIT 15;'
  4345. )
  4346. )
  4347. {
  4348. infoprint " +-- $nbL: $lQuery";
  4349. $nbL++;
  4350. }
  4351. infoprint "No information found or indicators deactivated."
  4352. if ( $nbL == 1 );
  4353. subheaderprint
  4354. "Performance schema: TOP 15 average sort merges queries with sort";
  4355. $nbL = 1;
  4356. for my $lQuery (
  4357. select_array(
  4358. 'select db, query, avg_sort_merges AS search from sys.x\\$statements_with_sorting ORDER BY avg_sort_merges DESC LIMIT 15;'
  4359. )
  4360. )
  4361. {
  4362. infoprint " +-- $nbL: $lQuery";
  4363. $nbL++;
  4364. }
  4365. infoprint "No information found or indicators deactivated."
  4366. if ( $nbL == 1 );
  4367. subheaderprint "Performance schema: TOP 15 scans queries with sort";
  4368. $nbL = 1;
  4369. for my $lQuery (
  4370. select_array(
  4371. 'use sys;select db, query, sorts_using_scans AS search from sys.x\\$statements_with_sorting ORDER BY sorts_using_scans DESC LIMIT 15;'
  4372. )
  4373. )
  4374. {
  4375. infoprint " +-- $nbL: $lQuery";
  4376. $nbL++;
  4377. }
  4378. infoprint "No information found or indicators deactivated."
  4379. if ( $nbL == 1 );
  4380. subheaderprint "Performance schema: TOP 15 range queries with sort";
  4381. $nbL = 1;
  4382. for my $lQuery (
  4383. select_array(
  4384. 'use sys;select db, query, sort_using_range AS search from sys.x\\$statements_with_sorting ORDER BY sort_using_range DESC LIMIT 15;'
  4385. )
  4386. )
  4387. {
  4388. infoprint " +-- $nbL: $lQuery";
  4389. $nbL++;
  4390. }
  4391. infoprint "No information found or indicators deactivated."
  4392. if ( $nbL == 1 );
  4393. ##################################################################################
  4394. #statements_with_temp_tables
  4395. #mysql> desc statements_with_temp_tables;
  4396. #+--------------------------+---------------------+------+-----+---------------------+-------+
  4397. #| Field | Type | Null | Key | Default | Extra |
  4398. #+--------------------------+---------------------+------+-----+---------------------+-------+
  4399. #| query | longtext | YES | | NULL | |
  4400. #| db | varchar(64) | YES | | NULL | |
  4401. #| exec_count | bigint(20) unsigned | NO | | NULL | |
  4402. #| total_latency | text | YES | | NULL | |
  4403. #| memory_tmp_tables | bigint(20) unsigned | NO | | NULL | |
  4404. #| disk_tmp_tables | bigint(20) unsigned | NO | | NULL | |
  4405. #| avg_tmp_tables_per_query | decimal(21,0) | NO | | 0 | |
  4406. #| tmp_tables_to_disk_pct | decimal(24,0) | NO | | 0 | |
  4407. #| first_seen | timestamp | NO | | 0000-00-00 00:00:00 | |
  4408. #| last_seen | timestamp | NO | | 0000-00-00 00:00:00 | |
  4409. #| digest | varchar(32) | YES | | NULL | |
  4410. #+--------------------------+---------------------+------+-----+---------------------+-------+
  4411. #11 rows in set (0,01 sec)#
  4412. #
  4413. subheaderprint "Performance schema: Top 20 queries with temp table";
  4414. $nbL = 1;
  4415. for my $lQuery (
  4416. select_array(
  4417. 'select db, query, exec_count from sys.x\\$statements_with_temp_tables order BY exec_count DESC LIMIT 20;'
  4418. )
  4419. )
  4420. {
  4421. infoprint " +-- $nbL: $lQuery";
  4422. $nbL++;
  4423. }
  4424. infoprint "No information found or indicators deactivated."
  4425. if ( $nbL == 1 );
  4426. subheaderprint "Performance schema: Last 50 queries with temp table";
  4427. $nbL = 1;
  4428. for my $lQuery (
  4429. select_array(
  4430. 'select db, query, last_seen from sys.x\\$statements_with_temp_tables order BY last_seen DESC LIMIT 50;'
  4431. )
  4432. )
  4433. {
  4434. infoprint " +-- $nbL: $lQuery";
  4435. $nbL++;
  4436. }
  4437. infoprint "No information found or indicators deactivated."
  4438. if ( $nbL == 1 );
  4439. subheaderprint
  4440. "Performance schema: TOP 15 total latency queries with temp table";
  4441. $nbL = 1;
  4442. for my $lQuery (
  4443. select_array(
  4444. 'select db, query, total_latency AS search from sys.x\\$statements_with_temp_tables ORDER BY total_latency DESC LIMIT 15;'
  4445. )
  4446. )
  4447. {
  4448. infoprint " +-- $nbL: $lQuery";
  4449. $nbL++;
  4450. }
  4451. infoprint "No information found or indicators deactivated."
  4452. if ( $nbL == 1 );
  4453. subheaderprint "Performance schema: TOP 15 queries with temp table to disk";
  4454. $nbL = 1;
  4455. for my $lQuery (
  4456. select_array(
  4457. 'use sys;select db, query, disk_tmp_tables from sys.x\\$statements_with_temp_tables ORDER BY disk_tmp_tables DESC LIMIT 15;'
  4458. )
  4459. )
  4460. {
  4461. infoprint " +-- $nbL: $lQuery";
  4462. $nbL++;
  4463. }
  4464. infoprint "No information found or indicators deactivated."
  4465. if ( $nbL == 1 );
  4466. ##################################################################################
  4467. #wait_classes_global_by_latency
  4468. #ysql> select * from wait_classes_global_by_latency;
  4469. #-----------------+-------+---------------+-------------+-------------+-------------+
  4470. # event_class | total | total_latency | min_latency | avg_latency | max_latency |
  4471. #-----------------+-------+---------------+-------------+-------------+-------------+
  4472. # wait/io/file | 15381 | 1.23 s | 0 ps | 80.12 us | 230.64 ms |
  4473. # wait/io/table | 59 | 7.57 ms | 5.45 us | 128.24 us | 3.95 ms |
  4474. # wait/lock/table | 69 | 3.22 ms | 658.84 ns | 46.64 us | 1.10 ms |
  4475. #-----------------+-------+---------------+-------------+-------------+-------------+
  4476. # rows in set (0,00 sec)
  4477. subheaderprint "Performance schema: TOP 15 class events by number";
  4478. $nbL = 1;
  4479. for my $lQuery (
  4480. select_array(
  4481. 'use sys;select event_class, total from sys.x\\$wait_classes_global_by_latency ORDER BY total DESC LIMIT 15;'
  4482. )
  4483. )
  4484. {
  4485. infoprint " +-- $nbL: $lQuery";
  4486. $nbL++;
  4487. }
  4488. infoprint "No information found or indicators deactivated."
  4489. if ( $nbL == 1 );
  4490. subheaderprint "Performance schema: TOP 30 events by number";
  4491. $nbL = 1;
  4492. for my $lQuery (
  4493. select_array(
  4494. 'use sys;select events, total from sys.x\\$waits_global_by_latency ORDER BY total DESC LIMIT 30;'
  4495. )
  4496. )
  4497. {
  4498. infoprint " +-- $nbL: $lQuery";
  4499. $nbL++;
  4500. }
  4501. infoprint "No information found or indicators deactivated."
  4502. if ( $nbL == 1 );
  4503. subheaderprint "Performance schema: TOP 15 class events by total latency";
  4504. $nbL = 1;
  4505. for my $lQuery (
  4506. select_array(
  4507. 'use sys;select event_class, total_latency from sys.x\\$wait_classes_global_by_latency ORDER BY total_latency DESC LIMIT 15;'
  4508. )
  4509. )
  4510. {
  4511. infoprint " +-- $nbL: $lQuery";
  4512. $nbL++;
  4513. }
  4514. infoprint "No information found or indicators deactivated."
  4515. if ( $nbL == 1 );
  4516. subheaderprint "Performance schema: TOP 30 events by total latency";
  4517. $nbL = 1;
  4518. for my $lQuery (
  4519. select_array(
  4520. 'use sys;select events, total_latency from sys.x\\$waits_global_by_latency ORDER BY total_latency DESC LIMIT 30;'
  4521. )
  4522. )
  4523. {
  4524. infoprint " +-- $nbL: $lQuery";
  4525. $nbL++;
  4526. }
  4527. infoprint "No information found or indicators deactivated."
  4528. if ( $nbL == 1 );
  4529. subheaderprint "Performance schema: TOP 15 class events by max latency";
  4530. $nbL = 1;
  4531. for my $lQuery (
  4532. select_array(
  4533. 'select event_class, max_latency from sys.x\\$wait_classes_global_by_latency ORDER BY max_latency DESC LIMIT 15;'
  4534. )
  4535. )
  4536. {
  4537. infoprint " +-- $nbL: $lQuery";
  4538. $nbL++;
  4539. }
  4540. infoprint "No information found or indicators deactivated."
  4541. if ( $nbL == 1 );
  4542. subheaderprint "Performance schema: TOP 30 events by max latency";
  4543. $nbL = 1;
  4544. for my $lQuery (
  4545. select_array(
  4546. 'select events, max_latency from sys.x\\$waits_global_by_latency ORDER BY max_latency DESC LIMIT 30;'
  4547. )
  4548. )
  4549. {
  4550. infoprint " +-- $nbL: $lQuery";
  4551. $nbL++;
  4552. }
  4553. infoprint "No information found or indicators deactivated."
  4554. if ( $nbL == 1 );
  4555. }
  4556. # Recommendations for Ariadb
  4557. sub mariadb_ariadb {
  4558. subheaderprint "AriaDB Metrics";
  4559. # AriaDB
  4560. unless ( defined $myvar{'have_aria'}
  4561. and $myvar{'have_aria'} eq "YES" )
  4562. {
  4563. infoprint "AriaDB is disabled.";
  4564. return;
  4565. }
  4566. infoprint "AriaDB is enabled.";
  4567. # Aria pagecache
  4568. if ( !defined( $mycalc{'total_aria_indexes'} ) and $doremote == 1 ) {
  4569. push( @generalrec,
  4570. "Unable to calculate Aria indexes on remote MySQL server < 5.0.0" );
  4571. }
  4572. elsif ( $mycalc{'total_aria_indexes'} =~ /^fail$/ ) {
  4573. badprint
  4574. "Cannot calculate Aria index size - re-run script as root user";
  4575. }
  4576. elsif ( $mycalc{'total_aria_indexes'} == "0" ) {
  4577. badprint
  4578. "None of your Aria tables are indexed - add indexes immediately";
  4579. }
  4580. else {
  4581. if (
  4582. $myvar{'aria_pagecache_buffer_size'} < $mycalc{'total_aria_indexes'}
  4583. && $mycalc{'pct_aria_keys_from_mem'} < 95 )
  4584. {
  4585. badprint "Aria pagecache size / total Aria indexes: "
  4586. . hr_bytes( $myvar{'aria_pagecache_buffer_size'} ) . "/"
  4587. . hr_bytes( $mycalc{'total_aria_indexes'} ) . "";
  4588. push( @adjvars,
  4589. "aria_pagecache_buffer_size (> "
  4590. . hr_bytes( $mycalc{'total_aria_indexes'} )
  4591. . ")" );
  4592. }
  4593. else {
  4594. goodprint "Aria pagecache size / total Aria indexes: "
  4595. . hr_bytes( $myvar{'aria_pagecache_buffer_size'} ) . "/"
  4596. . hr_bytes( $mycalc{'total_aria_indexes'} ) . "";
  4597. }
  4598. if ( $mystat{'Aria_pagecache_read_requests'} > 0 ) {
  4599. if ( $mycalc{'pct_aria_keys_from_mem'} < 95 ) {
  4600. badprint
  4601. "Aria pagecache hit rate: $mycalc{'pct_aria_keys_from_mem'}% ("
  4602. . hr_num( $mystat{'Aria_pagecache_read_requests'} )
  4603. . " cached / "
  4604. . hr_num( $mystat{'Aria_pagecache_reads'} )
  4605. . " reads)";
  4606. }
  4607. else {
  4608. goodprint
  4609. "Aria pagecache hit rate: $mycalc{'pct_aria_keys_from_mem'}% ("
  4610. . hr_num( $mystat{'Aria_pagecache_read_requests'} )
  4611. . " cached / "
  4612. . hr_num( $mystat{'Aria_pagecache_reads'} )
  4613. . " reads)";
  4614. }
  4615. }
  4616. else {
  4617. # No queries have run that would use keys
  4618. }
  4619. }
  4620. }
  4621. # Recommendations for TokuDB
  4622. sub mariadb_tokudb {
  4623. subheaderprint "TokuDB Metrics";
  4624. # AriaDB
  4625. unless ( defined $myvar{'have_tokudb'}
  4626. && $myvar{'have_tokudb'} eq "YES" )
  4627. {
  4628. infoprint "TokuDB is disabled.";
  4629. return;
  4630. }
  4631. infoprint "TokuDB is enabled.";
  4632. # All is to done here
  4633. }
  4634. # Recommendations for XtraDB
  4635. sub mariadb_xtradb {
  4636. subheaderprint "XtraDB Metrics";
  4637. # XtraDB
  4638. unless ( defined $myvar{'have_xtradb'}
  4639. && $myvar{'have_xtradb'} eq "YES" )
  4640. {
  4641. infoprint "XtraDB is disabled.";
  4642. return;
  4643. }
  4644. infoprint "XtraDB is enabled.";
  4645. infoprint "Note that MariaDB 10.2 makes use of InnoDB, not XtraDB."
  4646. # All is to done here
  4647. }
  4648. # Recommendations for RocksDB
  4649. sub mariadb_rockdb {
  4650. subheaderprint "RocksDB Metrics";
  4651. # RocksDB
  4652. unless ( defined $myvar{'have_rocksdb'}
  4653. && $myvar{'have_rocksdb'} eq "YES" )
  4654. {
  4655. infoprint "RocksDB is disabled.";
  4656. return;
  4657. }
  4658. infoprint "RocksDB is enabled.";
  4659. # All is to do here
  4660. }
  4661. # Recommendations for Spider
  4662. sub mariadb_spider {
  4663. subheaderprint "Spider Metrics";
  4664. # Spider
  4665. unless ( defined $myvar{'have_spider'}
  4666. && $myvar{'have_spider'} eq "YES" )
  4667. {
  4668. infoprint "Spider is disabled.";
  4669. return;
  4670. }
  4671. infoprint "Spider is enabled.";
  4672. # All is to do here
  4673. }
  4674. # Recommendations for Connect
  4675. sub mariadb_connect {
  4676. subheaderprint "Connect Metrics";
  4677. # Connect
  4678. unless ( defined $myvar{'have_connect'}
  4679. && $myvar{'have_connect'} eq "YES" )
  4680. {
  4681. infoprint "Connect is disabled.";
  4682. return;
  4683. }
  4684. infoprint "Connect is enabled.";
  4685. # All is to do here
  4686. }
  4687. # Perl trim function to remove whitespace from the start and end of the string
  4688. sub trim {
  4689. my $string = shift;
  4690. return "" unless defined($string);
  4691. $string =~ s/^\s+//;
  4692. $string =~ s/\s+$//;
  4693. return $string;
  4694. }
  4695. sub get_wsrep_options {
  4696. return () unless defined $myvar{'wsrep_provider_options'};
  4697. my @galera_options = split /;/, $myvar{'wsrep_provider_options'};
  4698. my $wsrep_slave_threads = $myvar{'wsrep_slave_threads'};
  4699. push @galera_options, ' wsrep_slave_threads = ' . $wsrep_slave_threads;
  4700. @galera_options = remove_cr @galera_options;
  4701. @galera_options = remove_empty @galera_options;
  4702. debugprint Dumper( \@galera_options );
  4703. return @galera_options;
  4704. }
  4705. sub get_gcache_memory {
  4706. my $gCacheMem = hr_raw( get_wsrep_option('gcache.size') );
  4707. return 0 unless defined $gCacheMem and $gCacheMem ne '';
  4708. return $gCacheMem;
  4709. }
  4710. sub get_wsrep_option {
  4711. my $key = shift;
  4712. return '' unless defined $myvar{'wsrep_provider_options'};
  4713. my @galera_options = get_wsrep_options;
  4714. return '' unless scalar(@galera_options) > 0;
  4715. my @memValues = grep /\s*$key =/, @galera_options;
  4716. my $memValue = $memValues[0];
  4717. return 0 unless defined $memValue;
  4718. $memValue =~ s/.*=\s*(.+)$/$1/g;
  4719. return $memValue;
  4720. }
  4721. # Recommendations for Galera
  4722. sub mariadb_galera {
  4723. subheaderprint "Galera Metrics";
  4724. # Galera Cluster
  4725. unless ( defined $myvar{'have_galera'}
  4726. && $myvar{'have_galera'} eq "YES" )
  4727. {
  4728. infoprint "Galera is disabled.";
  4729. return;
  4730. }
  4731. infoprint "Galera is enabled.";
  4732. debugprint "Galera variables:";
  4733. foreach my $gvar ( keys %myvar ) {
  4734. next unless $gvar =~ /^wsrep.*/;
  4735. next if $gvar eq 'wsrep_provider_options';
  4736. debugprint "\t" . trim($gvar) . " = " . $myvar{$gvar};
  4737. $result{'Galera'}{'variables'}{$gvar} = $myvar{$gvar};
  4738. }
  4739. debugprint "Galera wsrep provider Options:";
  4740. my @galera_options = get_wsrep_options;
  4741. $result{'Galera'}{'wsrep options'} = get_wsrep_options();
  4742. foreach my $gparam (@galera_options) {
  4743. debugprint "\t" . trim($gparam);
  4744. }
  4745. debugprint "Galera status:";
  4746. foreach my $gstatus ( keys %mystat ) {
  4747. next unless $gstatus =~ /^wsrep.*/;
  4748. debugprint "\t" . trim($gstatus) . " = " . $mystat{$gstatus};
  4749. $result{'Galera'}{'status'}{$gstatus} = $myvar{$gstatus};
  4750. }
  4751. infoprint "GCache is using "
  4752. . hr_bytes_rnd( get_wsrep_option('gcache.mem_size') );
  4753. #my @primaryKeysNbTables=();
  4754. my @primaryKeysNbTables = select_array(
  4755. "Select CONCAT(c.table_schema,CONCAT('.', c.table_name))
  4756. from information_schema.columns c
  4757. join information_schema.tables t using (TABLE_SCHEMA, TABLE_NAME)
  4758. where c.table_schema not in ('mysql', 'information_schema', 'performance_schema')
  4759. and t.table_type != 'VIEW'
  4760. group by c.table_schema,c.table_name
  4761. having sum(if(c.column_key in ('PRI','UNI'), 1,0)) = 0"
  4762. );
  4763. infoprint "CPU core detected : ". (cpu_cores);
  4764. infoprint "wsrep_slave_threads: ". get_wsrep_option('wsrep_slave_threads');
  4765. if ( get_wsrep_option('wsrep_slave_threads') > ((cpu_cores) * 4)
  4766. or get_wsrep_option('wsrep_slave_threads') < ((cpu_cores) * 2) )
  4767. {
  4768. badprint
  4769. "wsrep_slave_threads is not equal to 2, 3 or 4 times number of CPU(s)";
  4770. push @adjvars, "wsrep_slave_threads = ".((cpu_cores) * 4);
  4771. }
  4772. else {
  4773. goodprint
  4774. "wsrep_slave_threads is equal to 2, 3 or 4 times number of CPU(s)";
  4775. }
  4776. if ( get_wsrep_option('gcs.fc_limit') !=
  4777. get_wsrep_option('wsrep_slave_threads') * 5 )
  4778. {
  4779. badprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads";
  4780. push @adjvars, "gcs.fc_limit= wsrep_slave_threads * 5";
  4781. }
  4782. else {
  4783. goodprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads";
  4784. }
  4785. if ( get_wsrep_option('wsrep_slave_threads') > 1 ) {
  4786. infoprint
  4787. "wsrep parallel slave can cause frequent inconsistency crash.";
  4788. push @adjvars,
  4789. "Set wsrep_slave_threads to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
  4790. # check options for parallel slave
  4791. if ( get_wsrep_option('wsrep_slave_FK_checks') eq "OFF" ) {
  4792. badprint "wsrep_slave_FK_checks is off with parallel slave";
  4793. push @adjvars,
  4794. "wsrep_slave_FK_checks should be ON when using parallel slave";
  4795. }
  4796. # wsrep_slave_UK_checks seems useless in MySQL source code
  4797. if ( $myvar{'innodb_autoinc_lock_mode'} != 2 ) {
  4798. badprint
  4799. "innodb_autoinc_lock_mode is incorrect with parallel slave";
  4800. push @adjvars,
  4801. "innodb_autoinc_lock_mode should be 2 when using parallel slave";
  4802. }
  4803. }
  4804. if ( get_wsrep_option('gcs.fc_limit') != $myvar{'wsrep_slave_threads'} * 5 )
  4805. {
  4806. badprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads";
  4807. push @adjvars, "gcs.fc_limit= wsrep_slave_threads * 5";
  4808. }
  4809. else {
  4810. goodprint "gcs.fc_limit is equal to 5 * wsrep_slave_threads";
  4811. }
  4812. if ( get_wsrep_option('gcs.fc_factor') != 0.8 ) {
  4813. badprint "gcs.fc_factor should be equal to 0.8";
  4814. push @adjvars, "gcs.fc_factor=0.8";
  4815. }
  4816. else {
  4817. goodprint "gcs.fc_factor is equal to 0.8";
  4818. }
  4819. if ( get_wsrep_option('wsrep_flow_control_paused') > 0.02 ) {
  4820. badprint "Fraction of time node pause flow control > 0.02";
  4821. }
  4822. else {
  4823. goodprint
  4824. "Flow control fraction seems to be OK (wsrep_flow_control_paused<=0.02)";
  4825. }
  4826. if ( scalar(@primaryKeysNbTables) > 0 ) {
  4827. badprint "Following table(s) don't have primary key:";
  4828. foreach my $badtable (@primaryKeysNbTables) {
  4829. badprint "\t$badtable";
  4830. push @{ $result{'Tables without PK'} }, $badtable;
  4831. }
  4832. }
  4833. else {
  4834. goodprint "All tables get a primary key";
  4835. }
  4836. my @nonInnoDBTables = select_array(
  4837. "select CONCAT(table_schema,CONCAT('.', table_name)) from information_schema.tables where ENGINE <> 'InnoDB' and table_schema not in ('mysql', 'performance_schema', 'information_schema')"
  4838. );
  4839. if ( scalar(@nonInnoDBTables) > 0 ) {
  4840. badprint "Following table(s) are not InnoDB table:";
  4841. push @generalrec,
  4842. "Ensure that all table(s) are InnoDB tables for Galera replication";
  4843. foreach my $badtable (@nonInnoDBTables) {
  4844. badprint "\t$badtable";
  4845. }
  4846. }
  4847. else {
  4848. goodprint "All tables are InnoDB tables";
  4849. }
  4850. if ( $myvar{'binlog_format'} ne 'ROW' ) {
  4851. badprint "Binlog format should be in ROW mode.";
  4852. push @adjvars, "binlog_format = ROW";
  4853. }
  4854. else {
  4855. goodprint "Binlog format is in ROW mode.";
  4856. }
  4857. if ( $myvar{'innodb_flush_log_at_trx_commit'} != 0 ) {
  4858. badprint "InnoDB flush log at each commit should be disabled.";
  4859. push @adjvars, "innodb_flush_log_at_trx_commit = 0";
  4860. }
  4861. else {
  4862. goodprint "InnoDB flush log at each commit is disabled for Galera.";
  4863. }
  4864. infoprint "Read consistency mode :" . $myvar{'wsrep_causal_reads'};
  4865. if ( defined( $myvar{'wsrep_cluster_name'} )
  4866. and $myvar{'wsrep_on'} eq "ON" )
  4867. {
  4868. goodprint "Galera WsREP is enabled.";
  4869. if ( defined( $myvar{'wsrep_cluster_address'} )
  4870. and trim("$myvar{'wsrep_cluster_address'}") ne "" )
  4871. {
  4872. goodprint "Galera Cluster address is defined: "
  4873. . $myvar{'wsrep_cluster_address'};
  4874. my @NodesTmp = split /,/, $myvar{'wsrep_cluster_address'};
  4875. my $nbNodes = @NodesTmp;
  4876. infoprint "There are $nbNodes nodes in wsrep_cluster_address";
  4877. my $nbNodesSize = trim( $mystat{'wsrep_cluster_size'} );
  4878. if ( $nbNodesSize == 3 or $nbNodesSize == 5 ) {
  4879. goodprint "There are $nbNodesSize nodes in wsrep_cluster_size.";
  4880. }
  4881. else {
  4882. badprint
  4883. "There are $nbNodesSize nodes in wsrep_cluster_size. Prefer 3 or 5 nodes architecture.";
  4884. push @generalrec, "Prefer 3 or 5 nodes architecture.";
  4885. }
  4886. # wsrep_cluster_address doesn't include garbd nodes
  4887. if ( $nbNodes > $nbNodesSize ) {
  4888. badprint
  4889. "All cluster nodes are not detected. wsrep_cluster_size less then node count in wsrep_cluster_address";
  4890. }
  4891. else {
  4892. goodprint "All cluster nodes detected.";
  4893. }
  4894. }
  4895. else {
  4896. badprint "Galera Cluster address is undefined";
  4897. push @adjvars,
  4898. "set up wsrep_cluster_address variable for Galera replication";
  4899. }
  4900. if ( defined( $myvar{'wsrep_cluster_name'} )
  4901. and trim( $myvar{'wsrep_cluster_name'} ) ne "" )
  4902. {
  4903. goodprint "Galera Cluster name is defined: "
  4904. . $myvar{'wsrep_cluster_name'};
  4905. }
  4906. else {
  4907. badprint "Galera Cluster name is undefined";
  4908. push @adjvars,
  4909. "set up wsrep_cluster_name variable for Galera replication";
  4910. }
  4911. if ( defined( $myvar{'wsrep_node_name'} )
  4912. and trim( $myvar{'wsrep_node_name'} ) ne "" )
  4913. {
  4914. goodprint "Galera Node name is defined: "
  4915. . $myvar{'wsrep_node_name'};
  4916. }
  4917. else {
  4918. badprint "Galera node name is undefined";
  4919. push @adjvars,
  4920. "set up wsrep_node_name variable for Galera replication";
  4921. }
  4922. if ( trim( $myvar{'wsrep_notify_cmd'} ) ne "" ) {
  4923. goodprint "Galera Notify command is defined.";
  4924. }
  4925. else {
  4926. badprint "Galera Notify command is not defined.";
  4927. push( @adjvars, "set up parameter wsrep_notify_cmd to be notify" );
  4928. }
  4929. if ( trim( $myvar{'wsrep_sst_method'} ) !~ "^xtrabackup.*"
  4930. and trim( $myvar{'wsrep_sst_method'} ) !~ "^mariabackup" )
  4931. {
  4932. badprint "Galera SST method is not xtrabackup based.";
  4933. push( @adjvars,
  4934. "set up parameter wsrep_sst_method to xtrabackup based parameter"
  4935. );
  4936. }
  4937. else {
  4938. goodprint "SST Method is based on xtrabackup.";
  4939. }
  4940. if (
  4941. (
  4942. defined( $myvar{'wsrep_OSU_method'} )
  4943. && trim( $myvar{'wsrep_OSU_method'} ) eq "TOI"
  4944. )
  4945. || ( defined( $myvar{'wsrep_osu_method'} )
  4946. && trim( $myvar{'wsrep_osu_method'} ) eq "TOI" )
  4947. )
  4948. {
  4949. goodprint "TOI is default mode for upgrade.";
  4950. }
  4951. else {
  4952. badprint "Schema upgrade are not replicated automatically";
  4953. push( @adjvars, "set up parameter wsrep_OSU_method to TOI" );
  4954. }
  4955. infoprint "Max WsRep message : "
  4956. . hr_bytes( $myvar{'wsrep_max_ws_size'} );
  4957. }
  4958. else {
  4959. badprint "Galera WsREP is disabled";
  4960. }
  4961. if ( defined( $mystat{'wsrep_connected'} )
  4962. and $mystat{'wsrep_connected'} eq "ON" )
  4963. {
  4964. goodprint "Node is connected";
  4965. }
  4966. else {
  4967. badprint "Node is disconnected";
  4968. }
  4969. if ( defined( $mystat{'wsrep_ready'} ) and $mystat{'wsrep_ready'} eq "ON" )
  4970. {
  4971. goodprint "Node is ready";
  4972. }
  4973. else {
  4974. badprint "Node is not ready";
  4975. }
  4976. infoprint "Cluster status :" . $mystat{'wsrep_cluster_status'};
  4977. if ( defined( $mystat{'wsrep_cluster_status'} )
  4978. and $mystat{'wsrep_cluster_status'} eq "Primary" )
  4979. {
  4980. goodprint "Galera cluster is consistent and ready for operations";
  4981. }
  4982. else {
  4983. badprint "Cluster is not consistent and ready";
  4984. }
  4985. if ( $mystat{'wsrep_local_state_uuid'} eq
  4986. $mystat{'wsrep_cluster_state_uuid'} )
  4987. {
  4988. goodprint "Node and whole cluster at the same level: "
  4989. . $mystat{'wsrep_cluster_state_uuid'};
  4990. }
  4991. else {
  4992. badprint "Node and whole cluster not the same level";
  4993. infoprint "Node state uuid: " . $mystat{'wsrep_local_state_uuid'};
  4994. infoprint "Cluster state uuid: " . $mystat{'wsrep_cluster_state_uuid'};
  4995. }
  4996. if ( $mystat{'wsrep_local_state_comment'} eq 'Synced' ) {
  4997. goodprint "Node is synced with whole cluster.";
  4998. }
  4999. else {
  5000. badprint "Node is not synced";
  5001. infoprint "Node State : " . $mystat{'wsrep_local_state_comment'};
  5002. }
  5003. if ( $mystat{'wsrep_local_cert_failures'} == 0 ) {
  5004. goodprint "There is no certification failures detected.";
  5005. }
  5006. else {
  5007. badprint "There is "
  5008. . $mystat{'wsrep_local_cert_failures'}
  5009. . " certification failure(s)detected.";
  5010. }
  5011. for my $key ( keys %mystat ) {
  5012. if ( $key =~ /wsrep_|galera/i ) {
  5013. debugprint "WSREP: $key = $mystat{$key}";
  5014. }
  5015. }
  5016. debugprint Dumper get_wsrep_options();
  5017. }
  5018. # Recommendations for InnoDB
  5019. sub mysql_innodb {
  5020. subheaderprint "InnoDB Metrics";
  5021. # InnoDB
  5022. unless ( defined $myvar{'have_innodb'}
  5023. && $myvar{'have_innodb'} eq "YES"
  5024. && defined $enginestats{'InnoDB'} )
  5025. {
  5026. infoprint "InnoDB is disabled.";
  5027. if ( mysql_version_ge( 5, 5 ) ) {
  5028. badprint
  5029. "InnoDB Storage engine is disabled. InnoDB is the default storage engine";
  5030. }
  5031. return;
  5032. }
  5033. infoprint "InnoDB is enabled.";
  5034. if ( $opt{buffers} ne 0 ) {
  5035. infoprint "InnoDB Buffers";
  5036. if ( defined $myvar{'innodb_buffer_pool_size'} ) {
  5037. infoprint " +-- InnoDB Buffer Pool: "
  5038. . hr_bytes( $myvar{'innodb_buffer_pool_size'} ) . "";
  5039. }
  5040. if ( defined $myvar{'innodb_buffer_pool_instances'} ) {
  5041. infoprint " +-- InnoDB Buffer Pool Instances: "
  5042. . $myvar{'innodb_buffer_pool_instances'} . "";
  5043. }
  5044. if ( defined $myvar{'innodb_buffer_pool_chunk_size'} ) {
  5045. infoprint " +-- InnoDB Buffer Pool Chunk Size: "
  5046. . hr_bytes( $myvar{'innodb_buffer_pool_chunk_size'} ) . "";
  5047. }
  5048. if ( defined $myvar{'innodb_additional_mem_pool_size'} ) {
  5049. infoprint " +-- InnoDB Additional Mem Pool: "
  5050. . hr_bytes( $myvar{'innodb_additional_mem_pool_size'} ) . "";
  5051. }
  5052. if ( defined $myvar{'innodb_log_file_size'} ) {
  5053. infoprint " +-- InnoDB Log File Size: "
  5054. . hr_bytes( $myvar{'innodb_log_file_size'} );
  5055. }
  5056. if ( defined $myvar{'innodb_log_files_in_group'} ) {
  5057. infoprint " +-- InnoDB Log File In Group: "
  5058. . $myvar{'innodb_log_files_in_group'};
  5059. }
  5060. if ( defined $myvar{'innodb_log_files_in_group'} ) {
  5061. infoprint " +-- InnoDB Total Log File Size: "
  5062. . hr_bytes( $myvar{'innodb_log_files_in_group'} *
  5063. $myvar{'innodb_log_file_size'} )
  5064. . "("
  5065. . $mycalc{'innodb_log_size_pct'}
  5066. . " % of buffer pool)";
  5067. }
  5068. if ( defined $myvar{'innodb_log_buffer_size'} ) {
  5069. infoprint " +-- InnoDB Log Buffer: "
  5070. . hr_bytes( $myvar{'innodb_log_buffer_size'} );
  5071. }
  5072. if ( defined $mystat{'Innodb_buffer_pool_pages_free'} ) {
  5073. infoprint " +-- InnoDB Log Buffer Free: "
  5074. . hr_bytes( $mystat{'Innodb_buffer_pool_pages_free'} ) . "";
  5075. }
  5076. if ( defined $mystat{'Innodb_buffer_pool_pages_total'} ) {
  5077. infoprint " +-- InnoDB Log Buffer Used: "
  5078. . hr_bytes( $mystat{'Innodb_buffer_pool_pages_total'} ) . "";
  5079. }
  5080. }
  5081. if ( defined $myvar{'innodb_thread_concurrency'} ) {
  5082. infoprint "InnoDB Thread Concurrency: "
  5083. . $myvar{'innodb_thread_concurrency'};
  5084. }
  5085. # InnoDB Buffer Pool Size
  5086. if ( $myvar{'innodb_file_per_table'} eq "ON" ) {
  5087. goodprint "InnoDB File per table is activated";
  5088. }
  5089. else {
  5090. badprint "InnoDB File per table is not activated";
  5091. push( @adjvars, "innodb_file_per_table=ON" );
  5092. }
  5093. # InnoDB Buffer Pool Size
  5094. if ( $myvar{'innodb_buffer_pool_size'} > $enginestats{'InnoDB'} ) {
  5095. goodprint "InnoDB buffer pool / data size: "
  5096. . hr_bytes( $myvar{'innodb_buffer_pool_size'} ) . "/"
  5097. . hr_bytes( $enginestats{'InnoDB'} ) . "";
  5098. }
  5099. else {
  5100. badprint "InnoDB buffer pool / data size: "
  5101. . hr_bytes( $myvar{'innodb_buffer_pool_size'} ) . "/"
  5102. . hr_bytes( $enginestats{'InnoDB'} ) . "";
  5103. push( @adjvars,
  5104. "innodb_buffer_pool_size (>= "
  5105. . hr_bytes( $enginestats{'InnoDB'} )
  5106. . ") if possible." );
  5107. }
  5108. if ( $mycalc{'innodb_log_size_pct'} < 20
  5109. or $mycalc{'innodb_log_size_pct'} > 30 )
  5110. {
  5111. badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
  5112. . $mycalc{'innodb_log_size_pct'} . " %): "
  5113. . hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
  5114. . $myvar{'innodb_log_files_in_group'} . "/"
  5115. . hr_bytes( $myvar{'innodb_buffer_pool_size'} )
  5116. . " should be equal 25%";
  5117. push(
  5118. @adjvars,
  5119. "innodb_log_file_size should be (="
  5120. . hr_bytes_rnd(
  5121. $myvar{'innodb_buffer_pool_size'} /
  5122. $myvar{'innodb_log_files_in_group'} / 4
  5123. )
  5124. . ") if possible, so InnoDB total log files size equals to 25% of buffer pool size."
  5125. );
  5126. push( @generalrec,
  5127. "Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: http://bit.ly/2wgkDvS"
  5128. );
  5129. }
  5130. else {
  5131. goodprint "Ratio InnoDB log file size / InnoDB Buffer pool size: "
  5132. . hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
  5133. . $myvar{'innodb_log_files_in_group'} . "/"
  5134. . hr_bytes( $myvar{'innodb_buffer_pool_size'} )
  5135. . " should be equal 25%";
  5136. }
  5137. # InnoDB Buffer Pool Instances (MySQL 5.6.6+)
  5138. if ( defined( $myvar{'innodb_buffer_pool_instances'} ) ) {
  5139. # Bad Value if > 64
  5140. if ( $myvar{'innodb_buffer_pool_instances'} > 64 ) {
  5141. badprint "InnoDB buffer pool instances: "
  5142. . $myvar{'innodb_buffer_pool_instances'} . "";
  5143. push( @adjvars, "innodb_buffer_pool_instances (<= 64)" );
  5144. }
  5145. # InnoDB Buffer Pool Size > 1Go
  5146. if ( $myvar{'innodb_buffer_pool_size'} > 1024 * 1024 * 1024 ) {
  5147. # InnoDB Buffer Pool Size / 1Go = InnoDB Buffer Pool Instances limited to 64 max.
  5148. # InnoDB Buffer Pool Size > 64Go
  5149. my $max_innodb_buffer_pool_instances =
  5150. int( $myvar{'innodb_buffer_pool_size'} / ( 1024 * 1024 * 1024 ) );
  5151. $max_innodb_buffer_pool_instances = 64
  5152. if ( $max_innodb_buffer_pool_instances > 64 );
  5153. if ( $myvar{'innodb_buffer_pool_instances'} !=
  5154. $max_innodb_buffer_pool_instances )
  5155. {
  5156. badprint "InnoDB buffer pool instances: "
  5157. . $myvar{'innodb_buffer_pool_instances'} . "";
  5158. push( @adjvars,
  5159. "innodb_buffer_pool_instances(="
  5160. . $max_innodb_buffer_pool_instances
  5161. . ")" );
  5162. }
  5163. else {
  5164. goodprint "InnoDB buffer pool instances: "
  5165. . $myvar{'innodb_buffer_pool_instances'} . "";
  5166. }
  5167. # InnoDB Buffer Pool Size < 1Go
  5168. }
  5169. else {
  5170. if ( $myvar{'innodb_buffer_pool_instances'} != 1 ) {
  5171. badprint
  5172. "InnoDB buffer pool <= 1G and Innodb_buffer_pool_instances(!=1).";
  5173. push( @adjvars, "innodb_buffer_pool_instances (=1)" );
  5174. }
  5175. else {
  5176. goodprint "InnoDB buffer pool instances: "
  5177. . $myvar{'innodb_buffer_pool_instances'} . "";
  5178. }
  5179. }
  5180. }
  5181. # InnoDB Used Buffer Pool Size vs CHUNK size
  5182. if ( !defined( $myvar{'innodb_buffer_pool_chunk_size'} ) ) {
  5183. infoprint
  5184. "InnoDB Buffer Pool Chunk Size not used or defined in your version";
  5185. }
  5186. else {
  5187. infoprint "Number of InnoDB Buffer Pool Chunk : "
  5188. . int( $myvar{'innodb_buffer_pool_size'} ) /
  5189. int( $myvar{'innodb_buffer_pool_chunk_size'} ) . " for "
  5190. . $myvar{'innodb_buffer_pool_instances'}
  5191. . " Buffer Pool Instance(s)";
  5192. if (
  5193. int( $myvar{'innodb_buffer_pool_size'} ) % (
  5194. int( $myvar{'innodb_buffer_pool_chunk_size'} ) *
  5195. int( $myvar{'innodb_buffer_pool_instances'} )
  5196. ) eq 0
  5197. )
  5198. {
  5199. goodprint
  5200. "Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances";
  5201. }
  5202. else {
  5203. badprint
  5204. "Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances";
  5205. #push( @adjvars, "Adjust innodb_buffer_pool_instances, innodb_buffer_pool_chunk_size with innodb_buffer_pool_size" );
  5206. push( @adjvars,
  5207. "innodb_buffer_pool_size must always be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances"
  5208. );
  5209. }
  5210. }
  5211. # InnoDB Read efficiency
  5212. if ( defined $mycalc{'pct_read_efficiency'}
  5213. && $mycalc{'pct_read_efficiency'} < 90 )
  5214. {
  5215. badprint "InnoDB Read buffer efficiency: "
  5216. . $mycalc{'pct_read_efficiency'} . "% ("
  5217. . ( $mystat{'Innodb_buffer_pool_read_requests'} -
  5218. $mystat{'Innodb_buffer_pool_reads'} )
  5219. . " hits/ "
  5220. . $mystat{'Innodb_buffer_pool_read_requests'}
  5221. . " total)";
  5222. }
  5223. else {
  5224. goodprint "InnoDB Read buffer efficiency: "
  5225. . $mycalc{'pct_read_efficiency'} . "% ("
  5226. . ( $mystat{'Innodb_buffer_pool_read_requests'} -
  5227. $mystat{'Innodb_buffer_pool_reads'} )
  5228. . " hits/ "
  5229. . $mystat{'Innodb_buffer_pool_read_requests'}
  5230. . " total)";
  5231. }
  5232. # InnoDB Write efficiency
  5233. if ( defined $mycalc{'pct_write_efficiency'}
  5234. && $mycalc{'pct_write_efficiency'} < 90 )
  5235. {
  5236. badprint "InnoDB Write Log efficiency: "
  5237. . abs( $mycalc{'pct_write_efficiency'} ) . "% ("
  5238. . abs( $mystat{'Innodb_log_write_requests'} -
  5239. $mystat{'Innodb_log_writes'} )
  5240. . " hits/ "
  5241. . $mystat{'Innodb_log_write_requests'}
  5242. . " total)";
  5243. }
  5244. else {
  5245. goodprint "InnoDB Write log efficiency: "
  5246. . $mycalc{'pct_write_efficiency'} . "% ("
  5247. . ( $mystat{'Innodb_log_write_requests'} -
  5248. $mystat{'Innodb_log_writes'} )
  5249. . " hits/ "
  5250. . $mystat{'Innodb_log_write_requests'}
  5251. . " total)";
  5252. }
  5253. # InnoDB Log Waits
  5254. if ( defined $mystat{'Innodb_log_waits'}
  5255. && $mystat{'Innodb_log_waits'} > 0 )
  5256. {
  5257. badprint "InnoDB log waits: "
  5258. . percentage( $mystat{'Innodb_log_waits'},
  5259. $mystat{'Innodb_log_writes'} )
  5260. . "% ("
  5261. . $mystat{'Innodb_log_waits'}
  5262. . " waits / "
  5263. . $mystat{'Innodb_log_writes'}
  5264. . " writes)";
  5265. push( @adjvars,
  5266. "innodb_log_buffer_size (>= "
  5267. . hr_bytes_rnd( $myvar{'innodb_log_buffer_size'} )
  5268. . ")" );
  5269. }
  5270. else {
  5271. goodprint "InnoDB log waits: "
  5272. . percentage( $mystat{'Innodb_log_waits'},
  5273. $mystat{'Innodb_log_writes'} )
  5274. . "% ("
  5275. . $mystat{'Innodb_log_waits'}
  5276. . " waits / "
  5277. . $mystat{'Innodb_log_writes'}
  5278. . " writes)";
  5279. }
  5280. $result{'Calculations'} = {%mycalc};
  5281. }
  5282. sub check_metadata_perf {
  5283. subheaderprint "Analysis Performance Metrics";
  5284. infoprint "innodb_stats_on_metadata: ".$myvar{'innodb_stats_on_metadata'};
  5285. if ($myvar{'innodb_stats_on_metadata'} eq 'ON') {
  5286. badprint "Stat are updated during querying INFORMATION_SCHEMA.";
  5287. push @adjvars, "SET innodb_stats_on_metadata = OFF";
  5288. #Disabling innodb_stats_on_metadata
  5289. select_one("SET GLOBAL innodb_stats_on_metadata = OFF;");
  5290. return 1;
  5291. }
  5292. goodprint "No stat updates during querying INFORMATION_SCHEMA.";
  5293. return 0
  5294. }
  5295. # Recommendations for Database metrics
  5296. sub mysql_databases {
  5297. return if ( $opt{dbstat} == 0 );
  5298. subheaderprint "Database Metrics";
  5299. unless ( mysql_version_ge( 5, 5 ) ) {
  5300. infoprint
  5301. "Skip Database metrics from information schema missing in this version";
  5302. return;
  5303. }
  5304. my @dblist = select_array(
  5305. "SELECT DISTINCT TABLE_SCHEMA FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
  5306. );
  5307. infoprint "There is " . scalar(@dblist) . " Database(s).";
  5308. my @totaldbinfo = split /\s/,
  5309. select_one(
  5310. "SELECT SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH) , SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(TABLE_NAME),COUNT(DISTINCT(TABLE_COLLATION)),COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
  5311. );
  5312. infoprint "All User Databases:";
  5313. infoprint " +-- TABLE : "
  5314. . ( $totaldbinfo[4] eq 'NULL' ? 0 : $totaldbinfo[4] ) . "";
  5315. infoprint " +-- ROWS : "
  5316. . ( $totaldbinfo[0] eq 'NULL' ? 0 : $totaldbinfo[0] ) . "";
  5317. infoprint " +-- DATA : "
  5318. . hr_bytes( $totaldbinfo[1] ) . "("
  5319. . percentage( $totaldbinfo[1], $totaldbinfo[3] ) . "%)";
  5320. infoprint " +-- INDEX : "
  5321. . hr_bytes( $totaldbinfo[2] ) . "("
  5322. . percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%)";
  5323. infoprint " +-- SIZE : " . hr_bytes( $totaldbinfo[3] ) . "";
  5324. infoprint " +-- COLLA : "
  5325. . ( $totaldbinfo[5] eq 'NULL' ? 0 : $totaldbinfo[5] ) . " ("
  5326. . (
  5327. join ", ",
  5328. select_array(
  5329. "SELECT DISTINCT(TABLE_COLLATION) FROM information_schema.TABLES;")
  5330. ) . ")";
  5331. infoprint " +-- ENGIN : "
  5332. . ( $totaldbinfo[6] eq 'NULL' ? 0 : $totaldbinfo[6] ) . " ("
  5333. . (
  5334. join ", ",
  5335. select_array("SELECT DISTINCT(ENGINE) FROM information_schema.TABLES;")
  5336. ) . ")";
  5337. $result{'Databases'}{'All databases'}{'Rows'} =
  5338. ( $totaldbinfo[0] eq 'NULL' ? 0 : $totaldbinfo[0] );
  5339. $result{'Databases'}{'All databases'}{'Data Size'} = $totaldbinfo[1];
  5340. $result{'Databases'}{'All databases'}{'Data Pct'} =
  5341. percentage( $totaldbinfo[1], $totaldbinfo[3] ) . "%";
  5342. $result{'Databases'}{'All databases'}{'Index Size'} = $totaldbinfo[2];
  5343. $result{'Databases'}{'All databases'}{'Index Pct'} =
  5344. percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
  5345. $result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
  5346. print "\n" unless ( $opt{'silent'} or $opt{'json'} );
  5347. foreach (@dblist) {
  5348. my @dbinfo = split /\s/,
  5349. select_one(
  5350. "SELECT TABLE_SCHEMA, SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH) , SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(DISTINCT ENGINE),COUNT(TABLE_NAME),COUNT(DISTINCT(TABLE_COLLATION)),COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_' GROUP BY TABLE_SCHEMA ORDER BY TABLE_SCHEMA"
  5351. );
  5352. next unless defined $dbinfo[0];
  5353. infoprint "Database: " . $dbinfo[0] . "";
  5354. infoprint " +-- TABLE: "
  5355. . ( !defined( $dbinfo[6] ) or $dbinfo[6] eq 'NULL' ? 0 : $dbinfo[6] )
  5356. . "";
  5357. infoprint " +-- COLL : "
  5358. . ( $dbinfo[7] eq 'NULL' ? 0 : $dbinfo[7] ) . " ("
  5359. . (
  5360. join ", ",
  5361. select_array(
  5362. "SELECT DISTINCT(TABLE_COLLATION) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_';"
  5363. )
  5364. ) . ")";
  5365. infoprint " +-- ROWS : "
  5366. . ( !defined( $dbinfo[1] ) or $dbinfo[1] eq 'NULL' ? 0 : $dbinfo[1] )
  5367. . "";
  5368. infoprint " +-- DATA : "
  5369. . hr_bytes( $dbinfo[2] ) . "("
  5370. . percentage( $dbinfo[2], $dbinfo[4] ) . "%)";
  5371. infoprint " +-- INDEX: "
  5372. . hr_bytes( $dbinfo[3] ) . "("
  5373. . percentage( $dbinfo[3], $dbinfo[4] ) . "%)";
  5374. infoprint " +-- TOTAL: " . hr_bytes( $dbinfo[4] ) . "";
  5375. infoprint " +-- ENGIN : "
  5376. . ( $dbinfo[8] eq 'NULL' ? 0 : $dbinfo[8] ) . " ("
  5377. . (
  5378. join ", ",
  5379. select_array(
  5380. "SELECT DISTINCT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_'"
  5381. )
  5382. ) . ")";
  5383. badprint "Index size is larger than data size for $dbinfo[0] \n"
  5384. if ( $dbinfo[2] ne 'NULL' )
  5385. and ( $dbinfo[3] ne 'NULL' )
  5386. and ( $dbinfo[2] < $dbinfo[3] );
  5387. badprint "There are " . $dbinfo[5] . " storage engines. Be careful. \n"
  5388. if $dbinfo[5] > 1;
  5389. $result{'Databases'}{ $dbinfo[0] }{'Rows'} = $dbinfo[1];
  5390. $result{'Databases'}{ $dbinfo[0] }{'Tables'} = $dbinfo[6];
  5391. $result{'Databases'}{ $dbinfo[0] }{'Collations'} = $dbinfo[7];
  5392. $result{'Databases'}{ $dbinfo[0] }{'Data Size'} = $dbinfo[2];
  5393. $result{'Databases'}{ $dbinfo[0] }{'Data Pct'} =
  5394. percentage( $dbinfo[2], $dbinfo[4] ) . "%";
  5395. $result{'Databases'}{ $dbinfo[0] }{'Index Size'} = $dbinfo[3];
  5396. $result{'Databases'}{ $dbinfo[0] }{'Index Pct'} =
  5397. percentage( $dbinfo[3], $dbinfo[4] ) . "%";
  5398. $result{'Databases'}{ $dbinfo[0] }{'Total Size'} = $dbinfo[4];
  5399. if ( $dbinfo[7] > 1 ) {
  5400. badprint $dbinfo[7]
  5401. . " different collations for database "
  5402. . $dbinfo[0];
  5403. push( @generalrec,
  5404. "Check all table collations are identical for all tables in "
  5405. . $dbinfo[0]
  5406. . " database." );
  5407. }
  5408. else {
  5409. goodprint $dbinfo[7]
  5410. . " collation for "
  5411. . $dbinfo[0]
  5412. . " database.";
  5413. }
  5414. if ( $dbinfo[8] > 1 ) {
  5415. badprint $dbinfo[8]
  5416. . " different engines for database "
  5417. . $dbinfo[0];
  5418. push( @generalrec,
  5419. "Check all table engines are identical for all tables in "
  5420. . $dbinfo[0]
  5421. . " database." );
  5422. }
  5423. else {
  5424. goodprint $dbinfo[8] . " engine for " . $dbinfo[0] . " database.";
  5425. }
  5426. my @distinct_column_charset = select_array(
  5427. "select DISTINCT(CHARACTER_SET_NAME) from information_schema.COLUMNS where CHARACTER_SET_NAME IS NOT NULL AND TABLE_SCHEMA ='$_'"
  5428. );
  5429. infoprint "Charsets for $dbinfo[0] database table column: "
  5430. . join( ', ', @distinct_column_charset );
  5431. if ( scalar(@distinct_column_charset) > 1 ) {
  5432. badprint $dbinfo[0]
  5433. . " table column(s) has several charsets defined for all text like column(s).";
  5434. push( @generalrec,
  5435. "Limit charset for column to one charset if possible for "
  5436. . $dbinfo[0]
  5437. . " database." );
  5438. }
  5439. else {
  5440. goodprint $dbinfo[0]
  5441. . " table column(s) has same charset defined for all text like column(s).";
  5442. }
  5443. my @distinct_column_collation = select_array(
  5444. "select DISTINCT(COLLATION_NAME) from information_schema.COLUMNS where COLLATION_NAME IS NOT NULL AND TABLE_SCHEMA ='$_'"
  5445. );
  5446. infoprint "Collations for $dbinfo[0] database table column: "
  5447. . join( ', ', @distinct_column_collation );
  5448. if ( scalar(@distinct_column_collation) > 1 ) {
  5449. badprint $dbinfo[0]
  5450. . " table column(s) has several collations defined for all text like column(s).";
  5451. push( @generalrec,
  5452. "Limit collations for column to one collation if possible for "
  5453. . $dbinfo[0]
  5454. . " database." );
  5455. }
  5456. else {
  5457. goodprint $dbinfo[0]
  5458. . " table column(s) has same collation defined for all text like column(s).";
  5459. }
  5460. }
  5461. }
  5462. # Recommendations for database columns
  5463. sub mysql_tables {
  5464. return if ( $opt{tbstat} == 0 );
  5465. subheaderprint "Table Column Metrics";
  5466. unless ( mysql_version_ge( 5, 5 ) ) {
  5467. infoprint
  5468. "Skip Database metrics from information schema missing in this version";
  5469. return;
  5470. }
  5471. my @dblist = select_array(
  5472. "SELECT DISTINCT TABLE_SCHEMA FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ( 'mysql', 'performance_schema', 'information_schema', 'sys' );"
  5473. );
  5474. foreach (@dblist) {
  5475. my $dbname = $_;
  5476. next unless defined $_;
  5477. infoprint "Database: " . $_ . "";
  5478. my @dbtable = select_array(
  5479. "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$dbname' AND TABLE_TYPE='BASE TABLE' ORDER BY TABLE_NAME"
  5480. );
  5481. foreach (@dbtable) {
  5482. my $tbname = $_;
  5483. infoprint " +-- TABLE: $tbname";
  5484. my @tbcol = select_array(
  5485. "SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='$dbname' AND TABLE_NAME='$tbname'"
  5486. );
  5487. foreach (@tbcol) {
  5488. my $ctype = select_one(
  5489. "SELECT COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='$dbname' AND TABLE_NAME='$tbname' AND COLUMN_NAME='$_' "
  5490. );
  5491. my $isnull = select_one(
  5492. "SELECT IS_NULLABLE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='$dbname' AND TABLE_NAME='$tbname' AND COLUMN_NAME='$_' "
  5493. );
  5494. infoprint " +-- Column $tbname.$_:";
  5495. my $current_type =
  5496. uc($ctype) . ( $isnull eq 'NO' ? " NOT NULL" : "" );
  5497. my $optimal_type = select_str_g( "Optimal_fieldtype",
  5498. "SELECT $_ FROM $dbname.$tbname PROCEDURE ANALYSE(100000)"
  5499. );
  5500. if ( not defined($optimal_type) or $optimal_type eq '' ) {
  5501. infoprint " Current Fieldtype: $current_type";
  5502. infoprint " Optimal Fieldtype: Not available";
  5503. }
  5504. elsif ( $current_type ne $optimal_type ) {
  5505. infoprint " Current Fieldtype: $current_type";
  5506. infoprint " Optimal Fieldtype: $optimal_type";
  5507. badprint
  5508. "Consider changing type for column $_ in table $dbname.$tbname";
  5509. push( @generalrec,
  5510. "ALTER TABLE $dbname.$tbname MODIFY $_ $optimal_type;"
  5511. );
  5512. }
  5513. else {
  5514. goodprint "$dbname.$tbname ($_) type: $current_type";
  5515. }
  5516. }
  5517. }
  5518. }
  5519. }
  5520. # Recommendations for Indexes metrics
  5521. sub mysql_indexes {
  5522. return if ( $opt{idxstat} == 0 );
  5523. subheaderprint "Indexes Metrics";
  5524. unless ( mysql_version_ge( 5, 5 ) ) {
  5525. infoprint
  5526. "Skip Index metrics from information schema missing in this version";
  5527. return;
  5528. }
  5529. # unless ( mysql_version_ge( 5, 6 ) ) {
  5530. # infoprint
  5531. #"Skip Index metrics from information schema due to erroneous information provided in this version";
  5532. # return;
  5533. # }
  5534. my $selIdxReq = <<'ENDSQL';
  5535. SELECT
  5536. CONCAT(CONCAT(t.TABLE_SCHEMA, '.'),t.TABLE_NAME) AS 'table'
  5537. , CONCAT(CONCAT(CONCAT(s.INDEX_NAME, '('),s.COLUMN_NAME), ')') AS 'index'
  5538. , s.SEQ_IN_INDEX AS 'seq'
  5539. , s2.max_columns AS 'maxcol'
  5540. , s.CARDINALITY AS 'card'
  5541. , t.TABLE_ROWS AS 'est_rows'
  5542. , INDEX_TYPE as type
  5543. , ROUND(((s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) * 100), 2) AS 'sel'
  5544. FROM INFORMATION_SCHEMA.STATISTICS s
  5545. INNER JOIN INFORMATION_SCHEMA.TABLES t
  5546. ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
  5547. AND s.TABLE_NAME = t.TABLE_NAME
  5548. INNER JOIN (
  5549. SELECT
  5550. TABLE_SCHEMA
  5551. , TABLE_NAME
  5552. , INDEX_NAME
  5553. , MAX(SEQ_IN_INDEX) AS max_columns
  5554. FROM INFORMATION_SCHEMA.STATISTICS
  5555. WHERE TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema')
  5556. AND INDEX_TYPE <> 'FULLTEXT'
  5557. GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME
  5558. ) AS s2
  5559. ON s.TABLE_SCHEMA = s2.TABLE_SCHEMA
  5560. AND s.TABLE_NAME = s2.TABLE_NAME
  5561. AND s.INDEX_NAME = s2.INDEX_NAME
  5562. WHERE t.TABLE_SCHEMA NOT IN ('mysql', 'information_schema', 'performance_schema')
  5563. AND t.TABLE_ROWS > 10
  5564. AND s.CARDINALITY IS NOT NULL
  5565. AND (s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) < 8.00
  5566. ORDER BY sel
  5567. LIMIT 10;
  5568. ENDSQL
  5569. my @idxinfo = select_array($selIdxReq);
  5570. infoprint "Worst selectivity indexes:";
  5571. foreach (@idxinfo) {
  5572. debugprint "$_";
  5573. my @info = split /\s/;
  5574. infoprint "Index: " . $info[1] . "";
  5575. infoprint " +-- COLUMN : " . $info[0] . "";
  5576. infoprint " +-- NB SEQS : " . $info[2] . " sequence(s)";
  5577. infoprint " +-- NB COLS : " . $info[3] . " column(s)";
  5578. infoprint " +-- CARDINALITY : " . $info[4] . " distinct values";
  5579. infoprint " +-- NB ROWS : " . $info[5] . " rows";
  5580. infoprint " +-- TYPE : " . $info[6];
  5581. infoprint " +-- SELECTIVITY : " . $info[7] . "%";
  5582. $result{'Indexes'}{ $info[1] }{'Column'} = $info[0];
  5583. $result{'Indexes'}{ $info[1] }{'Sequence number'} = $info[2];
  5584. $result{'Indexes'}{ $info[1] }{'Number of column'} = $info[3];
  5585. $result{'Indexes'}{ $info[1] }{'Cardinality'} = $info[4];
  5586. $result{'Indexes'}{ $info[1] }{'Row number'} = $info[5];
  5587. $result{'Indexes'}{ $info[1] }{'Index Type'} = $info[6];
  5588. $result{'Indexes'}{ $info[1] }{'Selectivity'} = $info[7];
  5589. if ( $info[7] < 25 ) {
  5590. badprint "$info[1] has a low selectivity";
  5591. }
  5592. }
  5593. return
  5594. unless ( defined( $myvar{'performance_schema'} )
  5595. and $myvar{'performance_schema'} eq 'ON' );
  5596. $selIdxReq = <<'ENDSQL';
  5597. SELECT CONCAT(CONCAT(object_schema,'.'),object_name) AS 'table', index_name
  5598. FROM performance_schema.table_io_waits_summary_by_index_usage
  5599. WHERE index_name IS NOT NULL
  5600. AND count_star =0
  5601. AND index_name <> 'PRIMARY'
  5602. AND object_schema != 'mysql'
  5603. ORDER BY count_star, object_schema, object_name;
  5604. ENDSQL
  5605. @idxinfo = select_array($selIdxReq);
  5606. infoprint "Unused indexes:";
  5607. push( @generalrec, "Remove unused indexes." ) if ( scalar(@idxinfo) > 0 );
  5608. foreach (@idxinfo) {
  5609. debugprint "$_";
  5610. my @info = split /\s/;
  5611. badprint "Index: $info[1] on $info[0] is not used.";
  5612. push @{ $result{'Indexes'}{'Unused Indexes'} },
  5613. $info[0] . "." . $info[1];
  5614. }
  5615. }
  5616. # Take the two recommendation arrays and display them at the end of the output
  5617. sub make_recommendations {
  5618. $result{'Recommendations'} = \@generalrec;
  5619. $result{'Adjust variables'} = \@adjvars;
  5620. subheaderprint "Recommendations";
  5621. if ( @generalrec > 0 ) {
  5622. prettyprint "General recommendations:";
  5623. foreach (@generalrec) { prettyprint " " . $_ . ""; }
  5624. }
  5625. if ( @adjvars > 0 ) {
  5626. prettyprint "Variables to adjust:";
  5627. if ( $mycalc{'pct_max_physical_memory'} > 90 ) {
  5628. prettyprint
  5629. " *** MySQL's maximum memory usage is dangerously high ***\n"
  5630. . " *** Add RAM before increasing MySQL buffer variables ***";
  5631. }
  5632. foreach (@adjvars) { prettyprint " " . $_ . ""; }
  5633. }
  5634. if ( @generalrec == 0 && @adjvars == 0 ) {
  5635. prettyprint "No additional performance recommendations are available.";
  5636. }
  5637. }
  5638. sub close_outputfile {
  5639. close($fh) if defined($fh);
  5640. }
  5641. sub headerprint {
  5642. prettyprint
  5643. " >> MySQLTuner $tunerversion - Major Hayden <major\@mhtx.net>\n"
  5644. . " >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n"
  5645. . " >> Run with '--help' for additional options and output filtering";
  5646. }
  5647. sub string2file {
  5648. my $filename = shift;
  5649. my $content = shift;
  5650. open my $fh, q(>), $filename
  5651. or die
  5652. "Unable to open $filename in write mode. Please check permissions for this file or directory";
  5653. print $fh $content if defined($content);
  5654. close $fh;
  5655. debugprint $content if ( $opt{'debug'} );
  5656. }
  5657. sub file2array {
  5658. my $filename = shift;
  5659. debugprint "* reading $filename" if ( $opt{'debug'} );
  5660. my $fh;
  5661. open( $fh, q(<), "$filename" )
  5662. or die "Couldn't open $filename for reading: $!\n";
  5663. my @lines = <$fh>;
  5664. close($fh);
  5665. return @lines;
  5666. }
  5667. sub file2string {
  5668. return join( '', file2array(@_) );
  5669. }
  5670. my $templateModel;
  5671. if ( $opt{'template'} ne 0 ) {
  5672. $templateModel = file2string( $opt{'template'} );
  5673. }
  5674. else {
  5675. # DEFAULT REPORT TEMPLATE
  5676. $templateModel = <<'END_TEMPLATE';
  5677. <!DOCTYPE html>
  5678. <html>
  5679. <head>
  5680. <title>MySQLTuner Report</title>
  5681. <meta charset="UTF-8">
  5682. </head>
  5683. <body>
  5684. <h1>Result output</h1>
  5685. <pre>
  5686. {$data}
  5687. </pre>
  5688. </body>
  5689. </html>
  5690. END_TEMPLATE
  5691. }
  5692. sub dump_result {
  5693. debugprint Dumper( \%result ) if ( $opt{'debug'} );
  5694. debugprint "HTML REPORT: $opt{'reportfile'}";
  5695. if ( $opt{'reportfile'} ne 0 ) {
  5696. eval { require Text::Template };
  5697. if ($@) {
  5698. badprint "Text::Template Module is needed.";
  5699. die "Text::Template Module is needed.";
  5700. }
  5701. my $vars = { 'data' => Dumper( \%result ) };
  5702. my $template;
  5703. {
  5704. no warnings 'once';
  5705. $template = Text::Template->new(
  5706. TYPE => 'STRING',
  5707. PREPEND => q{;},
  5708. SOURCE => $templateModel
  5709. ) or die "Couldn't construct template: $Text::Template::ERROR";
  5710. }
  5711. open my $fh, q(>), $opt{'reportfile'}
  5712. or die
  5713. "Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory";
  5714. $template->fill_in( HASH => $vars, OUTPUT => $fh );
  5715. close $fh;
  5716. }
  5717. if ( $opt{'json'} ne 0 ) {
  5718. eval { require JSON };
  5719. if ($@) {
  5720. print "$bad JSON Module is needed.\n";
  5721. return 1;
  5722. }
  5723. my $json = JSON->new->allow_nonref;
  5724. print $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )->encode( \%result );
  5725. if ( $opt{'outputfile'} ne 0 ) {
  5726. unlink $opt{'outputfile'} if (-e $opt{'outputfile'});
  5727. open my $fh, q(>), $opt{'outputfile'}
  5728. or die
  5729. "Unable to open $opt{'outputfile'} in write mode. please check permissions for this file or directory";
  5730. print $fh $json->utf8(1)->pretty( ( $opt{'prettyjson'} ? 1 : 0 ) )->encode( \%result );
  5731. close $fh;
  5732. }
  5733. }
  5734. }
  5735. sub which {
  5736. my $prog_name = shift;
  5737. my $path_string = shift;
  5738. my @path_array = split /:/, $ENV{'PATH'};
  5739. for my $path (@path_array) {
  5740. return "$path/$prog_name" if ( -x "$path/$prog_name" );
  5741. }
  5742. return 0;
  5743. }
  5744. # ---------------------------------------------------------------------------
  5745. # BEGIN 'MAIN'
  5746. # ---------------------------------------------------------------------------
  5747. headerprint; # Header Print
  5748. validate_tuner_version; # Check last version
  5749. mysql_setup; # Gotta login first
  5750. debugprint "MySQL FINAL Client : $mysqlcmd $mysqllogin";
  5751. debugprint "MySQL Admin FINAL Client : $mysqladmincmd $mysqllogin";
  5752. #exit(0);
  5753. os_setup; # Set up some OS variables
  5754. get_all_vars; # Toss variables/status into hashes
  5755. get_tuning_info; # Get information about the tuning connexion
  5756. validate_mysql_version; # Check current MySQL version
  5757. check_architecture; # Suggest 64-bit upgrade
  5758. system_recommendations; # avoid to many service on the same host
  5759. log_file_recommendations; # check log file content
  5760. check_storage_engines; # Show enabled storage engines
  5761. check_metadata_perf; # Show parameter impacting performance during analysis
  5762. mysql_databases; # Show informations about databases
  5763. mysql_tables; # Show informations about table column
  5764. mysql_indexes; # Show informations about indexes
  5765. security_recommendations; # Display some security recommendations
  5766. cve_recommendations; # Display related CVE
  5767. calculations; # Calculate everything we need
  5768. mysql_stats; # Print the server stats
  5769. mysqsl_pfs; # Print Performance schema info
  5770. mariadb_threadpool; # Print MariaDB ThreadPool stats
  5771. mysql_myisam; # Print MyISAM stats
  5772. mysql_innodb; # Print InnoDB stats
  5773. mariadb_ariadb; # Print MariaDB AriaDB stats
  5774. mariadb_tokudb; # Print MariaDB Tokudb stats
  5775. mariadb_xtradb; # Print MariaDB XtraDB stats
  5776. #mariadb_rockdb; # Print MariaDB RockDB stats
  5777. #mariadb_spider; # Print MariaDB Spider stats
  5778. #mariadb_connect; # Print MariaDB Connect stats
  5779. mariadb_galera; # Print MariaDB Galera Cluster stats
  5780. get_replication_status; # Print replication info
  5781. make_recommendations; # Make recommendations based on stats
  5782. dump_result; # Dump result if debug is on
  5783. close_outputfile; # Close reportfile if needed
  5784. # ---------------------------------------------------------------------------
  5785. # END 'MAIN'
  5786. # ---------------------------------------------------------------------------
  5787. 1;
  5788. __END__
  5789. =pod
  5790. =encoding UTF-8
  5791. =head1 NAME
  5792. MySQLTuner 1.7.13 - MySQL High Performance Tuning Script
  5793. =head1 IMPORTANT USAGE GUIDELINES
  5794. To run the script with the default options, run the script without arguments
  5795. Allow MySQL server to run for at least 24-48 hours before trusting suggestions
  5796. Some routines may require root level privileges (script will provide warnings)
  5797. You must provide the remote server's total memory when connecting to other servers
  5798. =head1 CONNECTION AND AUTHENTICATION
  5799. --host <hostname> Connect to a remote host to perform tests (default: localhost)
  5800. --socket <socket> Use a different socket for a local connection
  5801. --port <port> Port to use for connection (default: 3306)
  5802. --user <username> Username to use for authentication
  5803. --userenv <envvar> Name of env variable which contains username to use for authentication
  5804. --pass <password> Password to use for authentication
  5805. --passenv <envvar> Name of env variable which contains password to use for authentication
  5806. --ssl-ca <path> Path to public key
  5807. --mysqladmin <path> Path to a custom mysqladmin executable
  5808. --mysqlcmd <path> Path to a custom mysql executable
  5809. --defaults-file <path> Path to a custom .my.cnf
  5810. =head1 PERFORMANCE AND REPORTING OPTIONS
  5811. --skipsize Don't enumerate tables and their types/sizes (default: on)
  5812. (Recommended for servers with many tables)
  5813. --skippassword Don't perform checks on user passwords(default: off)
  5814. --checkversion Check for updates to MySQLTuner (default: don't check)
  5815. --updateversion Check for updates to MySQLTuner and update when newer version is available (default: don't check)
  5816. --forcemem <size> Amount of RAM installed in megabytes
  5817. --forceswap <size> Amount of swap memory configured in megabytes
  5818. --passwordfile <path> Path to a password file list(one password by line)
  5819. =head1 OUTPUT OPTIONS
  5820. --silent Don't output anything on screen
  5821. --nogood Remove OK responses
  5822. --nobad Remove negative/suggestion responses
  5823. --noinfo Remove informational responses
  5824. --debug Print debug information
  5825. --dbstat Print database information
  5826. --tbstat Print table information
  5827. --notbstat Don't Print table information
  5828. --idxstat Print index information
  5829. --sysstat Print system information
  5830. --pfstat Print Performance schema
  5831. --bannedports Ports banned separated by comma(,)
  5832. --maxportallowed Number of ports opened allowed on this hosts
  5833. --cvefile <path> CVE File for vulnerability checks
  5834. --nocolor Don't print output in color
  5835. --json Print result as JSON string
  5836. --buffers Print global and per-thread buffer values
  5837. --outputfile <path> Path to a output txt file
  5838. --reportfile <path> Path to a report txt file
  5839. --template <path> Path to a template file
  5840. --verbose Prints out all options (default: no verbose)
  5841. =head1 PERLDOC
  5842. You can find documentation for this module with the perldoc command.
  5843. perldoc mysqltuner
  5844. =head2 INTERNALS
  5845. L<https://github.com/major/MySQLTuner-perl/blob/master/INTERNALS.md>
  5846. Internal documentation
  5847. =head1 AUTHORS
  5848. Major Hayden - major@mhtx.net
  5849. =head1 CONTRIBUTORS
  5850. =over 4
  5851. =item *
  5852. Matthew Montgomery
  5853. =item *
  5854. Paul Kehrer
  5855. =item *
  5856. Dave Burgess
  5857. =item *
  5858. Jonathan Hinds
  5859. =item *
  5860. Mike Jackson
  5861. =item *
  5862. Nils Breunese
  5863. =item *
  5864. Shawn Ashlee
  5865. =item *
  5866. Luuk Vosslamber
  5867. =item *
  5868. Ville Skytta
  5869. =item *
  5870. Trent Hornibrook
  5871. =item *
  5872. Jason Gill
  5873. =item *
  5874. Mark Imbriaco
  5875. =item *
  5876. Greg Eden
  5877. =item *
  5878. Aubin Galinotti
  5879. =item *
  5880. Giovanni Bechis
  5881. =item *
  5882. Bill Bradford
  5883. =item *
  5884. Ryan Novosielski
  5885. =item *
  5886. Michael Scheidell
  5887. =item *
  5888. Blair Christensen
  5889. =item *
  5890. Hans du Plooy
  5891. =item *
  5892. Victor Trac
  5893. =item *
  5894. Everett Barnes
  5895. =item *
  5896. Tom Krouper
  5897. =item *
  5898. Gary Barrueto
  5899. =item *
  5900. Simon Greenaway
  5901. =item *
  5902. Adam Stein
  5903. =item *
  5904. Isart Montane
  5905. =item *
  5906. Baptiste M.
  5907. =item *
  5908. Cole Turner
  5909. =item *
  5910. Major Hayden
  5911. =item *
  5912. Joe Ashcraft
  5913. =item *
  5914. Jean-Marie Renouard
  5915. =item *
  5916. Stephan GroBberndt
  5917. =item *
  5918. Christian Loos
  5919. =back
  5920. =head1 SUPPORT
  5921. Bug reports, feature requests, and downloads at http://mysqltuner.com/
  5922. Bug tracker can be found at https://github.com/major/MySQLTuner-perl/issues
  5923. Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL
  5924. =head1 SOURCE CODE
  5925. L<https://github.com/major/MySQLTuner-perl>
  5926. git clone https://github.com/major/MySQLTuner-perl.git
  5927. =head1 COPYRIGHT AND LICENSE
  5928. Copyright (C) 2006-2017 Major Hayden - major@mhtx.net
  5929. For the latest updates, please visit http://mysqltuner.com/
  5930. Git repository available at http://github.com/major/MySQLTuner-perl
  5931. This program is free software: you can redistribute it and/or modify
  5932. it under the terms of the GNU General Public License as published by
  5933. the Free Software Foundation, either version 3 of the License, or
  5934. (at your option) any later version.
  5935. This program is distributed in the hope that it will be useful,
  5936. but WITHOUT ANY WARRANTY; without even the implied warranty of
  5937. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  5938. See the GNU General Public License for more details.
  5939. You should have received a copy of the GNU General Public License
  5940. along with this program. If not, see <http://www.gnu.org/licenses/>.
  5941. =cut
  5942. # Local variables:
  5943. # indent-tabs-mode: t
  5944. # cperl-indent-level: 8
  5945. # perl-indent-level: 8
  5946. # End: