温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Netdata Mysql运行情况监控插件怎么用

发布时间:2022-01-05 17:22:18 来源:亿速云 阅读:189 作者:小新 栏目:大数据

这篇文章给大家分享的是有关Netdata Mysql运行情况监控插件怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

一:mysql文件配置
/usr/local/netdata/etc/netdata  增加配置文件mysql.conf


  1. mysql_cmds[MY_A]="/usr/local/mysql/bin/mysql"

  2. mysql_opts[MY_A]="-h localhost -uroot"



二:mysql.chart.sh 插件脚本


  1. #!/bin/bash


  2. # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html

  3. #

  4. # https://dev.mysql.com/doc/refman/5.1/en/show-status.html

  5. # SHOW STATUS provides server status information (see Section 5.1.6, “Server Status Variables”).

  6. # This statement does not require any privilege.

  7. # It requires only the ability to connect to the server.


  8. mysql_update_every=5

  9. mysql_priority=60000


  10. declare -A mysql_cmds=() mysql_opts=() mysql_ids=()


  11. mysql_exec() {

  12.     local ret


  13.     "${@}" -s -e "show global status;"

  14.     ret=$?


  15.     [ $ret -ne 0 ] && echo "plugin_command_failure $ret"

  16.     return $ret

  17. }


  18. mysql_get() {

  19.     unset \

  20.         mysql_Bytes_received \

  21.         mysql_Bytes_sent \

  22.         mysql_Queries \

  23.         mysql_Questions \

  24.         mysql_Slow_queries \

  25.         mysql_Handler_commit \

  26.         mysql_Handler_delete \

  27.         mysql_Handler_prepare \

  28.         mysql_Handler_read_first \

  29.         mysql_Handler_read_key \

  30.         mysql_Handler_read_next \

  31.         mysql_Handler_read_prev \

  32.         mysql_Handler_read_rnd \

  33.         mysql_Handler_read_rnd_next \

  34.         mysql_Handler_rollback \

  35.         mysql_Handler_savepoint \

  36.         mysql_Handler_savepoint_rollback \

  37.         mysql_Handler_update \

  38.         mysql_Handler_write \

  39.         mysql_Table_locks_immediate \

  40.         mysql_Table_locks_waited \

  41.         mysql_Select_full_join \

  42.         mysql_Select_full_range_join \

  43.         mysql_Select_range \

  44.         mysql_Select_range_check \

  45.         mysql_Select_scan \

  46.         mysql_Sort_merge_passes \

  47.         mysql_Sort_range \

  48.         mysql_Sort_scan \

  49.         mysql_Created_tmp_disk_tables \

  50.         mysql_Created_tmp_files \

  51.         mysql_Created_tmp_tables \

  52.         mysql_Connection_errors_accept \

  53.         mysql_Connection_errors_internal \

  54.         mysql_Connection_errors_max_connections \

  55.         mysql_Connection_errors_peer_addr \

  56.         mysql_Connection_errors_select \

  57.         mysql_Connection_errors_tcpwrap \

  58.         mysql_Connections \

  59.         mysql_Aborted_connects \

  60.         mysql_Binlog_cache_disk_use \

  61.         mysql_Binlog_cache_use \

  62.         mysql_Binlog_stmt_cache_disk_use \

  63.         mysql_Binlog_stmt_cache_use \

  64.         mysql_Threads_connected \

  65.         mysql_Threads_created \

  66.         mysql_Threads_cached \

  67.         mysql_Threads_running \

  68.         mysql_Innodb_data_read \

  69.         mysql_Innodb_data_written \

  70.         mysql_Innodb_data_reads \

  71.         mysql_Innodb_data_writes \

  72.         mysql_Innodb_data_fsyncs \

  73.         mysql_Innodb_data_pending_reads \

  74.         mysql_Innodb_data_pending_writes \

  75.         mysql_Innodb_data_pending_fsyncs \

  76.         mysql_Innodb_log_waits \

  77.         mysql_Innodb_log_write_requests \

  78.         mysql_Innodb_log_writes \

  79.         mysql_Innodb_os_log_fsyncs \

  80.         mysql_Innodb_os_log_pending_fsyncs \

  81.         mysql_Innodb_os_log_pending_writes \

  82.         mysql_Innodb_os_log_written \

  83.         mysql_Innodb_row_lock_current_waits \

  84.         mysql_Innodb_rows_inserted \

  85.         mysql_Innodb_rows_read \

  86.         mysql_Innodb_rows_updated \

  87.         mysql_Innodb_rows_deleted \

  88.         mysql_Innodb_buffer_pool_pages_data \

  89.         mysql_Innodb_buffer_pool_pages_dirty \

  90.         mysql_Innodb_buffer_pool_pages_flushed \

  91.         mysql_Innodb_buffer_pool_pages_free \

  92.         mysql_Innodb_buffer_pool_pages_misc \

  93.         mysql_Innodb_buffer_pool_pages_total \

  94.         mysql_Innodb_buffer_pool_bytes_data \

  95.         mysql_Innodb_buffer_pool_bytes_dirty \

  96.         mysql_Innodb_buffer_pool_read_ahead_rnd \

  97.         mysql_Innodb_buffer_pool_read_ahead \

  98.         mysql_Innodb_buffer_pool_read_ahead_evicted \

  99.         mysql_Innodb_buffer_pool_read_requests \

  100.         mysql_Innodb_buffer_pool_reads \

  101.         mysql_Innodb_buffer_pool_wait_free \

  102.         mysql_Innodb_buffer_pool_write_requests \

  103.         mysql_Qcache_free_blocks \

  104.         mysql_Qcache_free_memory \

  105.         mysql_Qcache_hits \

  106.         mysql_Qcache_inserts \

  107.         mysql_Qcache_lowmem_prunes \

  108.         mysql_Qcache_not_cached \

  109.         mysql_Qcache_queries_in_cache \

  110.         mysql_Qcache_total_blocks \

  111.         mysql_Key_blocks_not_flushed \

  112.         mysql_Key_blocks_unused \

  113.         mysql_Key_blocks_used \

  114.         mysql_Key_read_requests \

  115.         mysql_Key_reads \

  116.         mysql_Key_write_requests \

  117.         mysql_Key_writes \

  118.         mysql_Open_files \

  119.         mysql_Opened_files



  120.     mysql_plugin_command_failure=0


  121.     eval "$(mysql_exec "${@}" |\

  122.         sed \

  123.             -e "s/[[:space:]]\+/ /g" \

  124.             -e "s/\./_/g" \

  125.             -e "s/^\([a-zA-Z0-9_]\+\)[[:space:]]\+\([0-9]\+\)$/mysql_\1=\2/g" |\

  126.         egrep "^mysql_[a-zA-Z0-9_]+=[[:digit:]]+$")"


  127.     [ $mysql_plugin_command_failure -eq 1 ] && return 1

  128.     [ -z "$mysql_Connections" ] && return 1


  129.     mysql_Thread_cache_misses=0

  130.     [ $(( mysql_Connections + 1 - 1 )) -gt 0 ] && mysql_Thread_cache_misses=$(( mysql_Threads_created * 10000 / mysql_Connections ))


  131.     return 0

  132. }


  133. mysql_check() {

  134.     # this should return:

  135.     # - 0 to enable the chart

  136.     # - 1 to disable the chart


  137.     local x m mysql_cmd tryroot=0 unconfigured=0


  138.     if [ "${1}" = "tryroot" ]

  139.         then

  140.         tryroot=1

  141.         shift

  142.     fi


  143.     [ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql)"


  144.     if [ ${#mysql_opts[@]} -eq 0 ]

  145.         then

  146.         unconfigured=1


  147.         mysql_cmds[local]="$mysql_cmd"


  148.         if [ $tryroot -eq 1 ]

  149.             then

  150.             # the user has not configured us for mysql access

  151.             # if the root user is passwordless in mysql, we can

  152.             # attempt to connect to mysql as root

  153.             mysql_opts[local]="-u root"

  154.         else

  155.             mysql_opts[local]=

  156.         fi

  157.     fi


  158.     # check once if the url works

  159.     for m in "${!mysql_opts[@]}"

  160.     do

  161.         [ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd"

  162.         if [ -z "${mysql_cmds[$m]}" ]

  163.             then

  164.             echo >&2 "$PROGRAM_NAME: mysql: cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf"

  165.         fi


  166.         mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]}

  167.         if [ ! $? -eq 0 ]

  168.         then

  169.             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"

  170.             unset mysql_cmds[$m]

  171.             unset mysql_opts[$m]

  172.             unset mysql_ids[$m]

  173.             continue

  174.         fi


  175.         mysql_ids[$m]="$( fixid "$m" )"

  176.     done


  177.     if [ ${#mysql_opts[@]} -eq 0 ]

  178.         then

  179.         if [ ${unconfigured} -eq 1 && ${tryroot} -eq 0 ]

  180.             then

  181.             mysql_check tryroot "${@}"

  182.             return $?

  183.         else

  184.             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"

  185.             return 1

  186.         fi

  187.     fi


  188.     return 0

  189. }


  190. mysql_create() {

  191.     local x


  192.     # create the charts

  193.     for x in "${mysql_ids[@]}"

  194.     do

  195.         cat <<EOF

  196. CHART mysql_$x.net '' "mysql Bandwidth" "kilobits/s" bandwidth mysql.net area $((mysql_priority + 1)) $mysql_update_every

  197. DIMENSION Bytes_received in incremental 8 1024

  198. DIMENSION Bytes_sent out incremental -8 1024

  199. CHART mysql_$x.queries '' "mysql Queries" "queries/s" queries mysql.queries line $((mysql_priority + 2)) $mysql_update_every

  200. DIMENSION Queries queries incremental 1 1

  201. DIMENSION Questions questions incremental 1 1

  202. DIMENSION Slow_queries slow_queries incremental -1 1

  203. CHART mysql_$x.handlers '' "mysql Handlers" "handlers/s" handlers mysql.handlers line $((mysql_priority + 3)) $mysql_update_every

  204. DIMENSION Handler_commit commit incremental 1 1

  205. DIMENSION Handler_delete delete incremental 1 1

  206. DIMENSION Handler_prepare prepare incremental 1 1

  207. DIMENSION Handler_read_first read_first incremental 1 1

  208. DIMENSION Handler_read_key read_key incremental 1 1

  209. DIMENSION Handler_read_next read_next incremental 1 1

  210. DIMENSION Handler_read_prev read_prev incremental 1 1

  211. DIMENSION Handler_read_rnd read_rnd incremental 1 1

  212. DIMENSION Handler_read_rnd_next read_rnd_next incremental 1 1

  213. DIMENSION Handler_rollback rollback incremental 1 1

  214. DIMENSION Handler_savepoint savepoint incremental 1 1

  215. DIMENSION Handler_savepoint_rollback savepoint_rollback incremental 1 1

  216. DIMENSION Handler_update update incremental 1 1

  217. DIMENSION Handler_write write incremental 1 1

  218. CHART mysql_$x.table_locks '' "mysql Tables Locks" "locks/s" locks mysql.table_locks line $((mysql_priority + 4)) $mysql_update_every

  219. DIMENSION Table_locks_immediate immediate incremental 1 1

  220. DIMENSION Table_locks_waited waited incremental -1 1

  221. CHART mysql_$x.join_issues '' "mysql Select Join Issues" "joins/s" issues mysql.join_issues line $((mysql_priority + 5)) $mysql_update_every

  222. DIMENSION Select_full_join full_join incremental 1 1

  223. DIMENSION Select_full_range_join full_range_join incremental 1 1

  224. DIMENSION Select_range range incremental 1 1

  225. DIMENSION Select_range_check range_check incremental 1 1

  226. DIMENSION Select_scan scan incremental 1 1

  227. CHART mysql_$x.sort_issues '' "mysql Sort Issues" "issues/s" issues mysql.sort.issues line $((mysql_priority + 6)) $mysql_update_every

  228. DIMENSION Sort_merge_passes merge_passes incremental 1 1

  229. DIMENSION Sort_range range incremental 1 1

  230. DIMENSION Sort_scan scan incremental 1 1

  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. CHART mysql_$x.connections '' "mysql Connections" "connections/s" connections mysql.connections line $((mysql_priority + 8)) $mysql_update_every

  236. DIMENSION Connections all incremental 1 1

  237. DIMENSION Aborted_connects aborded incremental 1 1

  238. CHART mysql_$x.binlog_cache '' "mysql Binlog Cache" "transactions/s" binlog mysql.binlog_cache line $((mysql_priority + 9)) $mysql_update_every

  239. DIMENSION Binlog_cache_disk_use disk incremental 1 1

  240. DIMENSION Binlog_cache_use all incremental 1 1

  241. CHART mysql_$x.threads '' "mysql Threads" "threads" threads mysql.threads line $((mysql_priority + 10)) $mysql_update_every

  242. DIMENSION Threads_connected connected absolute 1 1

  243. DIMENSION Threads_created created incremental 1 1

  244. DIMENSION Threads_cached cached absolute -1 1

  245. DIMENSION Threads_running running absolute 1 1

  246. CHART mysql_$x.thread_cache_misses '' "mysql Threads Cache Misses" "misses" threads mysql.thread_cache_misses area $((mysql_priority + 11)) $mysql_update_every

  247. DIMENSION misses misses absolute 1 100

  248. CHART mysql_$x.innodb_io '' "mysql InnoDB I/O Bandwidth" "kilobytes/s" innodb mysql.innodb_io area $((mysql_priority + 12)) $mysql_update_every

  249. DIMENSION Innodb_data_read read incremental 1 1024

  250. DIMENSION Innodb_data_written write incremental -1 1024

  251. 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

  252. DIMENSION Innodb_data_reads reads incremental 1 1

  253. DIMENSION Innodb_data_writes writes incremental -1 1

  254. DIMENSION Innodb_data_fsyncs fsyncs incremental 1 1

  255. 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

  256. DIMENSION Innodb_data_pending_reads reads absolute 1 1

  257. DIMENSION Innodb_data_pending_writes writes absolute -1 1

  258. DIMENSION Innodb_data_pending_fsyncs fsyncs absolute 1 1

  259. CHART mysql_$x.innodb_log '' "mysql InnoDB Log Operations" "operations/s" innodb mysql.innodb_log line $((mysql_priority + 15)) $mysql_update_every

  260. DIMENSION Innodb_log_waits waits incremental 1 1

  261. DIMENSION Innodb_log_write_requests write_requests incremental -1 1

  262. DIMENSION Innodb_log_writes writes incremental -1 1

  263. CHART mysql_$x.innodb_os_log '' "mysql InnoDB OS Log Operations" "operations" innodb mysql.innodb_os_log line $((mysql_priority + 16)) $mysql_update_every

  264. DIMENSION Innodb_os_log_fsyncs fsyncs incremental 1 1

  265. DIMENSION Innodb_os_log_pending_fsyncs pending_fsyncs absolute 1 1

  266. DIMENSION Innodb_os_log_pending_writes pending_writes absolute -1 1

  267. 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

  268. DIMENSION Innodb_os_log_written write incremental -1 1024

  269. 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

  270. DIMENSION Innodb_row_lock_current_waits current_waits absolute 1 1

  271. CHART mysql_$x.innodb_rows '' "mysql InnoDB Row Operations" "operations/s" innodb mysql.innodb_rows area $((mysql_priority + 19)) $mysql_update_every

  272. DIMENSION Innodb_rows_read read incremental 1 1

  273. DIMENSION Innodb_rows_deleted deleted incremental -1 1

  274. DIMENSION Innodb_rows_inserted inserted incremental 1 1

  275. DIMENSION Innodb_rows_updated updated incremental -1 1

  276. 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

  277. DIMENSION Innodb_buffer_pool_pages_data data absolute 1 1

  278. DIMENSION Innodb_buffer_pool_pages_dirty dirty absolute -1 1

  279. DIMENSION Innodb_buffer_pool_pages_free free absolute 1 1

  280. DIMENSION Innodb_buffer_pool_pages_flushed flushed incremental -1 1

  281. DIMENSION Innodb_buffer_pool_pages_misc misc absolute -1 1

  282. DIMENSION Innodb_buffer_pool_pages_total total absolute 1 1

  283. 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

  284. DIMENSION Innodb_buffer_pool_bytes_data data absolute 1 $((1024 * 1024))

  285. DIMENSION Innodb_buffer_pool_bytes_dirty dirty absolute -1 $((1024 * 1024))

  286. 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

  287. DIMENSION Innodb_buffer_pool_read_ahead all incremental 1 1

  288. DIMENSION Innodb_buffer_pool_read_ahead_evicted evicted incremental -1 1

  289. DIMENSION Innodb_buffer_pool_read_ahead_rnd random incremental 1 1

  290. 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

  291. DIMENSION Innodb_buffer_pool_read_requests reads incremental 1 1

  292. DIMENSION Innodb_buffer_pool_write_requests writes incremental -1 1

  293. 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

  294. DIMENSION Innodb_buffer_pool_reads 'disk reads' incremental 1 1

  295. DIMENSION Innodb_buffer_pool_wait_free 'wait free' incremental -1 1

  296. CHART mysql_$x.qcache_ops '' "mysql QCache Operations" "queries/s" qcache mysql.qcache_ops line $((mysql_priority + 25)) $mysql_update_every

  297. DIMENSION Qcache_hits hits incremental 1 1

  298. DIMENSION Qcache_lowmem_prunes 'lowmem prunes' incremental -1 1

  299. DIMENSION Qcache_inserts inserts incremental 1 1

  300. DIMENSION Qcache_not_cached 'not cached' incremental -1 1

  301. CHART mysql_$x.qcache '' "mysql QCache Queries in Cache" "queries" qcache mysql.qcache line $((mysql_priority + 26)) $mysql_update_every

  302. DIMENSION Qcache_queries_in_cache queries absolute 1 1

  303. CHART mysql_$x.qcache_freemem '' "mysql QCache Free Memory" "MB" qcache mysql.qcache_freemem area $((mysql_priority + 27)) $mysql_update_every

  304. DIMENSION Qcache_free_memory free absolute 1 $((1024 * 1024))

  305. CHART mysql_$x.qcache_memblocks '' "mysql QCache Memory Blocks" "blocks" qcache mysql.qcache_memblocks line $((mysql_priority + 28)) $mysql_update_every

  306. DIMENSION Qcache_free_blocks free absolute 1 1

  307. DIMENSION Qcache_total_blocks total absolute 1 1

  308. CHART mysql_$x.key_blocks '' "mysql MyISAM Key Cache Blocks" "blocks" myisam mysql.key_blocks line $((mysql_priority + 29)) $mysql_update_every

  309. DIMENSION Key_blocks_unused unused absolute 1 1

  310. DIMENSION Key_blocks_used used absolute -1 1

  311. DIMENSION Key_blocks_not_flushed 'not flushed' absolute 1 1

  312. CHART mysql_$x.key_requests '' "mysql MyISAM Key Cache Requests" "requests/s" myisam mysql.key_requests area $((mysql_priority + 30)) $mysql_update_every

  313. DIMENSION Key_read_requests reads incremental 1 1

  314. DIMENSION Key_write_requests writes incremental -1 1

  315. 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

  316. DIMENSION Key_reads reads incremental 1 1

  317. DIMENSION Key_writes writes incremental -1 1

  318. CHART mysql_$x.files '' "mysql Open Files" "files" files mysql.files line $((mysql_priority + 32)) $mysql_update_every

  319. DIMENSION Open_files files absolute 1 1

  320. CHART mysql_$x.files_rate '' "mysql Opened Files Rate" "files/s" files mysql.files_rate line $((mysql_priority + 33)) $mysql_update_every

  321. DIMENSION Opened_files files incremental 1 1

  322. EOF


  323.     if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]

  324.         then

  325.         cat <<EOF

  326. CHART mysql_$x.binlog_stmt_cache '' "mysql Binlog Statement Cache" "statements/s" binlog mysql.binlog_stmt_cache line $((mysql_priority + 50)) $mysql_update_every

  327. DIMENSION Binlog_stmt_cache_disk_use disk incremental 1 1

  328. DIMENSION Binlog_stmt_cache_use all incremental 1 1

  329. EOF

  330.     fi


  331.     if [ ! -z "$mysql_Connection_errors_accept" ]

  332.         then

  333.         cat <<EOF

  334. CHART mysql_$x.connection_errors '' "mysql Connection Errors" "connections/s" connections mysql.connection_errors line $((mysql_priority + 51)) $mysql_update_every

  335. DIMENSION Connection_errors_accept accept incremental 1 1

  336. DIMENSION Connection_errors_internal internal incremental 1 1

  337. DIMENSION Connection_errors_max_connections max incremental 1 1

  338. DIMENSION Connection_errors_peer_addr peer_addr incremental 1 1

  339. DIMENSION Connection_errors_select select incremental 1 1

  340. DIMENSION Connection_errors_tcpwrap tcpwrap incremental 1 1

  341. EOF

  342.     fi


  343.     done

  344.     return 0

  345. }



  346. mysql_update() {

  347.     # the first argument to this function is the microseconds since last update

  348.     # pass this parameter to the BEGIN statement (see bellow).


  349.     # do all the work to collect / calculate the values

  350.     # for each dimension

  351.     # remember: KEEP IT SIMPLE AND SHORT


  352.     # 1. get the counters page from mysql

  353.     # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local mysql_

  354.     # 3. egrep lines starting with:

  355.     #    local mysql_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9

  356.     #    local mysql_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9

  357.     # 4. then execute this as a script with the eval

  358.     #

  359.     # be very carefull with eval:

  360.     # prepare the script and always grep at the end the lines that are usefull, so that

  361.     # even if something goes wrong, no other code can be executed


  362.     local m x

  363.     for m in "${!mysql_ids[@]}"

  364.     do

  365.         x="${mysql_ids[$m]}"


  366.         mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]}

  367.         if [ $? -ne 0 ]

  368.             then

  369.             unset mysql_ids[$m]

  370.             unset mysql_opts[$m]

  371.             unset mysql_cmds[$m]

  372.             echo >&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it."

  373.             continue

  374.         fi


  375.         # write the result of the work.

  376.         cat <<VALUESEOF

  377. BEGIN mysql_$x.net $1

  378. SET Bytes_received = $mysql_Bytes_received

  379. SET Bytes_sent = $mysql_Bytes_sent

  380. END

  381. BEGIN mysql_$x.queries $1

  382. SET Queries = $mysql_Queries

  383. SET Questions = $mysql_Questions

  384. SET Slow_queries = $mysql_Slow_queries

  385. END

  386. BEGIN mysql_$x.handlers $1

  387. SET Handler_commit = $mysql_Handler_commit

  388. SET Handler_delete = $mysql_Handler_delete

  389. SET Handler_prepare = $mysql_Handler_prepare

  390. SET Handler_read_first = $mysql_Handler_read_first

  391. SET Handler_read_key = $mysql_Handler_read_key

  392. SET Handler_read_next = $mysql_Handler_read_next

  393. SET Handler_read_prev = $mysql_Handler_read_prev

  394. SET Handler_read_rnd = $mysql_Handler_read_rnd

  395. SET Handler_read_rnd_next = $mysql_Handler_read_rnd_next

  396. SET Handler_rollback = $mysql_Handler_rollback

  397. SET Handler_savepoint = $mysql_Handler_savepoint

  398. SET Handler_savepoint_rollback = $mysql_Handler_savepoint_rollback

  399. SET Handler_update = $mysql_Handler_update

  400. SET Handler_write = $mysql_Handler_write

  401. END

  402. BEGIN mysql_$x.table_locks $1

  403. SET Table_locks_immediate = $mysql_Table_locks_immediate

  404. SET Table_locks_waited = $mysql_Table_locks_waited

  405. END

  406. BEGIN mysql_$x.join_issues $1

  407. SET Select_full_join = $mysql_Select_full_join

  408. SET Select_full_range_join = $mysql_Select_full_range_join

  409. SET Select_range = $mysql_Select_range

  410. SET Select_range_check = $mysql_Select_range_check

  411. SET Select_scan = $mysql_Select_scan

  412. END

  413. BEGIN mysql_$x.sort_issues $1

  414. SET Sort_merge_passes = $mysql_Sort_merge_passes

  415. SET Sort_range = $mysql_Sort_range

  416. SET Sort_scan = $mysql_Sort_scan

  417. END

  418. BEGIN mysql_$x.tmp $1

  419. SET Created_tmp_disk_tables = $mysql_Created_tmp_disk_tables

  420. SET Created_tmp_files = $mysql_Created_tmp_files

  421. SET Created_tmp_tables = $mysql_Created_tmp_tables

  422. END

  423. BEGIN mysql_$x.connections $1

  424. SET Connections = $mysql_Connections

  425. SET Aborted_connects = $mysql_Aborted_connects

  426. END

  427. BEGIN mysql_$x.binlog_cache $1

  428. SET Binlog_cache_disk_use = $mysql_Binlog_cache_disk_use

  429. SET Binlog_cache_use = $mysql_Binlog_cache_use

  430. END

  431. BEGIN mysql_$x.threads $1

  432. SET Threads_connected = $mysql_Threads_connected

  433. SET Threads_created = $mysql_Threads_created

  434. SET Threads_cached = $mysql_Threads_cached

  435. SET Threads_running = $mysql_Threads_running

  436. END

  437. BEGIN mysql_$x.thread_cache_misses $1

  438. SET misses = $mysql_Thread_cache_misses

  439. END

  440. BEGIN mysql_$x.innodb_io $1

  441. SET Innodb_data_read = $mysql_Innodb_data_read

  442. SET Innodb_data_written = $mysql_Innodb_data_written

  443. END

  444. BEGIN mysql_$x.innodb_io_ops $1

  445. SET Innodb_data_reads = $mysql_Innodb_data_reads

  446. SET Innodb_data_writes = $mysql_Innodb_data_writes

  447. SET Innodb_data_fsyncs = $mysql_Innodb_data_fsyncs

  448. END

  449. BEGIN mysql_$x.innodb_io_pending_ops $1

  450. SET Innodb_data_pending_reads = $mysql_Innodb_data_pending_reads

  451. SET Innodb_data_pending_writes = $mysql_Innodb_data_pending_writes

  452. SET Innodb_data_pending_fsyncs = $mysql_Innodb_data_pending_fsyncs

  453. END

  454. BEGIN mysql_$x.innodb_log $1

  455. SET Innodb_log_waits = $mysql_Innodb_log_waits

  456. SET Innodb_log_write_requests = $mysql_Innodb_log_write_requests

  457. SET Innodb_log_writes = $mysql_Innodb_log_writes

  458. END

  459. BEGIN mysql_$x.innodb_os_log $1

  460. SET Innodb_os_log_fsyncs = $mysql_Innodb_os_log_fsyncs

  461. SET Innodb_os_log_pending_fsyncs = $mysql_Innodb_os_log_pending_fsyncs

  462. SET Innodb_os_log_pending_writes = $mysql_Innodb_os_log_pending_writes

  463. END

  464. BEGIN mysql_$x.innodb_os_log_io $1

  465. SET Innodb_os_log_written = $mysql_Innodb_os_log_written

  466. END

  467. BEGIN mysql_$x.innodb_cur_row_lock $1

  468. SET Innodb_row_lock_current_waits = $mysql_Innodb_row_lock_current_waits

  469. END

  470. BEGIN mysql_$x.innodb_rows $1

  471. SET Innodb_rows_inserted = $mysql_Innodb_rows_inserted

  472. SET Innodb_rows_read = $mysql_Innodb_rows_read

  473. SET Innodb_rows_updated = $mysql_Innodb_rows_updated

  474. SET Innodb_rows_deleted = $mysql_Innodb_rows_deleted

  475. END

  476. BEGIN mysql_$x.innodb_buffer_pool_pages $1

  477. SET Innodb_buffer_pool_pages_data = $mysql_Innodb_buffer_pool_pages_data

  478. SET Innodb_buffer_pool_pages_dirty = $mysql_Innodb_buffer_pool_pages_dirty

  479. SET Innodb_buffer_pool_pages_free = $mysql_Innodb_buffer_pool_pages_free

  480. SET Innodb_buffer_pool_pages_flushed = $mysql_Innodb_buffer_pool_pages_flushed

  481. SET Innodb_buffer_pool_pages_misc = $mysql_Innodb_buffer_pool_pages_misc

  482. SET Innodb_buffer_pool_pages_total = $mysql_Innodb_buffer_pool_pages_total

  483. END

  484. BEGIN mysql_$x.innodb_buffer_pool_bytes $1

  485. SET Innodb_buffer_pool_bytes_data = $mysql_Innodb_buffer_pool_bytes_data

  486. SET Innodb_buffer_pool_bytes_dirty = $mysql_Innodb_buffer_pool_bytes_dirty

  487. END

  488. BEGIN mysql_$x.innodb_buffer_pool_read_ahead $1

  489. SET Innodb_buffer_pool_read_ahead = $mysql_Innodb_buffer_pool_read_ahead

  490. SET Innodb_buffer_pool_read_ahead_evicted = $mysql_Innodb_buffer_pool_read_ahead_evicted

  491. SET Innodb_buffer_pool_read_ahead_rnd = $mysql_Innodb_buffer_pool_read_ahead_rnd

  492. END

  493. BEGIN mysql_$x.innodb_buffer_pool_reqs $1

  494. SET Innodb_buffer_pool_read_requests = $mysql_Innodb_buffer_pool_read_requests

  495. SET Innodb_buffer_pool_write_requests = $mysql_Innodb_buffer_pool_write_requests

  496. END

  497. BEGIN mysql_$x.innodb_buffer_pool_ops $1

  498. SET Innodb_buffer_pool_reads = $mysql_Innodb_buffer_pool_reads

  499. SET Innodb_buffer_pool_wait_free = $mysql_Innodb_buffer_pool_wait_free

  500. END

  501. BEGIN mysql_$x.qcache_ops $1

  502. SET Qcache_hits hits = $mysql_Qcache_hits

  503. SET Qcache_lowmem_prunes = $mysql_Qcache_lowmem_prunes

  504. SET Qcache_inserts inserts = $mysql_Qcache_inserts inserts

  505. SET Qcache_not_cached = $mysql_Qcache_not_cached

  506. END

  507. BEGIN mysql_$x.qcache $1

  508. SET Qcache_queries_in_cache = $mysql_Qcache_queries_in_cache

  509. END

  510. BEGIN mysql_$x.qcache_freemem $1

  511. SET Qcache_free_memory = $mysql_Qcache_free_memory

  512. END

  513. BEGIN mysql_$x.qcache_memblocks $1

  514. SET Qcache_free_blocks = $mysql_Qcache_free_blocks

  515. SET Qcache_total_blocks = $mysql_Qcache_total_blocks

  516. END

  517. BEGIN mysql_$x.key_blocks $1

  518. SET Key_blocks_unused = $mysql_Key_blocks_unused

  519. SET Key_blocks_used = $mysql_Key_blocks_used

  520. SET Key_blocks_not_flushed = $mysql_Key_blocks_not_flushed

  521. END

  522. BEGIN mysql_$x.key_requests $1

  523. SET Key_read_requests = $mysql_Key_read_requests

  524. SET Key_write_requests = $mysql_Key_write_requests

  525. END

  526. BEGIN mysql_$x.key_disk_ops $1

  527. SET Key_reads = $mysql_Key_reads

  528. SET Key_writes = $mysql_Key_writes

  529. END

  530. BEGIN mysql_$x.files $1

  531. SET Open_files = $mysql_Open_files

  532. END

  533. BEGIN mysql_$x.files_rate $1

  534. SET Opened_files = $mysql_Opened_files

  535. END

  536. VALUESEOF


  537.         if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ]

  538.             then

  539.             cat <<VALUESEOF

  540. BEGIN mysql_$x.binlog_stmt_cache $1

  541. SET Binlog_stmt_cache_disk_use = $mysql_Binlog_stmt_cache_disk_use

  542. SET Binlog_stmt_cache_use = $mysql_Binlog_stmt_cache_use

  543. END

  544. VALUESEOF

  545.         fi


  546.         if [ ! -z "$mysql_Connection_errors_accept" ]

  547.             then

  548.             cat <<VALUESEOF

  549. BEGIN mysql_$x.connection_errors $1

  550. SET Connection_errors_accept = $mysql_Connection_errors_accept

  551. SET Connection_errors_internal = $mysql_Connection_errors_internal

  552. SET Connection_errors_max_connections = $mysql_Connection_errors_max_connections

  553. SET Connection_errors_peer_addr = $mysql_Connection_errors_peer_addr

  554. SET Connection_errors_select = $mysql_Connection_errors_select

  555. SET Connection_errors_tcpwrap = $mysql_Connection_errors_tcpwrap

  556. END

  557. VALUESEOF

  558.         fi

  559.     done


  560.     [ ${#mysql_ids[@]} -eq 0 ] && echo >&2 "$PROGRAM_NAME: mysql: no mysql servers left active." && return 1

  561.     return 0

  562. }






三:监控情况截图
Netdata Mysql运行情况监控插件怎么用

感谢各位的阅读!关于“Netdata Mysql运行情况监控插件怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI