fix for properly working when the name as given by the user and id of the charts do not match #325
Costa Tsaousis (ktsaou) committed
Apr 27, 2016 at 10:37 UTC
2886476060f54566c3faf02d337c4628c8230757
1 file changed
+65
-42
charts.d/mysql.chart.sh
+65
-42
@@ -116,14 +116,31 @@ mysql_check() {
116
# - 0 to enable the chart
117
# - 1 to disable the chart
118
119
- local x m mysql_cmd
119
+ local x m mysql_cmd tryroot=0 unconfigured=0
120
+
121
+ if [ "${1}" = "tryroot" ]
122
+ then
123
+ tryroot=1
124
+ shift
125
+ fi
126
127
[ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql)"
128
129
if [ ${#mysql_opts[@]} -eq 0 ]
130
then
131
+ unconfigured=1
132
+
133
mysql_cmds[local]="$mysql_cmd"
126
- mysql_opts[local]=
134
+
135
+ if [ $tryroot -eq 1 ]
136
+ then
137
+ # the user has not configured us for mysql access
138
+ # if the root user is passwordless in mysql, we can
139
+ # attempt to connect to mysql as root
140
+ mysql_opts[local]="-u root"
141
+ else
142
+ mysql_opts[local]=
143
+ fi
144
fi
145
146
# check once if the url works
@@ -150,30 +167,36 @@ mysql_check() {
167
168
if [ ${#mysql_opts[@]} -eq 0 ]
169
then
153
- 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"
154
- return 1
170
+ if [ ${unconfigured} -eq 1 && ${tryroot} -eq 0 ]
171
+ then
172
+ mysql_check tryroot "${@}"
173
+ return $?
174
+ else
175
+ 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"
176
+ return 1
177
+ fi
178
fi
179
180
return 0
181
}
182
183
mysql_create() {
161
- local m
184
+ local x
185
186
# create the charts
164
- for m in "${mysql_ids[@]}"
187
+ for x in "${mysql_ids[@]}"
188
do
189
cat <<EOF
167
-CHART mysql_$m.net '' "mysql Bandwidth" "kilobits/s" bandwidth mysql.net area $[mysql_priority + 1] $mysql_update_every
190
+CHART mysql_$x.net '' "mysql Bandwidth" "kilobits/s" bandwidth mysql.net area $[mysql_priority + 1] $mysql_update_every
191
DIMENSION Bytes_received in incremental 8 1024
192
DIMENSION Bytes_sent out incremental -8 1024
193
171
-CHART mysql_$m.queries '' "mysql Queries" "queries/s" queries mysql.queries line $[mysql_priority + 2] $mysql_update_every
194
+CHART mysql_$x.queries '' "mysql Queries" "queries/s" queries mysql.queries line $[mysql_priority + 2] $mysql_update_every
195
DIMENSION Queries queries incremental 1 1
196
DIMENSION Questions questions incremental 1 1
197
DIMENSION Slow_queries slow_queries incremental -1 1
198
176
-CHART mysql_$m.handlers '' "mysql Handlers" "handlers/s" handlers mysql.handlers line $[mysql_priority + 3] $mysql_update_every
199
+CHART mysql_$x.handlers '' "mysql Handlers" "handlers/s" handlers mysql.handlers line $[mysql_priority + 3] $mysql_update_every
200
DIMENSION Handler_commit commit incremental 1 1
201
DIMENSION Handler_delete delete incremental 1 1
202
DIMENSION Handler_prepare prepare incremental 1 1
@@ -189,75 +212,75 @@ DIMENSION Handler_savepoint_rollback savepoint_rollback incremental 1 1
212
DIMENSION Handler_update update incremental 1 1
213
DIMENSION Handler_write write incremental 1 1
214
192
-CHART mysql_$m.table_locks '' "mysql Tables Locks" "locks/s" locks mysql.table_locks line $[mysql_priority + 4] $mysql_update_every
215
+CHART mysql_$x.table_locks '' "mysql Tables Locks" "locks/s" locks mysql.table_locks line $[mysql_priority + 4] $mysql_update_every
216
DIMENSION Table_locks_immediate immediate incremental 1 1
217
DIMENSION Table_locks_waited waited incremental -1 1
218
196
-CHART mysql_$m.join_issues '' "mysql Select Join Issues" "joins/s" issues mysql.join_issues line $[mysql_priority + 5] $mysql_update_every
219
+CHART mysql_$x.join_issues '' "mysql Select Join Issues" "joins/s" issues mysql.join_issues line $[mysql_priority + 5] $mysql_update_every
220
DIMENSION Select_full_join full_join incremental 1 1
221
DIMENSION Select_full_range_join full_range_join incremental 1 1
222
DIMENSION Select_range range incremental 1 1
223
DIMENSION Select_range_check range_check incremental 1 1
224
DIMENSION Select_scan scan incremental 1 1
225
203
-CHART mysql_$m.sort_issues '' "mysql Sort Issues" "issues/s" issues mysql.sort.issues line $[mysql_priority + 6] $mysql_update_every
226
+CHART mysql_$x.sort_issues '' "mysql Sort Issues" "issues/s" issues mysql.sort.issues line $[mysql_priority + 6] $mysql_update_every
227
DIMENSION Sort_merge_passes merge_passes incremental 1 1
228
DIMENSION Sort_range range incremental 1 1
229
DIMENSION Sort_scan scan incremental 1 1
230
208
-CHART mysql_$m.tmp '' "mysql Tmp Operations" "counter" temporaries mysql.tmp line $[mysql_priority + 7] $mysql_update_every
231
+CHART mysql_$x.tmp '' "mysql Tmp Operations" "counter" temporaries mysql.tmp line $[mysql_priority + 7] $mysql_update_every
232
DIMENSION Created_tmp_disk_tables disk_tables incremental 1 1
233
DIMENSION Created_tmp_files files incremental 1 1
234
DIMENSION Created_tmp_tables tables incremental 1 1
235
213
-CHART mysql_$m.connections '' "mysql Connections" "connections/s" connections mysql.connections line $[mysql_priority + 8] $mysql_update_every
236
+CHART mysql_$x.connections '' "mysql Connections" "connections/s" connections mysql.connections line $[mysql_priority + 8] $mysql_update_every
237
DIMENSION Connections all incremental 1 1
238
DIMENSION Aborted_connects aborded incremental 1 1
239
217
-CHART mysql_$m.binlog_cache '' "mysql Binlog Cache" "transactions/s" binlog mysql.binlog_cache line $[mysql_priority + 9] $mysql_update_every
240
+CHART mysql_$x.binlog_cache '' "mysql Binlog Cache" "transactions/s" binlog mysql.binlog_cache line $[mysql_priority + 9] $mysql_update_every
241
DIMENSION Binlog_cache_disk_use disk incremental 1 1
242
DIMENSION Binlog_cache_use all incremental 1 1
243
221
-CHART mysql_$m.threads '' "mysql Threads" "threads" threads mysql.threads line $[mysql_priority + 10] $mysql_update_every
244
+CHART mysql_$x.threads '' "mysql Threads" "threads" threads mysql.threads line $[mysql_priority + 10] $mysql_update_every
245
DIMENSION Threads_connected connected absolute 1 1
246
DIMENSION Threads_created created incremental 1 1
247
DIMENSION Threads_cached cached absolute -1 1
248
DIMENSION Threads_running running absolute 1 1
249
227
-CHART mysql_$m.thread_cache_misses '' "mysql Threads Cache Misses" "misses" threads mysql.thread_cache_misses area $[mysql_priority + 11] $mysql_update_every
250
+CHART mysql_$x.thread_cache_misses '' "mysql Threads Cache Misses" "misses" threads mysql.thread_cache_misses area $[mysql_priority + 11] $mysql_update_every
251
DIMENSION misses misses absolute 1 100
252
230
-CHART mysql_$m.innodb_io '' "mysql InnoDB I/O Bandwidth" "kilobytes/s" innodb mysql.innodb_io area $[mysql_priority + 12] $mysql_update_every
253
+CHART mysql_$x.innodb_io '' "mysql InnoDB I/O Bandwidth" "kilobytes/s" innodb mysql.innodb_io area $[mysql_priority + 12] $mysql_update_every
254
DIMENSION Innodb_data_read read incremental 1 1024
255
DIMENSION Innodb_data_written write incremental -1 1024
256
234
-CHART mysql_$m.innodb_io_ops '' "mysql InnoDB I/O Operations" "operations/s" innodb mysql.innodb_io_ops line $[mysql_priority + 13] $mysql_update_every
257
+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
258
DIMENSION Innodb_data_reads reads incremental 1 1
259
DIMENSION Innodb_data_writes writes incremental -1 1
260
DIMENSION Innodb_data_fsyncs fsyncs incremental 1 1
261
239
-CHART mysql_$m.innodb_io_pending_ops '' "mysql InnoDB Pending I/O Operations" "operations" innodb mysql.innodb_io_pending_ops line $[mysql_priority + 14] $mysql_update_every
262
+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
263
DIMENSION Innodb_data_pending_reads reads absolute 1 1
264
DIMENSION Innodb_data_pending_writes writes absolute -1 1
265
DIMENSION Innodb_data_pending_fsyncs fsyncs absolute 1 1
266
244
-CHART mysql_$m.innodb_log '' "mysql InnoDB Log Operations" "operations/s" innodb mysql.innodb_log line $[mysql_priority + 15] $mysql_update_every
267
+CHART mysql_$x.innodb_log '' "mysql InnoDB Log Operations" "operations/s" innodb mysql.innodb_log line $[mysql_priority + 15] $mysql_update_every
268
DIMENSION Innodb_log_waits waits incremental 1 1
269
DIMENSION Innodb_log_write_requests write_requests incremental -1 1
270
DIMENSION Innodb_log_writes writes incremental -1 1
271
249
-CHART mysql_$m.innodb_os_log '' "mysql InnoDB OS Log Operations" "operations" innodb mysql.innodb_os_log line $[mysql_priority + 16] $mysql_update_every
272
+CHART mysql_$x.innodb_os_log '' "mysql InnoDB OS Log Operations" "operations" innodb mysql.innodb_os_log line $[mysql_priority + 16] $mysql_update_every
273
DIMENSION Innodb_os_log_fsyncs fsyncs incremental 1 1
274
DIMENSION Innodb_os_log_pending_fsyncs pending_fsyncs absolute 1 1
275
DIMENSION Innodb_os_log_pending_writes pending_writes absolute -1 1
276
254
-CHART mysql_$m.innodb_os_log_io '' "mysql InnoDB OS Log Bandwidth" "kilobytes/s" innodb mysql.innodb_os_log_io area $[mysql_priority + 17] $mysql_update_every
277
+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
278
DIMENSION Innodb_os_log_written write incremental -1 1024
279
257
-CHART mysql_$m.innodb_cur_row_lock '' "mysql InnoDB Current Row Locks" "operations" innodb mysql.innodb_cur_row_lock area $[mysql_priority + 18] $mysql_update_every
280
+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
281
DIMENSION Innodb_row_lock_current_waits current_waits absolute 1 1
282
260
-CHART mysql_$m.innodb_rows '' "mysql InnoDB Row Operations" "operations/s" innodb mysql.innodb_rows area $[mysql_priority + 19] $mysql_update_every
283
+CHART mysql_$x.innodb_rows '' "mysql InnoDB Row Operations" "operations/s" innodb mysql.innodb_rows area $[mysql_priority + 19] $mysql_update_every
284
DIMENSION Innodb_rows_read read incremental 1 1
285
DIMENSION Innodb_rows_deleted deleted incremental -1 1
286
DIMENSION Innodb_rows_inserted inserted incremental 1 1
@@ -268,7 +291,7 @@ EOF
291
if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]
292
then
293
cat <<EOF
271
-CHART mysql_$m.binlog_stmt_cache '' "mysql Binlog Statement Cache" "statements/s" binlog mysql.binlog_stmt_cache line $[mysql_priority + 20] $mysql_update_every
294
+CHART mysql_$x.binlog_stmt_cache '' "mysql Binlog Statement Cache" "statements/s" binlog mysql.binlog_stmt_cache line $[mysql_priority + 20] $mysql_update_every
295
DIMENSION Binlog_stmt_cache_disk_use disk incremental 1 1
296
DIMENSION Binlog_stmt_cache_use all incremental 1 1
297
EOF
@@ -277,7 +300,7 @@ EOF
300
if [ ! -z "$mysql_Connection_errors_accept" ]
301
then
302
cat <<EOF
280
-CHART mysql_$m.connection_errors '' "mysql Connection Errors" "connections/s" connections mysql.connection_errors line $[mysql_priority + 21] $mysql_update_every
303
+CHART mysql_$x.connection_errors '' "mysql Connection Errors" "connections/s" connections mysql.connection_errors line $[mysql_priority + 21] $mysql_update_every
304
DIMENSION Connection_errors_accept accept incremental 1 1
305
DIMENSION Connection_errors_internal internal incremental 1 1
306
DIMENSION Connection_errors_max_connections max incremental 1 1
@@ -369,59 +392,59 @@ SET Sort_merge_passes = $mysql_Sort_merge_passes
392
SET Sort_range = $mysql_Sort_range
393
SET Sort_scan = $mysql_Sort_scan
394
END
372
-BEGIN mysql_$m.tmp $1
395
+BEGIN mysql_$x.tmp $1
396
SET Created_tmp_disk_tables = $mysql_Created_tmp_disk_tables
397
SET Created_tmp_files = $mysql_Created_tmp_files
398
SET Created_tmp_tables = $mysql_Created_tmp_tables
399
END
377
-BEGIN mysql_$m.connections $1
400
+BEGIN mysql_$x.connections $1
401
SET Connections = $mysql_Connections
402
SET Aborted_connects = $mysql_Aborted_connects
403
END
381
-BEGIN mysql_$m.binlog_cache $1
404
+BEGIN mysql_$x.binlog_cache $1
405
SET Binlog_cache_disk_use = $mysql_Binlog_cache_disk_use
406
SET Binlog_cache_use = $mysql_Binlog_cache_use
407
END
385
-BEGIN mysql_$m.threads $1
408
+BEGIN mysql_$x.threads $1
409
SET Threads_connected = $mysql_Threads_connected
410
SET Threads_created = $mysql_Threads_created
411
SET Threads_cached = $mysql_Threads_cached
412
SET Threads_running = $mysql_Threads_running
413
END
391
-BEGIN mysql_$m.thread_cache_misses $1
414
+BEGIN mysql_$x.thread_cache_misses $1
415
SET misses = $mysql_Thread_cache_misses
416
END
394
-BEGIN mysql_$m.innodb_io $1
417
+BEGIN mysql_$x.innodb_io $1
418
SET Innodb_data_read = $mysql_Innodb_data_read
419
SET Innodb_data_written = $mysql_Innodb_data_written
420
END
398
-BEGIN mysql_$m.innodb_io_ops $1
421
+BEGIN mysql_$x.innodb_io_ops $1
422
SET Innodb_data_reads = $mysql_Innodb_data_reads
423
SET Innodb_data_writes = $mysql_Innodb_data_writes
424
SET Innodb_data_fsyncs = $mysql_Innodb_data_fsyncs
425
END
403
-BEGIN mysql_$m.innodb_io_pending_ops $1
426
+BEGIN mysql_$x.innodb_io_pending_ops $1
427
SET Innodb_data_pending_reads = $mysql_Innodb_data_pending_reads
428
SET Innodb_data_pending_writes = $mysql_Innodb_data_pending_writes
429
SET Innodb_data_pending_fsyncs = $mysql_Innodb_data_pending_fsyncs
430
END
408
-BEGIN mysql_$m.innodb_log $1
431
+BEGIN mysql_$x.innodb_log $1
432
SET Innodb_log_waits = $mysql_Innodb_log_waits
433
SET Innodb_log_write_requests = $mysql_Innodb_log_write_requests
434
SET Innodb_log_writes = $mysql_Innodb_log_writes
435
END
413
-BEGIN mysql_$m.innodb_os_log $1
436
+BEGIN mysql_$x.innodb_os_log $1
437
SET Innodb_os_log_fsyncs = $mysql_Innodb_os_log_fsyncs
438
SET Innodb_os_log_pending_fsyncs = $mysql_Innodb_os_log_pending_fsyncs
439
SET Innodb_os_log_pending_writes = $mysql_Innodb_os_log_pending_writes
440
END
418
-BEGIN mysql_$m.innodb_os_log_io $1
441
+BEGIN mysql_$x.innodb_os_log_io $1
442
SET Innodb_os_log_written = $mysql_Innodb_os_log_written
443
END
421
-BEGIN mysql_$m.innodb_cur_row_lock $1
444
+BEGIN mysql_$x.innodb_cur_row_lock $1
445
SET Innodb_row_lock_current_waits = $mysql_Innodb_row_lock_current_waits
446
END
424
-BEGIN mysql_$m.innodb_rows $1
447
+BEGIN mysql_$x.innodb_rows $1
448
SET Innodb_rows_inserted = $mysql_Innodb_rows_inserted
449
SET Innodb_rows_read = $mysql_Innodb_rows_read
450
SET Innodb_rows_updated = $mysql_Innodb_rows_updated
@@ -432,7 +455,7 @@ VALUESEOF
455
if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]
456
then
457
cat <<VALUESEOF
435
-BEGIN mysql_$m.binlog_stmt_cache $1
458
+BEGIN mysql_$x.binlog_stmt_cache $1
459
SET Binlog_stmt_cache_disk_use = $mysql_Binlog_stmt_cache_disk_use
460
SET Binlog_stmt_cache_use = $mysql_Binlog_stmt_cache_use
461
END
@@ -442,7 +465,7 @@ VALUESEOF
465
if [ ! -z "$mysql_Connection_errors_accept" ]
466
then
467
cat <<VALUESEOF
445
-BEGIN mysql_$m.connection_errors $1
468
+BEGIN mysql_$x.connection_errors $1
469
SET Connection_errors_accept = $mysql_Connection_errors_accept
470
SET Connection_errors_internal = $mysql_Connection_errors_internal
471
SET Connection_errors_max_connections = $mysql_Connection_errors_max_connections