zabbix mysql 监控
生活随笔
收集整理的這篇文章主要介紹了
zabbix mysql 监控
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建監控用戶(權限usage):
mysql> grant usage on *.* to zabbix@127.0.0.1 identified by 'zabbix@123'; mysql> flush privileges;監控腳本:
# cat /etc/zabbix/alertscripts/mysql_status.sh #!/bin/bash #Desc:zabbix 監控 MySQL 狀態 #Date:2021-3-1#主機 HOST="127.0.0.1" #用戶 USER="zabbix" #密碼 PASSWORD="zabbix@123" #端口 PORT="22809" #MySQL連接 CONNECTION="/usr/local/mysql/bin/mysqladmin -h ${HOST} -u ${USER} -P ${PORT} -p${PASSWORD}"if [ $# -ne "1" ];thenecho "arg error!" ficase $1 inUptime)result=`${CONNECTION} status 2>/dev/null |awk '{print $2}'`echo $result;;Questions)result=`${CONNECTION} status 2>/dev/null |awk '{print $6}'`echo $result;;Com_update)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_update" |awk '{print $4}'`echo $result;;Slow_queries)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Slow_queries" |awk '{print $4}'`echo $result;;Com_select)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_select" |awk '{print $4}'`echo $result;;Com_rollback)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_rollback" |awk '{print $4}'`echo $result;;Com_insert)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_insert" |awk '{print $4}'`echo $result;;Com_delete)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_delete" |awk '{print $4}'`echo $result;;Com_commit)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_commit" |awk '{print $4}'`echo $result;;Bytes_sent)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_sent" |awk '{print $4}'`echo $result;;Bytes_received)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_received" |awk '{print $4}'`echo $result;;Com_begin)result=`${CONNECTION} extended-status 2>/dev/null |grep -w "Com_begin" |awk '{print $4}'`echo $result;;*)echo "Usage:$0(Uptime|Questions|Com_update|Slow_queries|Com_select|Com_rollback|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)";; esaczabbix配置
#mysql監控 UserParameter=mysql.status[*],/etc/zabbix/alertscripts/mysql_status.sh $1#獲取MySQL運行狀態(與腳本無關,可以自信忽略) UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -u zabbix -h"127.0.0.1" -P22809 -p"zabbix@123" ping 2>/dev/null | grep -c alivezabbix模板:
# zbx_export_templates.xml<?xml version="1.0" encoding="UTF-8"?> <zabbix_export><version>5.0</version><date>2021-11-11T08:35:01Z</date><groups><group><name>Templates/Databases</name></group></groups><templates><template><template>Template DB MySQL custom</template><name>Template DB MySQL custom</name><groups><group><name>Templates/Databases</name></group></groups><applications><application><name>MySQL</name></application></applications><items><item><name>MySQL status</name><key>mysql.ping</key><history>1w</history><description>It requires user parameter mysql.ping, which is defined in userparameter_mysql.conf. 0 - MySQL server is down 1 - MySQL server is up</description><applications><application><name>MySQL</name></application></applications><valuemap><name>Service state</name></valuemap><triggers><trigger><expression>{last(0)}=0</expression><name>MySQL is down</name><priority>WARNING</priority></trigger></triggers></item><item><name>MySQL bytes received per second</name><key>mysql.status[Bytes_received]</key><history>1w</history><value_type>FLOAT</value_type><units>Bps</units><description>The number of bytes received from all clients. It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL bytes sent per second</name><key>mysql.status[Bytes_sent]</key><history>1w</history><value_type>FLOAT</value_type><units>Bps</units><description>The number of bytes sent to all clients. It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL begin operations per second</name><key>mysql.status[Com_begin]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL commit operations per second</name><key>mysql.status[Com_commit]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL delete operations per second</name><key>mysql.status[Com_delete]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL insert operations per second</name><key>mysql.status[Com_insert]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL rollback operations per second</name><key>mysql.status[Com_rollback]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL select operations per second</name><key>mysql.status[Com_select]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL update operations per second</name><key>mysql.status[Com_update]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL queries per second</name><key>mysql.status[Questions]</key><history>1w</history><value_type>FLOAT</value_type><units>qps</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications><preprocessing><step><type>CHANGE_PER_SECOND</type><params/></step></preprocessing></item><item><name>MySQL slow queries</name><key>mysql.status[Slow_queries]</key><history>1w</history><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications></item><item><name>MySQL uptime</name><key>mysql.status[Uptime]</key><history>1w</history><units>uptime</units><description>It requires user parameter mysql.status[*], which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications></item><item><name>MySQL version</name><key>mysql.version</key><delay>1h</delay><history>1w</history><trends>0</trends><value_type>CHAR</value_type><description>It requires user parameter mysql.version, which is defined in userparameter_mysql.conf.</description><applications><application><name>MySQL</name></application></applications></item></items><screens><screen><name>MySQL performance</name><hsize>2</hsize><vsize>1</vsize><screen_items><screen_item><resourcetype>0</resourcetype><style>0</style><resource><name>MySQL operations</name><host>Template DB MySQL</host></resource><width>500</width><height>200</height><x>0</x><y>0</y><colspan>1</colspan><rowspan>1</rowspan><elements>0</elements><valign>1</valign><halign>0</halign><dynamic>0</dynamic><sort_triggers>0</sort_triggers><url/><application/><max_columns>3</max_columns></screen_item><screen_item><resourcetype>0</resourcetype><style>0</style><resource><name>MySQL bandwidth</name><host>Template DB MySQL</host></resource><width>500</width><height>270</height><x>1</x><y>0</y><colspan>1</colspan><rowspan>1</rowspan><elements>0</elements><valign>1</valign><halign>0</halign><dynamic>0</dynamic><sort_triggers>0</sort_triggers><url/><application/><max_columns>3</max_columns></screen_item></screen_items></screen></screens></template></templates><value_maps><value_map><name>Service state</name><mappings><mapping><value>0</value><newvalue>Down</newvalue></mapping><mapping><value>1</value><newvalue>Up</newvalue></mapping></mappings></value_map></value_maps> </zabbix_export>?
總結
以上是生活随笔為你收集整理的zabbix mysql 监控的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ZZULIOJ:1151: 大整数加法
- 下一篇: ue4描边