当前位置:   article > 正文

mysqltuner.pl

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

使用:
10.25.80.7:gzz3306:Master> perl mysqltuner.pl --socket=/var/mysql/data3306/mysql.sock

MySQLTuner 1.7.15 - Major Hayden <major@mhtx.net>
Bug reports, feature requests, and downloads at http://mysqltuner.com/
Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: [OK] Currently running supported MySQL version 5.6.38-log
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /var/mysql/data3306/SZD-L0087668.err(100M)
[OK] Log file /var/mysql/data3306/SZD-L0087668.err exists
[OK] Log file /var/mysql/data3306/SZD-L0087668.err is readable.
[OK] Log file /var/mysql/data3306/SZD-L0087668.err is not empty
[!!] Log file /var/mysql/data3306/SZD-L0087668.err is bigger than 32 Mb
[!!] /var/mysql/data3306/SZD-L0087668.err contains 346 warning(s).
[!!] /var/mysql/data3306/SZD-L0087668.err contains 267390 error(s).
[--] 65 start(s) detected in /var/mysql/data3306/SZD-L0087668.err
[--] 1) 2019-03-05 16:23:10 1800 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 2) 2019-02-28 16:09:20 31621 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 3) 2019-02-22 15:09:35 12877 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 4) 2019-02-19 16:04:33 11845 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 5) 2019-02-19 15:57:24 10660 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 6) 2019-02-19 15:54:20 9517 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 7) 2019-02-19 15:35:40 7215 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 8) 2019-02-19 15:26:25 5860 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 9) 2019-02-19 15:22:30 4990 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 10) 2019-02-11 15:12:23 27338 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
[--] 58 shutdown(s) detected in /var/mysql/data3306/SZD-L0087668.err
[--] 1) 2019-03-05 16:22:59 31621 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 2) 2019-02-28 16:09:10 12877 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 3) 2019-02-22 15:09:25 11845 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 4) 2019-02-19 16:02:17 10660 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 5) 2019-02-19 15:57:07 9517 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 6) 2019-02-19 15:47:38 7215 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 7) 2019-02-19 15:35:28 5860 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 8) 2019-02-19 15:25:53 4990 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 9) 2019-02-19 15:20:21 4336 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
[--] 10) 2019-02-19 15:16:19 3482 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 5.2G (Tables: 69)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] User 'hive@%' has user name as password.
[!!] User 'hive@localhost' has user name as password.
[!!] User 'hive@spark1' has user name as password.
[!!] User 'alex@%' does not specify hostname restrictions.
[!!] User 'hive@%' does not specify hostname restrictions.
[!!] User 'root@%' does not specify hostname restrictions.
[!!] User 'test@%' does not specify hostname restrictions.
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 2d 19h 17m 22s (411 q [0.002 qps], 26 conn, TX: 342K, RX: 13K)
[--] Reads / Writes: 100% / 0%
[--] Binary logging is enabled (GTID MODE: ON)
[--] Physical Memory : 7.7G
[--] Max MySQL memory : 508.1M
[--] Other process memory: 0B
[--] Total buffers: 177.0M global + 1.8M per thread (151 max threads)
[--] P_S Max memory usage: 66M
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 245.6M (3.12% of installed RAM)
[OK] Maximum possible memory usage: 508.1M (6.46% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (1/411)
[OK] Highest usage of available connections: 0% (1/151)
[!!] Aborted connections: 7.69% (2/26)
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 70 selects)
[OK] Query cache prunes per day: 0
[OK] No Sort requiring temporary tables
[OK] No joins without indexes
[OK] Temporary tables created on disk: 18% (111 on disk / 603 total)
[OK] Thread cache hit rate: 96% (1 created / 26 connections)
[OK] Table cache hit rate: 46% (64 open / 137 opened)
[OK] Open file limit used: 0% (49/655K)
[OK] Table locks acquired immediately: 100% (133 immediate / 133 locks)
[OK] Binlog cache memory access: 0% (0 Memory / 0 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 66.9M
[--] Sys schema isn't installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (3M used / 16M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/112.0K
[!!] Read Key buffer hit rate: 75.5% (49 cached / 12 reads)
[!!] Write Key buffer hit rate: 66.7% (12 cached / 8 writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 128.0M/5.2G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal 25%
[!!] InnoDB buffer pool <= 1G and Innodb_buffer_pool_instances(!=1).
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[OK] InnoDB Read buffer efficiency: 99.74% (904890 hits/ 907282 total)
[!!] InnoDB Write Log efficiency: 27.27% (3 hits/ 11 total)
[OK] InnoDB log waits: 0.00% (0 waits / 8 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
/var/mysql/data3306/SZD-L0087668.err is > 32Mb, you should analyze why or implement a rotation log strategy such as logrotate!
Control warning line(s) into /var/mysql/data3306/SZD-L0087668.err file
Control error line(s) into /var/mysql/data3306/SZD-L0087668.err file
Set up a Secure Password for user@host ( SET PASSWORD FOR 'user'@'SpecificDNSorIp' = PASSWORD('secure_password'); )
Restrict Host for user@% to user@SpecificDNSorIp
Reduce or eliminate unclosed connections and network issues
Consider installing Sys schema from https://github.com/mysql/mysql-sys for MySQL
Consider installing Sys schema from https://github.com/good-dba/mariadb-sys for MariaDB
Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
query_cache_size (=0)
query_cache_type (=0)
query_cache_limit (> 1M, or use smaller result sets)
innodb_buffer_pool_size (>= 5.2G) if possible.
innodb_log_file_size should be (=16M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
innodb_buffer_pool_instances (=1)

转载于:https://blog.51cto.com/13476134/2360084

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/119953
推荐阅读
相关标签
  

闽ICP备14008679号