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
|
# File 'lib/mysqlcollector/collector.rb', line 18
def innodb_parse(text)
parsing = [ 'Mutex spin waits (?<spin_waits>\d+), rounds (?<spin_rounds>\d+), OS waits (?<os_waits>\d+)',
'RW-shared spins (?<spin_waits>\d+), rounds (\d+), OS waits (?<os_waits>\d+)',
'RW-excl spins (?<spin_waits>\d+), rounds (\d+), OS waits (?<os_waits>\d+)',
'(?<file_reads>\d+) OS file reads, (?<file_writes>\d+) OS file writes, (?<file_fsyncs>\d+) OS fsyncs',
'Pending normal aio reads: (?<pending_normal_aio_reads>\d+)(?: \[(?:\d+, )*\d+\] )?, aio writes: (?<pending_normal_aio_writes>\d+)(?: \[(?:\d+, )*\d+\] )?',
'ibuf aio reads: (?<pending_ibuf_aio_reads>\d+), log i\/o\'s: (?<pending_aio_log_ios>\d+), sync i\/o\'s: (?<pending_aio_sync_ios>\d+)',
'Pending flushes \(fsync\) log: (?<pending_log_flushes>\d+); buffer pool: (?<pending_buf_pool_flushes>\d+)',
'Ibuf: size (?<ibuf_used_cells>\d+), free list len (?<ibuf_free_cells>\d+), seg size (?<ibuf_cell_count>\d+), (?<ibuf_merges>\d+) merges',
'merged operations:\n insert (?<ibuf_inserts>\d+), delete mark \d+, delete \d+\ndiscarded operations:\n insert (?<ibuf_merged>\d+)',
'Hash table size (?<hash_index_cells_total>\d+), node heap has (?<hash_index_cells_used>\d+) buffer',
'(?<log_writes>\d+) log i\/o\'s done',
'(?<pending_log_writes>\d+) pending log writes, (?<pending_chkp_writes>\d+) pending chkp writes',
'Log sequence number\W+(?<log_bytes_written>\d+)',
'Log flushed up to\W+(?<log_bytes_flushed>\d+)',
'Last checkpoint at\W+(?<last_checkpoint>\d+)',
'Total memory allocated (?<total_mem_alloc>\d+); in additional pool allocated (?<additional_pool_alloc>\d+)',
'Buffer pool size\W+(?<pool_size>\d+)',
'Free buffers\W+(?<free_pages>\d+)',
'Database pages\W+(?<database_pages>\d+)',
'Modified db pages\W+(?<modified_pages>\d+)',
'Pages read (?<pages_read>\d+), created (?<pages_created>\d+), written (?<pages_written>\d+)',
'Number of rows inserted (?<rows_inserted>\d+), updated (?<rows_updated>\d+), deleted (?<rows_deleted>\d+), read (?<rows_read>\d+)',
'(?<queries_inside>\d+) queries inside InnoDB, (?<queries_queued>\d+) queries in queue',
'Trx id counter (?<innodb_transactions>\d+)',
'History list length (?<history_list>\d+)' ]
variables = { 'additional_pool_alloc' => 0,
'database_pages' => 0,
'file_fsyncs' => 0,
'file_reads' => 0,
'file_writes' => 0,
'free_pages' => 0,
'hash_index_cells_total' => 0,
'hash_index_cells_used' => 0,
'history_list' => 0,
'ibuf_cell_count' => 0,
'ibuf_free_cells' => 0,
'ibuf_inserts' => 0,
'ibuf_merged' => 0,
'ibuf_merges' => 0,
'ibuf_used_cells' => 0,
'innodb_transactions' => 0,
'last_checkpoint' => 0,
'log_bytes_flushed' => 0,
'log_bytes_written' => 0,
'log_writes' => 0,
'modified_pages' => 0,
'os_waits' => 0,
'pages_created' => 0,
'pages_read' => 0,
'pages_written' => 0,
'pending_aio_log_ios' => 0,
'pending_aio_sync_ios' => 0,
'pending_buf_pool_flushes' => 0,
'pending_chkp_writes' => 0,
'pending_ibuf_aio_reads' => 0,
'pending_log_flushes' => 0,
'pending_log_writes' => 0,
'pending_normal_aio_reads' => 0,
'pending_normal_aio_writes' => 0,
'pool_size' => 0,
'queries_inside' => 0,
'queries_queued' => 0,
'rows_deleted' => 0,
'rows_inserted' => 0,
'rows_read' => 0,
'rows_updated' => 0,
'spin_rounds' => 0,
'spin_waits' => 0,
'total_mem_alloc' => 0 }
parsing.each do |regular_expression|
matchs = text.match(/#{regular_expression}/i)
unless matchs.nil?
matchs.names.each do |variable_name|
variables[variable_name] += matchs[variable_name].to_i
end
end
end
metrics_innodb = variables.map do |variable_name, variable_value|
[variable_name, variable_value]
end
active_transactions = text.scan(/---TRANSACTION \d+, ACTIVE \d+ sec/).count
current_transactions = text.scan(/---TRANSACTION \d+, not started/).count
innodb_lock_structs = text.scan(/---TRANSACTION \d+, ACTIVE \d+ sec\n(?<innodb_lock_structs>\d+) lock struct\(s\), heap size/)
locked_transactions = text.scan(/---TRANSACTION \d+, ACTIVE \d+ sec\nLOCK WAIT (?<locked_transactions>\d+) lock struct\(s\), heap size/)
innodb_lock_structs = innodb_lock_structs.inject{|x,y| x.first.to_i + y.first.to_i }
locked_transactions = locked_transactions.inject{|x,y| x.first.to_i + y.first.to_i }
innodb_lock_structs = innodb_lock_structs.first.to_i if innodb_lock_structs.kind_of?(Array)
locked_transactions = locked_transactions.first.to_i if locked_transactions.kind_of?(Array)
innodb_lock_structs = 0 if innodb_lock_structs.nil?
locked_transactions = 0 if locked_transactions.nil?
current_transactions = current_transactions + active_transactions
variables = { 'innodb_lock_structs' => innodb_lock_structs,
'current_transactions' => current_transactions,
'active_transactions' => active_transactions,
'locked_transactions' => locked_transactions }
metrics_transactions = variables.map do |variable_name, variable_value|
[variable_name, variable_value]
end
metrics_innodb + metrics_transactions
end
|