]> arthur.barton.de Git - netdata.git/blob - charts.d/mysql.chart.sh
fixed mysql chart priorities
[netdata.git] / charts.d / mysql.chart.sh
1 #!/bin/bash
2
3 # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
4 #
5 # https://dev.mysql.com/doc/refman/5.1/en/show-status.html
6 # SHOW STATUS provides server status information (see Section 5.1.6, “Server Status Variables”).
7 # This statement does not require any privilege.
8 # It requires only the ability to connect to the server.
9
10 mysql_update_every=5
11 mysql_priority=60000
12
13 declare -A mysql_cmds=() mysql_opts=() mysql_ids=()
14
15 mysql_exec() {
16         local ret
17
18         "${@}" -s -e "show global status;"
19         ret=$?
20
21         [ $ret -ne 0 ] && echo "plugin_command_failure $ret"
22         return $ret
23 }
24
25 mysql_get() {
26         unset \
27                 mysql_Bytes_received \
28                 mysql_Bytes_sent \
29                 mysql_Queries \
30                 mysql_Questions \
31                 mysql_Slow_queries \
32                 mysql_Handler_commit \
33                 mysql_Handler_delete \
34                 mysql_Handler_prepare \
35                 mysql_Handler_read_first \
36                 mysql_Handler_read_key \
37                 mysql_Handler_read_next \
38                 mysql_Handler_read_prev \
39                 mysql_Handler_read_rnd \
40                 mysql_Handler_read_rnd_next \
41                 mysql_Handler_rollback \
42                 mysql_Handler_savepoint \
43                 mysql_Handler_savepoint_rollback \
44                 mysql_Handler_update \
45                 mysql_Handler_write \
46                 mysql_Table_locks_immediate \
47                 mysql_Table_locks_waited \
48                 mysql_Select_full_join \
49                 mysql_Select_full_range_join \
50                 mysql_Select_range \
51                 mysql_Select_range_check \
52                 mysql_Select_scan \
53                 mysql_Sort_merge_passes \
54                 mysql_Sort_range \
55                 mysql_Sort_scan \
56                 mysql_Created_tmp_disk_tables \
57                 mysql_Created_tmp_files \
58                 mysql_Created_tmp_tables \
59                 mysql_Connection_errors_accept \
60                 mysql_Connection_errors_internal \
61                 mysql_Connection_errors_max_connections \
62                 mysql_Connection_errors_peer_addr \
63                 mysql_Connection_errors_select \
64                 mysql_Connection_errors_tcpwrap \
65                 mysql_Connections \
66                 mysql_Aborted_connects \
67                 mysql_Binlog_cache_disk_use \
68                 mysql_Binlog_cache_use \
69                 mysql_Binlog_stmt_cache_disk_use \
70                 mysql_Binlog_stmt_cache_use \
71                 mysql_Threads_connected \
72                 mysql_Threads_created \
73                 mysql_Threads_cached \
74                 mysql_Threads_running \
75                 mysql_Innodb_data_read \
76                 mysql_Innodb_data_written \
77                 mysql_Innodb_data_reads \
78                 mysql_Innodb_data_writes \
79                 mysql_Innodb_data_fsyncs \
80                 mysql_Innodb_data_pending_reads \
81                 mysql_Innodb_data_pending_writes \
82                 mysql_Innodb_data_pending_fsyncs \
83                 mysql_Innodb_log_waits \
84                 mysql_Innodb_log_write_requests \
85                 mysql_Innodb_log_writes \
86                 mysql_Innodb_os_log_fsyncs \
87                 mysql_Innodb_os_log_pending_fsyncs \
88                 mysql_Innodb_os_log_pending_writes \
89                 mysql_Innodb_os_log_written \
90                 mysql_Innodb_row_lock_current_waits \
91                 mysql_Innodb_rows_inserted \
92                 mysql_Innodb_rows_read \
93                 mysql_Innodb_rows_updated \
94                 mysql_Innodb_rows_deleted \
95                 mysql_Innodb_buffer_pool_pages_data \
96                 mysql_Innodb_buffer_pool_pages_dirty \
97                 mysql_Innodb_buffer_pool_pages_flushed \
98                 mysql_Innodb_buffer_pool_pages_free \
99                 mysql_Innodb_buffer_pool_pages_misc \
100                 mysql_Innodb_buffer_pool_pages_total \
101                 mysql_Innodb_buffer_pool_bytes_data \
102                 mysql_Innodb_buffer_pool_bytes_dirty \
103                 mysql_Innodb_buffer_pool_read_ahead_rnd \
104                 mysql_Innodb_buffer_pool_read_ahead \
105                 mysql_Innodb_buffer_pool_read_ahead_evicted \
106                 mysql_Innodb_buffer_pool_read_requests \
107                 mysql_Innodb_buffer_pool_reads \
108                 mysql_Innodb_buffer_pool_wait_free \
109                 mysql_Innodb_buffer_pool_write_requests \
110                 mysql_Qcache_free_blocks \
111                 mysql_Qcache_free_memory \
112                 mysql_Qcache_hits \
113                 mysql_Qcache_inserts \
114                 mysql_Qcache_lowmem_prunes \
115                 mysql_Qcache_not_cached \
116                 mysql_Qcache_queries_in_cache \
117                 mysql_Qcache_total_blocks \
118                 mysql_Key_blocks_not_flushed \
119                 mysql_Key_blocks_unused \
120                 mysql_Key_blocks_used \
121                 mysql_Key_read_requests \
122                 mysql_Key_reads \
123                 mysql_Key_write_requests \
124                 mysql_Key_writes \
125                 mysql_Open_files \
126                 mysql_Opened_files
127
128
129         mysql_plugin_command_failure=0
130
131         eval "$(mysql_exec "${@}" |\
132                 sed \
133                         -e "s/[[:space:]]\+/ /g" \
134                         -e "s/\./_/g" \
135                         -e "s/^\([a-zA-Z0-9_]\+\)[[:space:]]\+\([0-9]\+\)$/mysql_\1=\2/g" |\
136                 egrep "^mysql_[a-zA-Z0-9_]+=[[:digit:]]+$")"
137
138         [ $mysql_plugin_command_failure -eq 1 ] && return 1
139         [ -z "$mysql_Connections" ] && return 1
140
141         mysql_Thread_cache_misses=0
142         [ $(( mysql_Connections + 1 - 1 )) -gt 0 ] && mysql_Thread_cache_misses=$(( mysql_Threads_created * 10000 / mysql_Connections ))
143
144         return 0
145 }
146
147 mysql_check() {
148         # this should return:
149         #  - 0 to enable the chart
150         #  - 1 to disable the chart
151
152         local x m mysql_cmd tryroot=0 unconfigured=0
153
154         if [ "${1}" = "tryroot" ]
155                 then
156                 tryroot=1
157                 shift
158         fi
159
160         [ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql)"
161
162         if [ ${#mysql_opts[@]} -eq 0 ]
163                 then
164                 unconfigured=1
165
166                 mysql_cmds[local]="$mysql_cmd"
167
168                 if [ $tryroot -eq 1 ]
169                         then
170                         # the user has not configured us for mysql access
171                         # if the root user is passwordless in mysql, we can
172                         # attempt to connect to mysql as root
173                         mysql_opts[local]="-u root"
174                 else
175                         mysql_opts[local]=
176                 fi
177         fi
178
179         # check once if the url works
180         for m in "${!mysql_opts[@]}"
181         do
182                 [ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd"
183                 if [ -z "${mysql_cmds[$m]}" ]
184                         then
185                         echo >&2 "$PROGRAM_NAME: mysql: cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf"
186                 fi
187
188                 mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]}
189                 if [ ! $? -eq 0 ]
190                 then
191                         echo >&2 "$PROGRAM_NAME: mysql: cannot get global status for '$m'. Please set mysql_opts[$m]='options' to whatever needed to get connected to the mysql server, in $confd/mysql.conf"
192                         unset mysql_cmds[$m]
193                         unset mysql_opts[$m]
194                         unset mysql_ids[$m]
195                         continue
196                 fi
197
198                 mysql_ids[$m]="$( fixid "$m" )"
199         done
200
201         if [ ${#mysql_opts[@]} -eq 0 ]
202                 then
203                 if [ ${unconfigured} -eq 1 && ${tryroot} -eq 0 ]
204                         then
205                         mysql_check tryroot "${@}"
206                         return $?
207                 else
208                         echo >&2 "$PROGRAM_NAME: mysql: no mysql servers found. Please set mysql_opts[name]='options' to whatever needed to get connected to the mysql server, in $confd/mysql.conf"
209                         return 1
210                 fi
211         fi
212
213         return 0
214 }
215
216 mysql_create() {
217         local x
218
219         # create the charts
220         for x in "${mysql_ids[@]}"
221         do
222                 cat <<EOF
223 CHART mysql_$x.net '' "mysql Bandwidth" "kilobits/s" bandwidth mysql.net area $((mysql_priority + 1)) $mysql_update_every
224 DIMENSION Bytes_received in incremental 8 1024
225 DIMENSION Bytes_sent out incremental -8 1024
226
227 CHART mysql_$x.queries '' "mysql Queries" "queries/s" queries mysql.queries line $((mysql_priority + 2)) $mysql_update_every
228 DIMENSION Queries queries incremental 1 1
229 DIMENSION Questions questions incremental 1 1
230 DIMENSION Slow_queries slow_queries incremental -1 1
231
232 CHART mysql_$x.handlers '' "mysql Handlers" "handlers/s" handlers mysql.handlers line $((mysql_priority + 3)) $mysql_update_every
233 DIMENSION Handler_commit commit incremental 1 1
234 DIMENSION Handler_delete delete incremental 1 1
235 DIMENSION Handler_prepare prepare incremental 1 1
236 DIMENSION Handler_read_first read_first incremental 1 1
237 DIMENSION Handler_read_key read_key incremental 1 1
238 DIMENSION Handler_read_next read_next incremental 1 1
239 DIMENSION Handler_read_prev read_prev incremental 1 1
240 DIMENSION Handler_read_rnd read_rnd incremental 1 1
241 DIMENSION Handler_read_rnd_next read_rnd_next incremental 1 1
242 DIMENSION Handler_rollback rollback incremental 1 1
243 DIMENSION Handler_savepoint savepoint incremental 1 1
244 DIMENSION Handler_savepoint_rollback savepoint_rollback incremental 1 1
245 DIMENSION Handler_update update incremental 1 1
246 DIMENSION Handler_write write incremental 1 1
247
248 CHART mysql_$x.table_locks '' "mysql Tables Locks" "locks/s" locks mysql.table_locks line $((mysql_priority + 4)) $mysql_update_every
249 DIMENSION Table_locks_immediate immediate incremental 1 1
250 DIMENSION Table_locks_waited waited incremental -1 1
251
252 CHART mysql_$x.join_issues '' "mysql Select Join Issues" "joins/s" issues mysql.join_issues line $((mysql_priority + 5)) $mysql_update_every
253 DIMENSION Select_full_join full_join incremental 1 1
254 DIMENSION Select_full_range_join full_range_join incremental 1 1
255 DIMENSION Select_range range incremental 1 1
256 DIMENSION Select_range_check range_check incremental 1 1
257 DIMENSION Select_scan scan incremental 1 1
258
259 CHART mysql_$x.sort_issues '' "mysql Sort Issues" "issues/s" issues mysql.sort.issues line $((mysql_priority + 6)) $mysql_update_every
260 DIMENSION Sort_merge_passes merge_passes incremental 1 1
261 DIMENSION Sort_range range incremental 1 1
262 DIMENSION Sort_scan scan incremental 1 1
263
264 CHART mysql_$x.tmp '' "mysql Tmp Operations" "counter" temporaries mysql.tmp line $((mysql_priority + 7)) $mysql_update_every
265 DIMENSION Created_tmp_disk_tables disk_tables incremental 1 1
266 DIMENSION Created_tmp_files files incremental 1 1
267 DIMENSION Created_tmp_tables tables incremental 1 1
268
269 CHART mysql_$x.connections '' "mysql Connections" "connections/s" connections mysql.connections line $((mysql_priority + 8)) $mysql_update_every
270 DIMENSION Connections all incremental 1 1
271 DIMENSION Aborted_connects aborded incremental 1 1
272
273 CHART mysql_$x.binlog_cache '' "mysql Binlog Cache" "transactions/s" binlog mysql.binlog_cache line $((mysql_priority + 9)) $mysql_update_every
274 DIMENSION Binlog_cache_disk_use disk incremental 1 1
275 DIMENSION Binlog_cache_use all incremental 1 1
276
277 CHART mysql_$x.threads '' "mysql Threads" "threads" threads mysql.threads line $((mysql_priority + 10)) $mysql_update_every
278 DIMENSION Threads_connected connected absolute 1 1
279 DIMENSION Threads_created created incremental 1 1
280 DIMENSION Threads_cached cached absolute -1 1
281 DIMENSION Threads_running running absolute 1 1
282
283 CHART mysql_$x.thread_cache_misses '' "mysql Threads Cache Misses" "misses" threads mysql.thread_cache_misses area $((mysql_priority + 11)) $mysql_update_every
284 DIMENSION misses misses absolute 1 100
285
286 CHART mysql_$x.innodb_io '' "mysql InnoDB I/O Bandwidth" "kilobytes/s" innodb mysql.innodb_io area $((mysql_priority + 12)) $mysql_update_every
287 DIMENSION Innodb_data_read read incremental 1 1024
288 DIMENSION Innodb_data_written write incremental -1 1024
289
290 CHART mysql_$x.innodb_io_ops '' "mysql InnoDB I/O Operations" "operations/s" innodb mysql.innodb_io_ops line $((mysql_priority + 13)) $mysql_update_every
291 DIMENSION Innodb_data_reads reads incremental 1 1
292 DIMENSION Innodb_data_writes writes incremental -1 1
293 DIMENSION Innodb_data_fsyncs fsyncs incremental 1 1
294
295 CHART mysql_$x.innodb_io_pending_ops '' "mysql InnoDB Pending I/O Operations" "operations" innodb mysql.innodb_io_pending_ops line $((mysql_priority + 14)) $mysql_update_every
296 DIMENSION Innodb_data_pending_reads reads absolute 1 1
297 DIMENSION Innodb_data_pending_writes writes absolute -1 1
298 DIMENSION Innodb_data_pending_fsyncs fsyncs absolute 1 1
299
300 CHART mysql_$x.innodb_log '' "mysql InnoDB Log Operations" "operations/s" innodb mysql.innodb_log line $((mysql_priority + 15)) $mysql_update_every
301 DIMENSION Innodb_log_waits waits incremental 1 1
302 DIMENSION Innodb_log_write_requests write_requests incremental -1 1
303 DIMENSION Innodb_log_writes writes incremental -1 1
304
305 CHART mysql_$x.innodb_os_log '' "mysql InnoDB OS Log Operations" "operations" innodb mysql.innodb_os_log line $((mysql_priority + 16)) $mysql_update_every
306 DIMENSION Innodb_os_log_fsyncs fsyncs incremental 1 1
307 DIMENSION Innodb_os_log_pending_fsyncs pending_fsyncs absolute 1 1
308 DIMENSION Innodb_os_log_pending_writes pending_writes absolute -1 1
309
310 CHART mysql_$x.innodb_os_log_io '' "mysql InnoDB OS Log Bandwidth" "kilobytes/s" innodb mysql.innodb_os_log_io area $((mysql_priority + 17)) $mysql_update_every
311 DIMENSION Innodb_os_log_written write incremental -1 1024
312
313 CHART mysql_$x.innodb_cur_row_lock '' "mysql InnoDB Current Row Locks" "operations" innodb mysql.innodb_cur_row_lock area $((mysql_priority + 18)) $mysql_update_every
314 DIMENSION Innodb_row_lock_current_waits current_waits absolute 1 1
315
316 CHART mysql_$x.innodb_rows '' "mysql InnoDB Row Operations" "operations/s" innodb mysql.innodb_rows area $((mysql_priority + 19)) $mysql_update_every
317 DIMENSION Innodb_rows_read read incremental 1 1
318 DIMENSION Innodb_rows_deleted deleted incremental -1 1
319 DIMENSION Innodb_rows_inserted inserted incremental 1 1
320 DIMENSION Innodb_rows_updated updated incremental -1 1
321
322 CHART mysql_$x.innodb_buffer_pool_pages '' "mysql InnoDB Buffer Pool Pages" "pages" innodb mysql.innodb_buffer_pool_pages line $((mysql_priority + 20)) $mysql_update_every
323 DIMENSION Innodb_buffer_pool_pages_data data absolute 1 1
324 DIMENSION Innodb_buffer_pool_pages_dirty dirty absolute -1 1
325 DIMENSION Innodb_buffer_pool_pages_free free absolute 1 1
326 DIMENSION Innodb_buffer_pool_pages_flushed flushed incremental -1 1
327 DIMENSION Innodb_buffer_pool_pages_misc misc absolute -1 1
328 DIMENSION Innodb_buffer_pool_pages_total total absolute 1 1
329
330 CHART mysql_$x.innodb_buffer_pool_bytes '' "mysql InnoDB Buffer Pool Bytes" "MB" innodb mysql.innodb_buffer_pool_bytes area $((mysql_priority + 21)) $mysql_update_every
331 DIMENSION Innodb_buffer_pool_bytes_data data absolute 1 $((1024 * 1024))
332 DIMENSION Innodb_buffer_pool_bytes_dirty dirty absolute -1 $((1024 * 1024))
333
334 CHART mysql_$x.innodb_buffer_pool_read_ahead '' "mysql InnoDB Buffer Pool Read Ahead" "operations/s" innodb mysql.innodb_buffer_pool_read_ahead area $((mysql_priority + 22)) $mysql_update_every
335 DIMENSION Innodb_buffer_pool_read_ahead all incremental 1 1
336 DIMENSION Innodb_buffer_pool_read_ahead_evicted evicted incremental -1 1
337 DIMENSION Innodb_buffer_pool_read_ahead_rnd random incremental 1 1
338
339 CHART mysql_$x.innodb_buffer_pool_reqs '' "mysql InnoDB Buffer Pool Requests" "requests/s" innodb mysql.innodb_buffer_pool_reqs area $((mysql_priority + 23)) $mysql_update_every
340 DIMENSION Innodb_buffer_pool_read_requests reads incremental 1 1
341 DIMENSION Innodb_buffer_pool_write_requests writes incremental -1 1
342
343 CHART mysql_$x.innodb_buffer_pool_ops '' "mysql InnoDB Buffer Pool Operations" "operations/s" innodb mysql.innodb_buffer_pool_ops area $((mysql_priority + 24)) $mysql_update_every
344 DIMENSION Innodb_buffer_pool_reads 'disk reads' incremental 1 1
345 DIMENSION Innodb_buffer_pool_wait_free 'wait free' incremental -1 1
346
347 CHART mysql_$x.qcache_ops '' "mysql QCache Operations" "queries/s" qcache mysql.qcache_ops line $((mysql_priority + 25)) $mysql_update_every
348 DIMENSION Qcache_hits hits incremental 1 1
349 DIMENSION Qcache_lowmem_prunes 'lowmem prunes' incremental -1 1
350 DIMENSION Qcache_inserts inserts incremental 1 1
351 DIMENSION Qcache_not_cached 'not cached' incremental -1 1
352
353 CHART mysql_$x.qcache '' "mysql QCache Queries in Cache" "queries" qcache mysql.qcache line $((mysql_priority + 26)) $mysql_update_every
354 DIMENSION Qcache_queries_in_cache queries absolute 1 1
355
356 CHART mysql_$x.qcache_freemem '' "mysql QCache Free Memory" "MB" qcache mysql.qcache_freemem area $((mysql_priority + 27)) $mysql_update_every
357 DIMENSION Qcache_free_memory free absolute 1 $((1024 * 1024))
358
359 CHART mysql_$x.qcache_memblocks '' "mysql QCache Memory Blocks" "blocks" qcache mysql.qcache_memblocks line $((mysql_priority + 28)) $mysql_update_every
360 DIMENSION Qcache_free_blocks free absolute 1 1
361 DIMENSION Qcache_total_blocks total absolute 1 1
362
363 CHART mysql_$x.key_blocks '' "mysql MyISAM Key Cache Blocks" "blocks" myisam mysql.key_blocks line $((mysql_priority + 29)) $mysql_update_every
364 DIMENSION Key_blocks_unused unused absolute 1 1
365 DIMENSION Key_blocks_used used absolute -1 1
366 DIMENSION Key_blocks_not_flushed 'not flushed' absolute 1 1
367
368 CHART mysql_$x.key_requests '' "mysql MyISAM Key Cache Requests" "requests/s" myisam mysql.key_requests area $((mysql_priority + 30)) $mysql_update_every
369 DIMENSION Key_read_requests reads incremental 1 1
370 DIMENSION Key_write_requests writes incremental -1 1
371
372 CHART mysql_$x.key_disk_ops '' "mysql MyISAM Key Cache Disk Operations" "operations/s" myisam mysql.key_disk_ops area $((mysql_priority + 31)) $mysql_update_every
373 DIMENSION Key_reads reads incremental 1 1
374 DIMENSION Key_writes writes incremental -1 1
375
376 CHART mysql_$x.files '' "mysql Open Files" "files" files mysql.files line $((mysql_priority + 32)) $mysql_update_every
377 DIMENSION Open_files files absolute 1 1
378
379 CHART mysql_$x.files_rate '' "mysql Opened Files Rate" "files/s" files mysql.files_rate line $((mysql_priority + 33)) $mysql_update_every
380 DIMENSION Opened_files files incremental 1 1
381 EOF
382
383         if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]
384                 then
385                 cat <<EOF
386 CHART mysql_$x.binlog_stmt_cache '' "mysql Binlog Statement Cache" "statements/s" binlog mysql.binlog_stmt_cache line $((mysql_priority + 50)) $mysql_update_every
387 DIMENSION Binlog_stmt_cache_disk_use disk incremental 1 1
388 DIMENSION Binlog_stmt_cache_use all incremental 1 1
389 EOF
390         fi
391
392         if [ ! -z "$mysql_Connection_errors_accept" ]
393                 then
394                 cat <<EOF
395 CHART mysql_$x.connection_errors '' "mysql Connection Errors" "connections/s" connections mysql.connection_errors line $((mysql_priority + 51)) $mysql_update_every
396 DIMENSION Connection_errors_accept accept incremental 1 1
397 DIMENSION Connection_errors_internal internal incremental 1 1
398 DIMENSION Connection_errors_max_connections max incremental 1 1
399 DIMENSION Connection_errors_peer_addr peer_addr incremental 1 1
400 DIMENSION Connection_errors_select select incremental 1 1
401 DIMENSION Connection_errors_tcpwrap tcpwrap incremental 1 1
402 EOF
403         fi
404
405         done
406         return 0
407 }
408
409
410 mysql_update() {
411         # the first argument to this function is the microseconds since last update
412         # pass this parameter to the BEGIN statement (see bellow).
413
414         # do all the work to collect / calculate the values
415         # for each dimension
416         # remember: KEEP IT SIMPLE AND SHORT
417
418         # 1. get the counters page from mysql
419         # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local mysql_
420         # 3. egrep lines starting with:
421         #    local mysql_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
422         #    local mysql_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
423         # 4. then execute this as a script with the eval
424         #
425         # be very carefull with eval:
426         # prepare the script and always grep at the end the lines that are usefull, so that
427         # even if something goes wrong, no other code can be executed
428
429         local m x
430         for m in "${!mysql_ids[@]}"
431         do
432                 x="${mysql_ids[$m]}"
433
434                 mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]}
435                 if [ $? -ne 0 ]
436                         then
437                         unset mysql_ids[$m]
438                         unset mysql_opts[$m]
439                         unset mysql_cmds[$m]
440                         echo >&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it."
441                         continue
442                 fi
443
444                 # write the result of the work.
445                 cat <<VALUESEOF
446 BEGIN mysql_$x.net $1
447 SET Bytes_received = $mysql_Bytes_received
448 SET Bytes_sent = $mysql_Bytes_sent
449 END
450 BEGIN mysql_$x.queries $1
451 SET Queries = $mysql_Queries
452 SET Questions = $mysql_Questions
453 SET Slow_queries = $mysql_Slow_queries
454 END
455 BEGIN mysql_$x.handlers $1
456 SET Handler_commit = $mysql_Handler_commit
457 SET Handler_delete = $mysql_Handler_delete
458 SET Handler_prepare = $mysql_Handler_prepare
459 SET Handler_read_first = $mysql_Handler_read_first
460 SET Handler_read_key = $mysql_Handler_read_key
461 SET Handler_read_next = $mysql_Handler_read_next
462 SET Handler_read_prev = $mysql_Handler_read_prev
463 SET Handler_read_rnd = $mysql_Handler_read_rnd
464 SET Handler_read_rnd_next = $mysql_Handler_read_rnd_next
465 SET Handler_rollback = $mysql_Handler_rollback
466 SET Handler_savepoint = $mysql_Handler_savepoint
467 SET Handler_savepoint_rollback = $mysql_Handler_savepoint_rollback
468 SET Handler_update = $mysql_Handler_update
469 SET Handler_write = $mysql_Handler_write
470 END
471 BEGIN mysql_$x.table_locks $1
472 SET Table_locks_immediate = $mysql_Table_locks_immediate
473 SET Table_locks_waited = $mysql_Table_locks_waited
474 END
475 BEGIN mysql_$x.join_issues $1
476 SET Select_full_join = $mysql_Select_full_join
477 SET Select_full_range_join = $mysql_Select_full_range_join
478 SET Select_range = $mysql_Select_range
479 SET Select_range_check = $mysql_Select_range_check
480 SET Select_scan = $mysql_Select_scan
481 END
482 BEGIN mysql_$x.sort_issues $1
483 SET Sort_merge_passes = $mysql_Sort_merge_passes
484 SET Sort_range = $mysql_Sort_range
485 SET Sort_scan = $mysql_Sort_scan
486 END
487 BEGIN mysql_$x.tmp $1
488 SET Created_tmp_disk_tables = $mysql_Created_tmp_disk_tables
489 SET Created_tmp_files = $mysql_Created_tmp_files
490 SET Created_tmp_tables = $mysql_Created_tmp_tables
491 END
492 BEGIN mysql_$x.connections $1
493 SET Connections = $mysql_Connections
494 SET Aborted_connects = $mysql_Aborted_connects
495 END
496 BEGIN mysql_$x.binlog_cache $1
497 SET Binlog_cache_disk_use = $mysql_Binlog_cache_disk_use
498 SET Binlog_cache_use = $mysql_Binlog_cache_use
499 END
500 BEGIN mysql_$x.threads $1
501 SET Threads_connected = $mysql_Threads_connected
502 SET Threads_created = $mysql_Threads_created
503 SET Threads_cached = $mysql_Threads_cached
504 SET Threads_running = $mysql_Threads_running
505 END
506 BEGIN mysql_$x.thread_cache_misses $1
507 SET misses = $mysql_Thread_cache_misses
508 END
509 BEGIN mysql_$x.innodb_io $1
510 SET Innodb_data_read = $mysql_Innodb_data_read
511 SET Innodb_data_written = $mysql_Innodb_data_written
512 END
513 BEGIN mysql_$x.innodb_io_ops $1
514 SET Innodb_data_reads = $mysql_Innodb_data_reads
515 SET Innodb_data_writes = $mysql_Innodb_data_writes
516 SET Innodb_data_fsyncs = $mysql_Innodb_data_fsyncs
517 END
518 BEGIN mysql_$x.innodb_io_pending_ops $1
519 SET Innodb_data_pending_reads = $mysql_Innodb_data_pending_reads
520 SET Innodb_data_pending_writes = $mysql_Innodb_data_pending_writes
521 SET Innodb_data_pending_fsyncs = $mysql_Innodb_data_pending_fsyncs
522 END
523 BEGIN mysql_$x.innodb_log $1
524 SET Innodb_log_waits = $mysql_Innodb_log_waits
525 SET Innodb_log_write_requests = $mysql_Innodb_log_write_requests
526 SET Innodb_log_writes = $mysql_Innodb_log_writes
527 END
528 BEGIN mysql_$x.innodb_os_log $1
529 SET Innodb_os_log_fsyncs = $mysql_Innodb_os_log_fsyncs
530 SET Innodb_os_log_pending_fsyncs = $mysql_Innodb_os_log_pending_fsyncs
531 SET Innodb_os_log_pending_writes = $mysql_Innodb_os_log_pending_writes
532 END
533 BEGIN mysql_$x.innodb_os_log_io $1
534 SET Innodb_os_log_written = $mysql_Innodb_os_log_written
535 END
536 BEGIN mysql_$x.innodb_cur_row_lock $1
537 SET Innodb_row_lock_current_waits = $mysql_Innodb_row_lock_current_waits
538 END
539 BEGIN mysql_$x.innodb_rows $1
540 SET Innodb_rows_inserted = $mysql_Innodb_rows_inserted
541 SET Innodb_rows_read = $mysql_Innodb_rows_read
542 SET Innodb_rows_updated = $mysql_Innodb_rows_updated
543 SET Innodb_rows_deleted = $mysql_Innodb_rows_deleted
544 END
545 BEGIN mysql_$x.innodb_buffer_pool_pages $1
546 SET Innodb_buffer_pool_pages_data = $mysql_Innodb_buffer_pool_pages_data
547 SET Innodb_buffer_pool_pages_dirty = $mysql_Innodb_buffer_pool_pages_dirty
548 SET Innodb_buffer_pool_pages_free = $mysql_Innodb_buffer_pool_pages_free
549 SET Innodb_buffer_pool_pages_flushed = $mysql_Innodb_buffer_pool_pages_flushed
550 SET Innodb_buffer_pool_pages_misc = $mysql_Innodb_buffer_pool_pages_misc
551 SET Innodb_buffer_pool_pages_total = $mysql_Innodb_buffer_pool_pages_total
552 END
553 BEGIN mysql_$x.innodb_buffer_pool_bytes $1
554 SET Innodb_buffer_pool_bytes_data = $mysql_Innodb_buffer_pool_bytes_data
555 SET Innodb_buffer_pool_bytes_dirty = $mysql_Innodb_buffer_pool_bytes_dirty
556 END
557 BEGIN mysql_$x.innodb_buffer_pool_read_ahead $1
558 SET Innodb_buffer_pool_read_ahead = $mysql_Innodb_buffer_pool_read_ahead
559 SET Innodb_buffer_pool_read_ahead_evicted = $mysql_Innodb_buffer_pool_read_ahead_evicted
560 SET Innodb_buffer_pool_read_ahead_rnd = $mysql_Innodb_buffer_pool_read_ahead_rnd
561 END
562 BEGIN mysql_$x.innodb_buffer_pool_reqs $1
563 SET Innodb_buffer_pool_read_requests = $mysql_Innodb_buffer_pool_read_requests
564 SET Innodb_buffer_pool_write_requests = $mysql_Innodb_buffer_pool_write_requests
565 END
566 BEGIN mysql_$x.innodb_buffer_pool_ops $1
567 SET Innodb_buffer_pool_reads = $mysql_Innodb_buffer_pool_reads
568 SET Innodb_buffer_pool_wait_free = $mysql_Innodb_buffer_pool_wait_free
569 END
570 BEGIN mysql_$x.qcache_ops $1
571 SET Qcache_hits hits = $mysql_Qcache_hits
572 SET Qcache_lowmem_prunes = $mysql_Qcache_lowmem_prunes
573 SET Qcache_inserts inserts = $mysql_Qcache_inserts inserts
574 SET Qcache_not_cached = $mysql_Qcache_not_cached
575 END
576 BEGIN mysql_$x.qcache $1
577 SET Qcache_queries_in_cache = $mysql_Qcache_queries_in_cache
578 END
579 BEGIN mysql_$x.qcache_freemem $1
580 SET Qcache_free_memory = $mysql_Qcache_free_memory
581 END
582 BEGIN mysql_$x.qcache_memblocks $1
583 SET Qcache_free_blocks = $mysql_Qcache_free_blocks
584 SET Qcache_total_blocks = $mysql_Qcache_total_blocks
585 END
586 BEGIN mysql_$x.key_blocks $1
587 SET Key_blocks_unused = $mysql_Key_blocks_unused
588 SET Key_blocks_used = $mysql_Key_blocks_used
589 SET Key_blocks_not_flushed = $mysql_Key_blocks_not_flushed
590 END
591 BEGIN mysql_$x.key_requests $1
592 SET Key_read_requests = $mysql_Key_read_requests
593 SET Key_write_requests = $mysql_Key_write_requests
594 END
595 BEGIN mysql_$x.key_disk_ops $1
596 SET Key_reads = $mysql_Key_reads
597 SET Key_writes = $mysql_Key_writes
598 END
599 BEGIN mysql_$x.files $1
600 SET Open_files = $mysql_Open_files
601 END
602 BEGIN mysql_$x.files_rate $1
603 SET Opened_files = $mysql_Opened_files
604 END
605 VALUESEOF
606
607                 if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]
608                         then
609                         cat <<VALUESEOF
610 BEGIN mysql_$x.binlog_stmt_cache $1
611 SET Binlog_stmt_cache_disk_use = $mysql_Binlog_stmt_cache_disk_use
612 SET Binlog_stmt_cache_use = $mysql_Binlog_stmt_cache_use
613 END
614 VALUESEOF
615                 fi
616
617                 if [ ! -z "$mysql_Connection_errors_accept" ]
618                         then
619                         cat <<VALUESEOF
620 BEGIN mysql_$x.connection_errors $1
621 SET Connection_errors_accept = $mysql_Connection_errors_accept
622 SET Connection_errors_internal = $mysql_Connection_errors_internal
623 SET Connection_errors_max_connections = $mysql_Connection_errors_max_connections
624 SET Connection_errors_peer_addr = $mysql_Connection_errors_peer_addr
625 SET Connection_errors_select = $mysql_Connection_errors_select
626 SET Connection_errors_tcpwrap = $mysql_Connection_errors_tcpwrap
627 END
628 VALUESEOF
629                 fi
630         done
631
632         [ ${#mysql_ids[@]} -eq 0 ] && echo >&2 "$PROGRAM_NAME: mysql: no mysql servers left active." && return 1
633         return 0
634 }
635