ZABBIX4.0 添加mysql監控

環境簡介:

zabbix 服務器IP:192.168.101.1

mysql 服務器IP:192.168.101.2 (agent端)

前提條件:是192.168.102已經安裝zabbix_agent

1.創建監控所需mysql賬戶(agent端):
grant usage on *.* to [email protected] identified by '123456';
flush privileges;

 
2.agent端:創建.my.cnf並檢查zabbix賬號是否能正常連接數據庫
/etc/zabbix/下創建一個包含MySQL用戶名和密碼的配置文件“.my.cnf”

[client]
user=zabbix
host=127.0.0.1
password=123456

有了這個文件後,檢查zabbix賬號是否能正常連接數據庫:
HOME=/etc/zabbix/ mysqladmin ping | grep -c alive

我這裏是把已經改好的模板直接放到/etc/zabbix/zabbix_agentd.conf.d/ 目錄下 ,注意HOME=路徑的配置 配置完後續重啓zabbix-agent:
kill -9 XXX
/usr/sbin/zabbix_agentd

3.zabbix服務端驗證zabbix代理服務端是否正常返回數據

同時,在Server端也可以使用使用zabbix_get命令來測試從Server端獲取指定的Client端的數據,如下:

[root@Zabbixserver alertscripts]# zabbix_get -s172.18.200.61 -p 10050 -k mysql.ping

如果返回數據,證明zabbix服務端可獲取客戶端信息!

4.頁面對主機添加監控模板

至此,可看到監控數據!添加mysql監控成功!

監控腳本:

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/etc/zabbix mysql -N'

UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章