forked from kjellm/munin-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql
executable file
·959 lines (772 loc) · 29.1 KB
/
mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
#!/usr/bin/perl
=head1 NAME
mysql - Munin plugin to display misc MySQL server status
=head1 APPLICABLE SYSTEMS
Should work on most MySQL platforms.
=head1 CONFIGURATION
You need to configure connection parameters to override the
defaults. These are the defaults:
[mysql]
env.mysqlconnection DBI:mysql:mysql
env.mysqluser root
Non-default example:
[mysql]
env.mysqlconnection DBI:mysql:mysql;host=127.0.0.1;port=3306
env.mysqluser root
env.mysqlpassword geheim
Warning and critical values can be set via the environment in the usual way.
For example:
[mysql_replication]
env.seconds_behind_master_warning 300
env.seconds_behind_master_critical 600
=head2 Multiple instances
This plugin can monitor many instances of MySQL. See
L<http://github.com/kjellm/munin-mysql/issues#issue/22> for a hint on
how this can be configured.
=head2 Slave lag (mk-heartbeat, pt-heartbeat)
You can use Percona's pt-hearbeat L<http://www.percona.com/software/percona-toolkit>, formerly known as
maatkit's mk-heartbeat L<http://www.maatkit.org> to better measure slave lag. Add this to the configuration:
env.maatkit_heartbeat 1
or:
env.pt_heartbeat 1
If you want to use a table other than maatkit.heartbeat, name it like this:
env.maatkit_heartbeat_table schema.heartbeattable
or:
env.pt_heartbeat_table schema.heartbeattable
=head1 DEPENDENCIES
=over
=item DBD::mysql
=item Module::Pluggable
=back
=head1 INTERPRETATION
=head2 InnoDB
The statistics from innodb are mainly collected from the command
SHOW ENGINE INNODB STATUS
A nice walk through is found at
L<http://www.mysqlperformanceblog.com/2006/07/17/show-innodb-status-walk-through/>
=head2 The graphs
FIX point to relevant sections in the MySQL manual and other www
resources for each graph
=over
=item mysql_replication
slave_running and slave_stopped creates an alterning color under the
seconds_behind_master line. It will have the color of slave_running
when the SQL thread runs and the color of slave_stopped otherwise.
=back
=head1 LICENSE
Copyright (C) 2008-2011 Kjell-Magne Øierud
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
=head1 VERSION
git-master
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
use warnings;
use strict;
use utf8;
use DBI;
use File::Basename;
use Math::BigInt; # Used to append "=> lib 'GMP'" here, but GMP caused
# segfault on some occasions. Removed as I don't
# think the tiny performance boost is worth the
# debugging effort.
use Module::Pluggable search_path => ['Munin::MySQL::Graph'], require => 1, inner => 0;
use Munin::Plugin;
# Check that multigraph is supported
need_multigraph();
#
# Global hash holding the data collected from mysql.
#
our $data; # Was 'my'. Changed to 'our' to facilitate testing.
#
# FIX
#
my $instance;
#---------------------------------------------------------------------
# C O N F I G
#---------------------------------------------------------------------
my %config = (
'dsn' => $ENV{'mysqlconnection'} || 'DBI:mysql:mysql',
'user' => $ENV{'mysqluser'} || 'root',
'password' => $ENV{'mysqlpassword'} || '',
'maatkit_heartbeat' => $ENV{'maatkit_heartbeat'} || ( $ENV{'pt_heartbeat'} ? $ENV{'pt_heartbeat'} : 0 ),
'maatkit_heartbeat_table' => $ENV{'maatkit_heartbeat_table'} || ( $ENV{'pt_heartbeat_table'} ? $ENV{'pt_heartbeat_table'} : 'maatkit.heartbeat'),
);
#---------------------------------------------------------------------
# G R A P H D E F I N I T I O N S
#---------------------------------------------------------------------
# These are defaults to save typing in the graph definitions
my %defaults = (
global_attrs => {
args => "--base 1000",
},
data_source_attrs => {
min => '0',
type => 'DERIVE',
draw => 'AREASTACK',
},
);
# %graphs contains the graph definitions, it is indexed on the graph
# name. The information stored for each graph is used for both showing
# data source values and for printing the graph configuration. Each
# graph follows the followingformat:
#
# $graph{NAME} => {
# config => {
# # The global attributes for this graph
# global_attrs => {}
# # Attributes common to all data sources in this graph
# data_source_attrs => {}
# },
# data_sources => [
# # NAME - The name of the data source (e.g. variable names
# # from SHOW STATUS)
# # DATA_SOURCE_ATTRS - key-value pairs with data source
# # attributes
# {name => 'NAME', (DATA_SOURCE_ATTRS)},
# {...},
# ],
my %graphs = ();
#---------------------------------------------------------------------
# M A I N
#---------------------------------------------------------------------
sub main {
my $command = $ARGV[0] || 'show';
for my $graph_package (__PACKAGE__->plugins) {
%graphs = (%graphs, %{$graph_package->graphs});
}
my %command_map = (
'autoconf' => \&autoconf,
'config' => \&config,
'show' => \&show,
);
die "Unknown command: $command"
unless exists $command_map{$command};
build_instance();
if ($command eq 'autoconf') {
return $command_map{$command}->();
}
else {
if ($command eq 'show') {
collect_data();
}
for my $graph (sort keys %graphs) {
print "multigraph mysql_$graph$instance\n";
$command_map{$command}->($graph);
}
}
return 0;
}
#---------------------------------------------------------------------
# C O M M A N D H A N D L E R S
#---------------------------------------------------------------------
# Each command handler should return an appropriate exit code
# http://munin.projects.linpro.no/wiki/ConcisePlugins#autoconf
sub autoconf {
eval {
db_connect();
};
if ($@) {
my $err = $@;
$err =~ s{\s at \s \S+ \s line .*}{}xms;
print "no ($err)\n";
return 0;
}
print "yes\n";
return 0;
}
sub config {
my $graph_name = shift;
my $graph = $graphs{$graph_name};
my %conf = (%{$defaults{global_attrs}}, %{$graph->{config}{global_attrs}});
$conf{args} .= ' --no-gridfit --slope-mode';
while (my ($k, $v) = each %conf) {
print "graph_$k $v\n";
}
print "graph_category mysql$instance\n";
for my $ds (@{$graph->{data_sources}}) {
my %ds_spec = (
%{$defaults{data_source_attrs}},
%{$graph->{config}{data_source_attrs}},
%$ds,
);
while (my ($k, $v) = each %ds_spec) {
# 'name' is only used internally in this script, not
# understood by munin.
next if ($k eq 'name');
# 'value' should not be used in config context.
next if ($k eq 'value');
next if ($v eq '');
printf("%s.%s %s\n", clean_fieldname($ds->{name}), $k, $v);
}
print_thresholds(clean_fieldname($ds->{name}));
}
}
sub show {
my $graph_name = shift;
my $graph = $graphs{$graph_name};
die "Can't show data for '$graph_name' because InnoDB is disabled."
if $graph_name =~ /innodb_/ && $data->{_innodb_disabled};
for my $ds (@{$graph->{data_sources}}) {
my $value = exists $ds->{value}
? $ds->{value}($data)
: $data->{$ds->{name}};
printf "%s.value %s\n", clean_fieldname($ds->{name}), defined($value) ? $value : 'U';
}
}
#---------------------------------------------------------------------
# U T I L I T Y S U B S
#---------------------------------------------------------------------
sub build_instance {
$instance = basename($0);
if($instance =~ /^mysql_([0-9]+)/) {
$instance = "_$1";
}
else {
$instance = "";
}
}
sub db_connect {
my $dsn = "$config{dsn};mysql_connect_timeout=5";
return DBI->connect($dsn, $config{user}, $config{password}, {
RaiseError => 1,
PrintError => 0,
FetchHashKeyName => 'NAME_lc',
});
}
sub collect_data {
$data = {};
my $dbh = db_connect();
# Set up defaults in case the server is not a slave
$data->{relay_log_space} = 0;
$data->{slave_running} = 0;
$data->{slave_stopped} = 0;
$data->{seconds_behind_master} = 0;
# Set up defaults in case binlog is not enabled
$data->{ma_binlog_size} = 0;
update_variables($dbh);
update_innodb($dbh);
update_master($dbh);
update_slave($dbh);
update_process_list($dbh);
}
sub update_variables {
my ($dbh) = @_;
my @queries = (
'SHOW /*!50002 GLOBAL*/ STATUS',
'SHOW /*!40003 GLOBAL*/ VARIABLES',
);
my %variable_name_map = (
table_cache => 'table_open_cache', # table_open_cache was
# previously known as
# table_cache in MySQL
# 5.1.2 and earlier.
);
for my $query (@queries) {
$data->{$query} = {};
my $sth = $dbh->prepare($query);
$sth->execute();
while (my $row = $sth->fetch) {
my $var = $variable_name_map{$row->[0]} || $row->[0];
$data->{$var} = $row->[1];
}
$sth->finish();
}
}
sub update_innodb {
my ($dbh) = @_;
my $sth = $dbh->prepare('SHOW /*!50000 ENGINE*/ INNODB STATUS');
eval {
$sth->execute();
};
my $exit_message = $@;
if ($exit_message) {
if ($exit_message =~ /Unknown (storage|table) engine 'INNODB'|Cannot call SHOW INNODB STATUS because skip-innodb is defined/) {
$data->{_innodb_disabled} = 1;
return;
}
die $exit_message;
}
my $row = $sth->fetchrow_hashref();
my $status = $row->{'status'};
$sth->finish();
parse_innodb_status($status);
}
sub update_master {
my ($dbh) = @_;
return if $data->{log_bin} eq 'OFF';
my $sth = $dbh->prepare('SHOW MASTER LOGS');
$sth->execute();
while (my $row = $sth->fetch) {
$data->{ma_binlog_size} += $row->[1];
}
$sth->finish();
}
sub update_slave {
my ($dbh) = @_;
my $sth = $dbh->prepare('SHOW SLAVE STATUS');
$sth->execute();
my $row = $sth->fetchrow_hashref();
return unless $row;
while (my ($k, $v) = each %$row) {
$data->{$k} = $v;
}
$sth->finish();
if ($config{maatkit_heartbeat}) {
update_slave_maatkit_heartbeat($dbh);
}
# undef when slave is stopped, or when MySQL fails to calculate
# the lag (which happens depressingly often). (mk-heartbeat fixes
# this problem.)
$data->{seconds_behind_master} ||= 0;
# Scale slave_running and slave_stopped relative to the slave lag.
$data->{slave_running} = ($data->{slave_sql_running} eq 'Yes')
? $data->{seconds_behind_master} : 0;
$data->{slave_stopped} = ($data->{slave_sql_running} eq 'Yes')
? 0 : $data->{seconds_behind_master};
}
# Overwrites seconds_behind_master collected from SHOW SLAVE STATUS
sub update_slave_maatkit_heartbeat {
my ($dbh) = @_;
# The TIME_TO_SEC(TIMEDIFF in the query is necessary as mysql
# otherwise calculates the wrong difference (simply substracting
# won't work)
my $heartbeat_query = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), ts)) AS seconds_behind_master
FROM $config{maatkit_heartbeat_table}
LIMIT 1";
my $sth = $dbh->prepare($heartbeat_query);
$sth->execute();
my $row = $sth->fetchrow_hashref();
return unless $row;
while (my ($k, $v) = each %$row) {
$data->{$k} = $v;
}
$sth->finish();
}
sub update_process_list {
my ($dbh) = @_;
$data->{State_closing_tables} = 0;
$data->{State_copying_to_tmp_table} = 0;
$data->{State_end} = 0;
$data->{State_freeing_items} = 0;
$data->{State_init} = 0;
$data->{State_locked} = 0;
$data->{State_login} = 0;
$data->{State_preparing} = 0;
$data->{State_reading_from_net} = 0;
$data->{State_sending_data} = 0;
$data->{State_sorting_result} = 0;
$data->{State_statistics} = 0;
$data->{State_system_lock} = 0;
$data->{State_table_lock} = 0;
$data->{State_updating} = 0;
$data->{State_writing_to_net} = 0;
$data->{State_none} = 0;
$data->{State_other} = 0;
my $sth = $dbh->prepare('SHOW PROCESSLIST');
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
my $state = $row->{state};
if (! defined $state) {
$state = 'NULL';
}
elsif ($state eq '') {
$state = 'none';
}
$state = lc $state;
$state =~ tr/ /_/;
my $state_key = exists($data->{"State_$state"}) ? "State_$state" : 'State_other';
$data->{$state_key}++;
}
$sth->finish();
}
#
# In 'SHOW ENGINE INNODB STATUS' 64 bit integers are not formated as
# plain integers. They are either:
#
# - split in two and needs to be shifted together,
# - or hexadecimal
#
sub innodb_bigint {
my ($x, $y) = @_;
return defined $y
? Math::BigInt->new($x)->blsft(32) + $y
: Math::BigInt->new("0x$x");
}
sub innodb_bigint_nohex {
my ($x, $y) = @_;
return defined $y
? Math::BigInt->new($x)->blsft(32) + $y
: Math::BigInt->new($x);
}
#---------------------------------------------------------------------
# P A R S E 'SHOW ENGINE INNODB STATUS' O U T P U T
#---------------------------------------------------------------------
# A nice walk through
# http://www.mysqlperformanceblog.com/2006/07/17/show-innodb-status-walk-through/
# The parsing is split in one subrutine per section. Each subroutine
# should parse a block with the following structure
#
# block body ...
# more lines ....
# ----------
sub parse_innodb_status {
local $_ = shift;
# Add a dummy section to the end in case the innodb status output
# has been truncated (Happens for status > 64K characters)
$_ .= "\n----------\nDUMMY\n----------\n";
my %section_map = (
'BUFFER POOL AND MEMORY' => \&parse_buffer_pool_and_memory,
'INDIVIDUAL BUFFER POOL INFO' => \&parse_individual_buffer_pool,
'FILE I/O' => \&parse_file_io,
'INSERT BUFFER AND ADAPTIVE HASH INDEX'
=> \&parse_insert_buffer_and_adaptive_hash_index,
'LATEST DETECTED DEADLOCK' => \&skip,
'LATEST FOREIGN KEY ERROR' => \&skip,
'LOG' => \&parse_log,
'ROW OPERATIONS' => \&parse_row_operations,
'SEMAPHORES' => \&parse_semaphores,
'TRANSACTIONS' => \&parse_transactions,
'BACKGROUND THREAD' => \&parse_background_thread,
);
skip_heading();
for (;;) {
m/\G(.*)\n/gc;
my $sec = $1;
last if $sec eq 'END OF INNODB MONITOR OUTPUT';
if ($sec eq 'DUMMY') {
handle_incomplete_innodb_status();
last;
}
die "Unknown section: $1" unless exists $section_map{$sec};
die "Parse error. Expected a section separator" unless m/\G-+\n/gc;
$section_map{$sec}->();
}
}
# This regular expression handles the different formating of 64-bit
# integers in different versions of the innodb engine. Either two
# decimal 32-bit integers seperated by a space, or a single
# hexadecimal 64-bit integer.
my $innodb_bigint_rx = qr{([[a-fA-F\d]+)(?: (\d+))?};
# Need the negative lookahead in match dashes because some times the
# TRANSACTION section contains a line of only dashes (see
# http://munin-monitoring.org/ticket/956):
#
# ------- TRX HAS BEEN WAITING 808 SEC FOR THIS LOCK TO BE GRANTED:
# [...]
# ------------------
# ---TRANSACTION 1 2450838625, ACTIVE 831 sec, OS thread id 27 fetching rows, thread declared inside InnoDB 104
sub match_new_section {
return m/\G
-+\n # ---------------------------
(?= [A-Z\/ ]+\n # SECTION NAME
[=-]+\n)/gcx; # --------------------------- ('=' on end of output)
}
sub skip_line { return m/\G.*\n/gc; }
sub skip_heading {
# Heading is 6 lines
for my $foo (1...6) {
skip_line or die('Parse error');
}
}
sub parse_section {
my ($parser) = @_;
#warn substr($_, pos(), 10);
for (;;) {
return if match_new_section;
next if $parser->();
skip_line();
}
}
sub skip { parse_section(sub {}); }
sub parse_semaphores {
parse_section(
sub {
m/\GMutex spin waits (\d+), rounds (\d+), OS waits (\d+)\n/gc && do {
$data->{ib_spin_waits} = $1;
$data->{ib_spin_rounds} = $2;
$data->{ib_os_waits} = $3;
return 1;
};
m/\GRW-shared spins (\d+), rounds (\d+), OS waits (\d+)\n/gc && do {
$data->{ib_rw_shared_waits} = $1;
$data->{ib_rw_shared_rounds} = $2;
$data->{ib_rw_shared_os_waits} = $3;
return 1;
};
m/\GRW-excl spins (\d+), rounds (\d+), OS waits (\d+)\n/gc && do {
$data->{ib_rw_excl_waits} = $1;
$data->{ib_rw_excl_rounds} = $2;
$data->{ib_rw_excl_os_waits} = $3;
return 1;
};
}
);
}
sub parse_transactions {
parse_section(
sub {
m/\GTrx id counter $innodb_bigint_rx\n/gc && do {
$data->{ib_tnx} = innodb_bigint($1, $2);
return 1;
};
m/\GPurge done for trx's n:o < $innodb_bigint_rx undo n:o < $innodb_bigint_rx\n/gc && do {
if (defined $3) {
# old format
$data->{ib_tnx_prg} = innodb_bigint($1, $2);
# FIX add to data? innodb_bigint($3, $4);
}
else {
# new format
$data->{ib_tnx_prg} = innodb_bigint($1);
# FIX add to data? innodb_bigint($2);
}
return 1;
};
m/\GHistory list length (\d+)\n/gc && do {
$data->{ib_tnx_hist} = $1;
return 1;
};
}
);
}
sub parse_file_io {
parse_section(
sub {
m/\GPending normal aio reads: (\d+)(?: \[(?:\d+, )*\d+\] )?, aio writes: (\d+)(?: \[(?:\d+, )*\d+\] )?,\n\s*ibuf aio reads: (\d+), log i\/o's: (\d+), sync i\/o's: (\d+)\n/gc && do {
$data->{ib_iop_aioread} = $1;
$data->{ib_iop_aiowrite} = $2;
$data->{ib_iop_ibuf_aio} = $3;
$data->{ib_iop_log} = $4;
$data->{ib_iop_sync} = $5;
return 1;
};
m/\GPending flushes \(fsync\) log: (\d+); buffer pool: (\d+)\n/gc && do {
$data->{ib_iop_flush_log} = $1;
$data->{ib_iop_flush_bpool} = $2;
return 1;
};
m/\G(\d+) OS file reads, (\d+) OS file writes, (\d+) OS fsyncs\n/gc && do {
$data->{ib_io_read} = $1;
$data->{ib_io_write} = $2;
$data->{ib_io_fsync} = $3;
return 1;
};
}
);
}
sub parse_row_operations {
parse_section(
sub {
m/\G(\d+) queries inside InnoDB, (\d+) queries in queue\n/gc && do {
$data->{ib_innodb_queries} = $1;
$data->{ib_innodb_query_queue_len} = $2;
return 1;
};
m/\G(\d+) read views open inside InnoDB\n/gc && do {
$data->{ib_innodb_read_views} = $1;
return 1;
};
m/\G(\d+) transactions active inside InnoDB\n/gc && do {
$data->{ib_innodb_transactions_active} = $1;
return 1;
};
m/\G(\d+) RW transactions active inside InnoDB\n/gc && do {
$data->{ib_innodb_rw_transactions_active} = $1;
return 1;
};
m/\G(\d+) RO transactions active inside InnoDB\n/gc && do {
$data->{ib_innodb_ro_transactions_active} = $1;
return 1;
};
m/\G(\d+) out of (\d+) descriptors used\n/gc && do {
$data->{ib_innodb_descriptors} = $1;
$data->{ib_innodb_descriptors_max} = $2;
return 1;
};
}
);
}
sub parse_insert_buffer_and_adaptive_hash_index {
parse_section(
sub {
# MySQL < 5.5
m/\G(\d+) inserts, (\d+) merged recs, (\d+) merges\n/gc && do {
$data->{ib_ibuf_inserts} = $1;
$data->{ib_ibuf_merged_rec} = $2;
$data->{ib_ibuf_merges} = $3;
return 1;
};
# MySQL >= 5.5
m/\Gmerged operations:\n insert (\d+), delete mark (\d+), delete (\d+)\ndiscarded operations:\n insert (\d+), delete mark (\d+), delete (\d+)\n/gc && do {
$data->{ib_ibuf_inserts} = $1;
$data->{ib_ibuf_delete_mark} = $2;
$data->{ib_ibuf_delete} = $3;
$data->{ib_ibuf_discard_inserts} = $4;
$data->{ib_ibuf_discard_delete_mark} = $5;
$data->{ib_ibuf_discard_delete} = $6;
$data->{ib_ibuf_merged_rec} = $data->{ib_ibuf_inserts} + $data->{ib_ibuf_discard_inserts};
return 1;
};
m/\GIbuf: size (\d+), free list len (\d+), seg size (\d+),(?: (\d+) merges)?\n/gc && do {
$data->{ib_ibuf_size} = $1;
$data->{ib_ibuf_free_len} = $2;
$data->{ib_ibuf_seg_size} = $3;
$data->{ib_ibuf_merges} = $4 if defined $4; # MySQL >= 5.5
return 1;
};
}
);
}
sub parse_log {
parse_section(
sub {
m/\GLog sequence number $innodb_bigint_rx\n/gc && do {
$data->{ib_log_written} = innodb_bigint_nohex($1, $2);
return 1;
};
m/\GLog flushed up to\s+$innodb_bigint_rx\n/gc && do {
$data->{ib_log_flush} = innodb_bigint_nohex($1, $2);
return 1;
};
m/\GLast checkpoint at\s+$innodb_bigint_rx\n/gc && do {
$data->{ib_log_checkpoint} = innodb_bigint_nohex($1, $2);
return 1;
};
m/\G(\d+) log i\/o's done.*\n/gc && do {
$data->{ib_io_log} = $1;
return 1;
};
m/\GCheckpoint age\s+(\d+)/gc && do {
$data->{ib_log_checkpt_age} = $1;
return 1;
};
}
);
}
sub parse_background_thread {
parse_section(
sub {
m/\Gsrv_master_thread loops: \d+ 1_second, \d+ sleeps, \d+ 10_second, (\d+) background, (\d+) flush\n/gc && do {
$data->{ib_srv_main_flush_loops} = $1;
$data->{ib_srv_main_background_loops} = $2;
return 1;
};
m/\Gsrv_master_thread log flush and writes: (\d+)\n/gc && do {
$data->{ib_srv_main_flushs_writes} = $1;
return 1;
};
}
);
}
sub parse_buffer_pool_and_memory {
parse_section(
sub {
m/\GBuffer pool size\s+(\d+)\n/gc && do {
$data->{ib_bpool_size} = $1;
return 1;
};
m/\GFree buffers\s+(\d+)\n/gc && do {
$data->{ib_bpool_free} = $1;
return 1;
};
m/\GDatabase pages\s+(\d+)\n/gc && do {
$data->{ib_bpool_dbpages} = $1;
return 1;
};
m/\GModified db pages\s+(\d+)\n/gc && do {
$data->{ib_bpool_modpages} = $1;
return 1;
};
m/\GOld database pages\s+(\d+)\n/gc && do {
$data->{ib_bpool_oldpages} = $1;
return 1;
};
m/\GPages made young (\d+), not young (\d+)\n/gc && do {
$data->{ib_bpool_made_young} = $1;
$data->{ib_bpool_made_not_young} = $2;
return 1;
};
m/\GPages read (\d+), created (\d+), written (\d+)\n/gc && do {
$data->{ib_bpool_read} = $1;
$data->{ib_bpool_created} = $2;
$data->{ib_bpool_written} = $3;
return 1;
};
m/\GInternal hash tables \(constant factor \+ variable factor\)\n\s*Adaptive hash index\s*(\d+)\s*\((\d+) \+ (\d+)\) *\n\s+Page hash +(\d+) +\(buffer pool \d+ only\) *\n\s+Dictionary cache\s*(\d+)\s+\((\d+) \+ (\d+)\) *\n\s+File system\s+(\d+)\s+\((\d+) \+ (\d+)\) *\n\s+Lock system\s+(\d+)\s+\((\d+) \+ (\d+)\) *\n\s+Recovery system\s*(\d+)\s+\((\d+) \+ (\d+)\) *\n/gc
&& do {
$data->{ib_bpool_internal_adaptive_hash_size_total} = $1;
$data->{ib_bpool_internal_adaptive_hash_size_const} = $2;
$data->{ib_bpool_internal_adaptive_hash_size_var} = $3;
$data->{ib_bpool_internal_page_hash_size_total} = $4;
$data->{ib_bpool_internal_dictionary_cache_size_total} = $5;
$data->{ib_bpool_internal_dictionary_cache_size_const} = $6;
$data->{ib_bpool_internal_dictionary_cache_size_var} = $7;
$data->{ib_bpool_internal_file_system_size_total} = $8;
$data->{ib_bpool_internal_file_system_size_const} = $9;
$data->{ib_bpool_internal_file_system_size_var} = $10;
$data->{ib_bpool_internal_lock_system_size_total} = $11;
$data->{ib_bpool_internal_lock_system_size_const} = $12;
$data->{ib_bpool_internal_lock_system_size_var} = $13;
$data->{ib_bpool_internal_recovery_system_size_total} = $14;
$data->{ib_bpool_internal_recovery_system_size_const} = $15;
$data->{ib_bpool_internal_recovery_system_size_var} = $16;
return 1;
};
}
);
}
sub parse_individual_buffer_pool {
parse_section(
sub {
m/\G---BUFFER POOL (\d+)\n/gc && do {
my $pool = $1;
$data->{ib_bpool_individual_pool_count} = $pool + 1;
m/\GBuffer pool size\s+(\d+)\n/gc && do {
$data->{"ib_bpool_individual_pool_${pool}_size"} = $1;
};
m/\GBuffer pool size, bytes\s+(\d+)\n/gc && do {
$data->{"ib_bpool_individual_pool_${pool}_size_bytes"} = $1;
};
m/\GFree buffers\s+(\d+)\nDatabase pages\s+(\d+)\nOld database pages\s+(\d+)\nModified db pages\s+(\d+)\nPending reads\s+(\d+)\nPending writes: LRU\s+(\d+), flush list\s+(\d+), single page\s+(\d+)\n/gc && do {
$data->{"ib_bpool_individual_pool_${pool}_free"} = $1;
$data->{"ib_bpool_individual_pool_${pool}_dbpages"} = $2;
$data->{"ib_bpool_individual_pool_${pool}_oldpages"} = $3;
$data->{"ib_bpool_individual_pool_${pool}_modpages"} = $4;
$data->{"ib_bpool_individual_pool_${pool}_pending_reads"} = $5;
$data->{"ib_bpool_individual_pool_${pool}_pending_writes_lru"} = $6;
$data->{"ib_bpool_individual_pool_${pool}_pending_writes_flush"} = $7;
$data->{"ib_bpool_individual_pool_${pool}_pending_writes_single"} = $8;
};
skip_line();
m/\GPages read (\d+), created (\d+), written (\d+)\n/gc && do {
$data->{"ib_bpool_individual_pool_${pool}_read"} = $1;
$data->{"ib_bpool_individual_pool_${pool}_created"} = $2;
$data->{"ib_bpool_individual_pool_${pool}_written"} = $3;
};
return 1;
};
}
);
}
sub handle_incomplete_innodb_status {
warn "Output from SHOW ENGINE INNODB STATUS was truncated. "
. "This happens if the output of SEIS exceeds 64KB. "
. "Several of the InnoDB graphs might be affected by this."
. "You can use innotop to fix this issue by pressing 'D' "
. "to enter deadlock mode and then 'w' to wipe the deadlocks.";
# FIX Is it possible to find some of the missing values from SHOW
# STATUS?
}
exit main() unless caller;
1;