forked from kjellm/munin-mysql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_
executable file
·1643 lines (1380 loc) · 54.8 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
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
=head1 NAME
mysql_ - Munin plugin to display misc MySQL server status
=head1 APPLICABLE SYSTEMS
Should work on most MySQL platforms, tested by the author on MySQL
versions 5.1.41, 5.0.87, and 4.1.22.
=head1 CONFIGURATION
This script is used to generate data for several graphs. To generate
data for one specific graph, you need to create a symbolic link with a
name like mysql_<GRAPH> to this script.
To get a list of symlinks that can be created, run:
./mysql_ suggest
In addition you might need to specify connection parameters in the
plugin configuration 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
env.mysqlhbdb maindb
=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.
=head1 DEPENDENCIES
=over
=item Cache::Cache
The plugin uses shared memory to cache the statistics gathered from
MySQL. This ensures minimal inpact on the MySQL server.
=item DBD::mysql
=item mk-heartbeat from Maatkit
If you chose to use the heartbeat graph, mk-heartbeat must be installed and
the database containing the heartbeat table must be configured.
=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,2009 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
=head1 VERSION
git-master
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=suggest 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 POSIX qw(floor);
#
# Global hash holding the data collected from mysql.
#
our $data; # Was 'my'. Changed to 'our' to facilitate testing.
my ($has_cache, $has_mkhb);
my $instance;
my $shared_memory_cache;
BEGIN {
eval 'require Cache::SharedMemoryCache';
$has_cache = $@ ? 0 : 1;
qx(which mk-heartbeat 2>&1 >/dev/null);
$has_mkhb = $? ? 0: 1;
}
#---------------------------------------------------------------------
# C O N F I G
#---------------------------------------------------------------------
my %config = (
'dsn' => $ENV{'mysqlconnection'} || 'DBI:mysql:mysql',
'user' => $ENV{'mysqluser'} || 'root',
'password' => $ENV{'mysqlpassword'} || '',
'hbdb' => $ENV{'mysqlhbdb'} || '',
);
#---------------------------------------------------------------------
# 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 = ();
#---------------------------------------------------------------------
$graphs{bin_relay_log} = {
config => {
global_attrs => {
title => 'Binary/Relay Logs',
vlabel => 'Log activity',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'Binlog_cache_disk_use', label => 'Binlog Cache Disk Use',
info => 'The number of transactions that used the temporary binary log cache but that exceeded the value of binlog_cache_size and used a temporary file to store statements from the transaction.'},
{name => 'Binlog_cache_use', label => 'Binlog Cache Use',
info => 'The number of transactions that used the temporary binary log cache.'},
{name => 'ma_binlog_size', label => 'Binary Log Space',
info => 'The total combined size of all existing binary logs.'},
{name => 'relay_log_space', label => 'Relay Log Space',
info => 'The total combined size of all existing relay logs.'},
],
};
#---------------------------------------------------------------------
$graphs{commands} = {
config => {
global_attrs => {
title => 'Command Counters',
vlabel => 'Commands per ${graph_period}',
total => 'Questions',
},
data_source_attrs => {},
},
data_sources => [
{name => 'Com_delete', label => 'Delete',
info => 'The Com_xxx statement counter variables indicate the number of times each xxx statement has been executed.'},
{name => 'Com_insert', label => 'Insert'},
{name => 'Com_insert_select', label => 'Insert select'},
{name => 'Com_load', label => 'Load Data'},
{name => 'Com_replace', label => 'Replace'},
{name => 'Com_replace_select', label => 'Replace select'},
{name => 'Com_select', label => 'Select'},
{name => 'Com_update', label => 'Update'},
{name => 'Com_update_multi', label => 'Update multi'},
],
};
#---------------------------------------------------------------------
$graphs{connections} = {
config => {
global_attrs => {
title => 'Connections',
vlabel => 'Connections per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'max_connections', label => 'Max connections',
type => 'GAUGE',
draw => 'AREA',
colour => 'cdcfc4',
info => 'The number of simultaneous client connections allowed.'},
{name => 'Max_used_connections', label => 'Max used',
type => 'GAUGE',
draw => 'AREA',
colour => 'ffd660',
info => 'The maximum number of connections that have been in use simultaneously since the server started.'},
{name => 'Aborted_clients', label => 'Aborted clients',
info => 'The number of connections that were aborted because the client died without closing the connection properly.'},
{name => 'Aborted_connects', label => 'Aborted connects',
info => 'The number of failed attempts to connect to the MySQL server.'},
{name => 'Threads_connected', label => 'Threads connected',
type => 'GAUGE',
info => 'The number of currently open connections.'},
{name => 'Connections', label => 'New connections',
info => 'The number of connection attempts (successful or not) to the MySQL server.'},
],
};
#---------------------------------------------------------------------
$graphs{files_tables} = {
config => {
global_attrs => {
title => 'Files and tables',
vlabel => 'Tables',
},
data_source_attrs => {
type => 'GAUGE',
draw => 'LINE1',
},
},
data_sources => [
{name => 'table_open_cache', label => 'Table cache',
draw => 'AREA',
colour => 'cdcfc4',
info => 'The number of open tables for all threads.'},
{name => 'Open_files', label => 'Open files',
info => 'The number of files that are open.'},
{name => 'Open_tables', label => 'Open tables',
info => 'The number of tables that are open.'},
{name => 'Opened_tables', label => 'Opened tables',
type => 'DERIVE',
info => 'The number of tables that have been opened.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_bpool} = {
config => {
global_attrs => {
title => 'InnoDB Buffer Pool',
vlabel => 'Pages',
args => '--base 1024',
},
data_source_attrs => {
draw => 'LINE2',
type => 'GAUGE',
},
},
data_sources => [
{name => 'ib_bpool_size', label => 'Buffer pool size',
draw => 'AREA',
colour => 'ffd660',
info => 'The total number of buffer pool pages'},
{name => 'ib_bpool_dbpages', label => 'Database pages',
draw => 'AREA',
colour => 'cdcfc4',
info => 'The number of used buffer pool pages'},
{name => 'ib_bpool_free', label => 'Free pages',
info => 'The number of unused buffer pool pages'},
{name => 'ib_bpool_modpages', label => 'Modified pages',
info => 'The number of "dirty" database pages'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_bpool_act} = {
config => {
global_attrs => {
title => 'InnoDB Buffer Pool Activity',
vlabel => 'Activity per ${graph_period}',
total => 'Total',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'ib_bpool_read', label => 'Pages read',
info => 'Pages read into the buffer pool from disk.'},
{name => 'ib_bpool_created', label => 'Pages created',
info => 'Pages created in the buffer pool without reading the corresponding disk page.'},
{name => 'ib_bpool_written', label => 'Pages written',
info => 'Pages written to disk from the buffer pool.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_checkpoint_age} = {
config => {
global_attrs => {
title => 'InnoDB Checkpoint Age',
vlabel => 'Bytes',
args => '--base 1024 -l 0',
},
data_source_attrs => {
draw => 'AREA',
type => 'GAUGE',
},
},
data_sources => [
{name => 'innodb_log_size', label => 'InnoDB log size',
colour => 'cdcfc4',
info => 'The size in bytes of InnoDB log space.',
value => sub {
$_[0]->{innodb_log_file_size} * $_[0]->{innodb_log_files_in_group}
}},
{name => 'ib_log_chkpt_age', label => 'Uncheckpointed bytes',
colour => 'ffd660',
info => 'The age in bytes of InnoDB checkpoint.',
value => sub {
$_[0]->{ib_log_flush} - $_[0]->{ib_log_checkpoint}
}},
],
};
#---------------------------------------------------------------------
$graphs{innodb_history_length} = {
config => {
global_attrs => {
title => 'InnoDB History List',
vlabel => 'Transactions',
},
data_source_attrs => {
draw => 'LINE1',
type => 'GAUGE',
},
},
data_sources => [
{name => 'ib_tnx_hist', label => 'History list length',
info => 'Number of unpurged transactions in undo space.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_insert_buf} = {
config => {
global_attrs => {
title => 'InnoDB Insert Buffer',
vlabel => 'Activity per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'ib_ibuf_inserts', label => 'Inserts',
info => 'These values shows statistics about how many buffer operations InnoDB has done. The ratio of merges to inserts gives a good idea of how efficient the buffer is.'},
{name => 'ib_ibuf_merged_rec', label => 'Merged Records'},
{name => 'ib_ibuf_merges', label => 'Merges'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_insert_buf_size} = {
config => {
global_attrs => {
title => 'InnoDB Insert Buffer Size',
vlabel => 'Pages',
args => '-l 0',
},
data_source_attrs => {
draw => 'LINE1',
type => 'GAUGE',
},
},
data_sources => [
{name => 'ib_ibuf_seg_size', label => 'Segment size',
draw => 'AREA',
colour => 'cdcfc4',
info => 'Allocated size of insert buffer segment.'},
{name => 'ib_ibuf_size', label => 'Unmerged pages',
colour => '0022ff',
info => 'Number of pages containing unmerged records.'},
{name => 'ib_ibuf_free_len', label => 'Free pages',
info => 'Number of pages which are free.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_io} = {
config => {
global_attrs => {
title => 'InnoDB IO',
vlabel => 'IO operations per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'ib_io_read', label => 'File reads',
info => 'The number of calls to the OS read function.'},
{name => 'ib_io_write', label => 'File writes',
info => 'The number of calls to the OS write function.'},
{name => 'ib_io_log', label => 'Log writes',
info => 'The number of calls to the OS write function that is caused by the log subsystem.'},
{name => 'ib_io_fsync', label => 'File syncs',
info => 'The number of calls to the OS fsync function.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_io_pend} = {
config => {
global_attrs => {
title => 'InnoDB IO Pending',
vlabel => 'Pending operations',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'ib_iop_log', label => 'AIO Log'},
{name => 'ib_iop_sync', label => 'AIO Sync'},
{name => 'ib_iop_flush_bpool', label => 'Buf Pool Flush'},
{name => 'ib_iop_flush_log', label => 'Log Flushes'},
{name => 'ib_iop_ibuf_aio', label => 'Insert Buf AIO Read'},
{name => 'ib_iop_aioread', label => 'Normal AIO Reads'},
{name => 'ib_iop_aiowrite', label => 'Normal AIO Writes'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_log} = {
config => {
global_attrs => {
title => 'InnoDB Log',
vlabel => 'Log activity per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'innodb_log_buffer_size', label => 'Buffer Size',
type => 'GAUGE',
draw => 'AREA',
colour => 'fafd9e',
info => 'The size in bytes of the buffer that InnoDB uses to write to the log files on disk.'},
{name => 'ib_log_flush', label => 'KB Flushed',
info => 'Number of bytes flushed to the transaction log file.'},
{name => 'ib_log_written', label => 'KB Written',
info => 'Number of bytes written to the transaction log buffer.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_rows} = {
config => {
global_attrs => {
title => 'InnoDB Row Operations',
vlabel => 'Operations per ${graph_period}',
total => 'Total',
},
data_source_attrs => {},
},
data_sources => [
{name => 'Innodb_rows_deleted', label => 'Deletes',
info => 'The number of rows deleted from InnoDB tables.'},
{name => 'Innodb_rows_inserted', label => 'Inserts',
info => 'The number of rows inserted into InnoDB tables.'},
{name => 'Innodb_rows_read', label => 'Reads',
info => 'The number of rows read from InnoDB tables.'},
{name => 'Innodb_rows_updated', label => 'Updates',
info => 'The number of rows updated in InnoDB tables.'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_semaphores} = {
config => {
global_attrs => {
title => 'InnoDB Semaphores',
vlabel => 'Semaphores per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'ib_spin_rounds', label => 'Spin Rounds'},
{name => 'ib_spin_waits', label => 'Spin Waits'},
{name => 'ib_os_waits', label => 'OS Waits'},
],
};
#---------------------------------------------------------------------
$graphs{innodb_tnx} = {
config => {
global_attrs => {
title => 'InnoDB Transactions',
vlabel => 'Transactions per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'ib_tnx', label => 'Transactions created',
info => 'Number of transactions created.'},
],
};
#---------------------------------------------------------------------
$graphs{myisam_indexes} = {
config => {
global_attrs => {
title => 'MyISAM Indexes',
vlabel => 'Requests per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Key_read_requests', label => 'Key read requests',
info => 'The number of requests to read a key block from the cache.'},
{name => 'Key_reads', label => 'Key reads',
info => 'The number of physical reads of a key block from disk.'},
{name => 'Key_write_requests', label => 'Key write requests',
info => 'The number of requests to write a key block to the cache.'},
{name => 'Key_writes', label => 'Key writes',
info => 'The number of physical writes of a key block to disk.'},
],
};
#---------------------------------------------------------------------
$graphs{network_traffic} = {
config => {
global_attrs => {
title => 'Network Traffic',
args => '--base 1024',
vlabel => 'Bytes received (-) / sent (+) per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Bytes_received', label => 'Bytes transfered',
graph => 'no',
info => 'The number of bytes received from all clients.'},
{name => 'Bytes_sent', label => 'Bytes transfered',
negative => 'Bytes_received',
info => 'The number of bytes sent to all clients.'},
],
};
#---------------------------------------------------------------------
$graphs{processlist} = {
config => {
global_attrs => {
title => 'Processlist states',
vlabel => 'State count per ${graph_period}',
},
data_source_attrs => {
},
},
data_sources => [
{name => 'State_closing_tables', label => 'Closing tables',
info => 'The thread is flushing the changed table data to disk and closing the used tables.'},
{name => 'State_copying_to_tmp_table', label => 'Copying to tmp table',
info => 'The thread is processing an ALTER TABLE statement. This state occurs after the table with the new structure has been created but before rows are copied into it.'},
{name => 'State_end', label => 'End',
info => 'This occurs at the end but before the cleanup of ALTER TABLE, CREATE VIEW, DELETE, INSERT, SELECT, or UPDATE statements.'},
{name => 'State_freeing_items', label => 'Freeing items',
info => 'The thread has executed a command. This state is usually followed by cleaning up.'},
{name => 'State_init', label => 'Init',
info => 'This occurs before the initialization of ALTER TABLE, DELETE, INSERT, SELECT, or UPDATE statements.'},
{name => 'State_locked', label => 'Locked',
info => 'The query is locked by another query.'},
{name => 'State_login', label => 'Login',
info => 'The initial state for a connection thread until the client has been authenticated successfully.'},
{name => 'State_preparing', label => 'Preparing',
info => 'This state occurs during query optimization.'},
{name => 'State_reading_from_net', label => 'Reading from net',
info => 'The server is reading a packet from the network.'},
{name => 'State_sending_data', label => 'Sending data',
info => 'The thread is processing rows for a SELECT statement and also is sending data to the client.'},
{name => 'State_sorting_result', label => 'Sorting result',
info => 'For a SELECT statement, this is similar to Creating sort index, but for nontemporary tables.'},
{name => 'State_statistics', label => 'Statistics',
info => 'The server is calculating statistics to develop a query execution plan. If a thread is in this state for a long time, the server is probably disk-bound performing other work.'},
{name => 'State_updating', label => 'Updating',
info => 'The thread is searching for rows to update and is updating them.'},
{name => 'State_writing_to_net', label => 'Writing to net',
info => 'The server is writing a packet to the network.'},
{name => 'State_none', label => 'None',
info => ''},
{name => 'State_other', label => 'Other',
info => ''},
],
};
#---------------------------------------------------------------------
$graphs{qcache} = {
config => {
global_attrs => {
title => 'Query Cache',
vlabel => 'Commands per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'Qcache_queries_in_cache', label => 'Queries in cache',
info => 'The number of queries registered in the query cache.'},
{name => 'Qcache_hits', label => 'Cache hits',
info => 'The number of query cache hits.'},
{name => 'Qcache_inserts', label => 'Inserts',
info => 'The number of queries added to the query cache.'},
{name => 'Qcache_not_cached', label => 'Not cached',
info => 'The number of noncached queries (not cacheable, or not cached due to the query_cache_type setting).'},
{name => 'Qcache_lowmem_prunes', label => 'Low-memory prunes',
info => 'The number of queries that were deleted from the query cache because of low memory.'},
],
};
#---------------------------------------------------------------------
$graphs{qcache_mem} = {
config => {
global_attrs => {
title => 'Query Cache Memory',
vlabel => 'Bytes',
args => '--base 1024 --lower-limit 0',
},
data_source_attrs => {
draw => 'AREA',
type => 'GAUGE',
},
},
data_sources => [
{name => 'query_cache_size', label => 'Cache size',
info => 'The amount of memory allocated for caching query results.'},
{name => 'Qcache_free_memory', label => 'Free mem',
info => 'The amount of free memory for the query cache.'},
],
};
#---------------------------------------------------------------------
$graphs{replication} = {
config => {
global_attrs => {
title => 'Replication',
vlabel => 'Activity',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'slave_running', label => 'Slave Running',
type => 'GAUGE',
draw => 'AREA'},
{name => 'slave_stopped', label => 'Slave Stopped',
type => 'GAUGE',
draw => 'AREA'},
{name => 'Slave_retried_transactions', label => 'Retried Transactions',
info => 'The total number of times since startup that the replication slave SQL thread has retried transactions.'},
{name => 'Slave_open_temp_tables', label => 'Open Temp Tables',
info => 'The number of temporary tables that the slave SQL thread currently has open.'},
{name => 'seconds_behind_master', label => 'Secs Behind Master',
type => 'GAUGE',
info => 'http://dev.mysql.com/doc/refman/5.1/en/show-slave-status.html'},
],
};
#---------------------------------------------------------------------
$graphs{heartbeat} = {
config => {
global_attrs => {
title => 'Maatkit Heartbeat',
vlabel => 'Seconds behind master',
},
data_source_attrs => {
draw => 'LINE1',
},
},
data_sources => [
{name => 'mk_heartbeat', label => 'Slave Delay',
type => 'GAUGE',
draw => 'AREA'},
],
};
#---------------------------------------------------------------------
$graphs{select_types} = {
config => {
global_attrs => {
title => 'Select types',
vlabel => 'Commands per ${graph_period}',
total => 'Total',
},
data_source_attrs => {},
},
data_sources => [
{name => 'Select_full_join', label => 'Full join',
info => 'The number of joins that perform table scans because they do not use indexes.'},
{name => 'Select_full_range_join', label => 'Full range',
info => 'The number of joins that used a range search on a reference table.'},
{name => 'Select_range', label => 'Range',
info => 'The number of joins that used ranges on the first table.'},
{name => 'Select_range_check', label => 'Range check',
info => 'The number of joins without keys that check for key usage after each row.'},
{name => 'Select_scan', label => 'Scan',
info => 'The number of joins that did a full scan of the first table.'},
],
};
#---------------------------------------------------------------------
$graphs{slow} = {
config => {
global_attrs => {
title => 'Slow Queries',
vlabel => 'Slow queries per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Slow_queries', label => 'Slow queries',
info => 'The number of queries that have taken more than long_query_time seconds.'},
],
};
#---------------------------------------------------------------------
$graphs{sorts} = {
config => {
global_attrs => {
title => 'Sorts',
vlabel => 'Sorts / ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Sort_rows', label => 'Rows sorted',
info => 'The number of sorted rows.'},
{name => 'Sort_range', label => 'Range',
info => 'The number of sorts that were done using ranges.'},
{name => 'Sort_merge_passes', label => 'Merge passes',
info => 'The number of merge passes that the sort algorithm has had to do.'},
{name => 'Sort_scan', label => 'Scan',
info => 'The number of sorts that were done by scanning the table.'},
],
};
#---------------------------------------------------------------------
$graphs{table_locks} = {
config => {
global_attrs => {
title => 'Table locks',
vlabel => 'locks per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Table_locks_immediate', label => 'Table locks immed',
info => 'The number of times that a request for a table lock could be granted immediately.'},
{name => 'Table_locks_waited', label => 'Table locks waited',
info => 'The number of times that a request for a table lock could not be granted immediately and a wait was needed.'},
],
};
#---------------------------------------------------------------------
$graphs{threads} = {
config => {
global_attrs => {
title => 'Threads',
vlabel => 'Threads created per ${graph_period}',
},
data_source_attrs => {
},
},
data_sources => [
{name => 'thread_cache_size', label => 'Thread cache size',
draw => 'AREA',
info => 'How many threads the server should cache for reuse'},
{name => 'Threads_created', label => 'Threads created',
draw => 'LINE1',
type => 'GAUGE',
info => 'The number of threads created to handle connections'},
],
};
#---------------------------------------------------------------------
$graphs{tmp_tables} = {
config => {
global_attrs => {
title => 'Temporary objects',
vlabel => 'Objects per ${graph_period}',
},
data_source_attrs => {
draw => 'LINE2',
},
},
data_sources => [
{name => 'Created_tmp_disk_tables', label => 'Temp disk tables',
info => 'The number of internal on-disk temporary tables created by the server while executing statements.'},
{name => 'Created_tmp_tables', label => 'Temp tables',
info => 'The number of internal temporary tables created by the server while executing statements.'},
{name => 'Created_tmp_files', label => 'Temp files',
info => 'How many temporary files mysqld has created.'},
],
};
#---------------------------------------------------------------------
$graphs{uptime} = {
config => {
global_attrs => {
title => 'Uptime',
vlabel => 'Uptime in days',
},
data_source_attrs => {
draw => 'AREA',
type => 'GAUGE',
},
},
data_sources => [
{name => 'Uptime_days', label => 'Uptime',
info => 'Server uptime in days.',
value => sub {
floor($_[0]->{Uptime} / 86400); # seconds in a day
},
},
],
};
#---------------------------------------------------------------------
# M A I N
#---------------------------------------------------------------------
sub main {
my $graph = basename($0);
# remove prefix and instance number from command name
$graph =~ s/^mysql_([0-9]+_)?//;
my $command = $ARGV[0] || 'show';
my %command_map = (
'autoconf' => \&autoconf,
'config' => \&config,
'show' => \&show,
'suggest' => \&suggest,
);
die "Unknown command: $command"
unless exists $command_map{$command};
die "Missing dependency Cache::Cache"
unless $has_cache || $command eq 'autoconf';
build_instance();
if ($has_cache) {
build_shared_memory_cache();
}
return $command_map{$command}->($graph);
}
#---------------------------------------------------------------------
# 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 {
unless ($has_cache) {
print "no (Missing dependency Cache::Cache)\n";
return 0;
}
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;
}
# http://munin.projects.linpro.no/wiki/ConcisePlugins#suggest