zabbix使用內建模板監控MySQL

來源:互聯網
上載者:User

標籤:zabbix

1、web頁面添加mysql模版

Configuration > Hosts > 選擇主機或添加新主機 > Tempaltes,搜尋MySQL,添加彈出的模板,然後更新

2、配置userparameter_mysql.conf

找出設定檔

[[email protected] ~]# find / -name userparameter_mysql.conf/usr/share/doc/zabbix22-agent-2.2.16/userparameter_mysql.conf

在/etc/zabbix建一個目錄放設定檔

[[email protected] ~]# mkdir /etc/zabbix/zabbix_agentd.d/

把設定檔拷貝到該目錄下

[[email protected] ~]#cp /usr/share/doc/zabbix22-agent-2.2.16/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

建立一個使用者來擷取mysql的相關資料

mysql>GRANT USAGE ON *.* TO ‘zabbix‘@‘localhost‘ IDENTIFIED BY ‘123‘;mysql>FLUSH PRIVILEGES;

添加用來關聯mysql的設定檔my.cnf

[[email protected] ~]# vim /etc/zabbix/.my.cnf [mysql]host = localhostuser = zabbixpassword = 123socket = /tmp/mysql.sock[mysqladmin]host = localhostuser = zabbixpassword = 123socket = /tmp/mysql.sock

修改userparameter_mysql.conf:HOME目錄為新增.my.cnf檔案所在目錄

[[email protected] ~]#sed -i ‘[email protected]/var/lib/[email protected]/etc/zabbix/@g‘ /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[[email protected] ~]# grep -v "^#" /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf UserParameter=mysql.status[*],echo "show global status where Variable_name=‘$1‘;" | HOME=/etc/zabbix mysql -N | awk ‘{print $$2}‘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 aliveUserParameter=mysql.version,mysql -V

修改zabbix_agentd.conf檔案,添加一行,為userparameter_mysql.conf所在目錄

[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.confInclude=/etc/zabbix/zabbix_agentd.conf.d/

重啟zabbix-agentd

[[email protected] ~]# service zabbix-agentd restartShutting down Zabbix agent:                                [  OK  ]Starting Zabbix agent:                                     [  OK  ]

測試

[[email protected] ~]#zabbix_get -s 192.168.1.102 -p 10050 -k mysql.ping1[[email protected] ~]# zabbix_get -s 192.168.1.102 -p 10050 -k mysql.versionmysql  Ver 14.14 Distrib 5.1.71, for redhat-linux-gnu (x86_64) using readline 5.1


zabbix使用內建模板監控MySQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.