1.怎麼去獲取到數據庫大小、表大小?mysql
information_schema數據庫存儲了關於數據庫的信息web
使用information_schema數據庫sql
MariaDB [(none)]> use information_schema ;
查詢數據庫總大小
shell
MariaDB [information_schema]> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
查詢指定數據庫zabbix的大小數據庫
MariaDB [information_schema]> select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix';
查詢指定數據庫的指定表的大小(zabbix數據庫的items表的大小)vim
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix' and table_name='items';
2.如何經過shell 腳本去獲取?bash
vim /etc/zabbix/shell/monitor_mysql.sh微信
#!/bin/bash DB_size() { mysql -Dinformation_schema -e "select concat(round(sum(data_length/1024/1024),2)) as data from tables" |awk 'NR==2{print $1}' } DB_zabbix_size() { mysql -Dinformation_schema -e "select concat(round(sum(data_length/1024/1024),2)) as data from tables where table_schema='zabbix'" | \ awk 'NR==2{print $1}' } $1
3.agent定義模板
app
vim userparameter_my.conf
UserParameter=monitor_mysql[*],/bin/bash /etc/zabbix/shell/monitor_mysql.sh "$1"
參數解釋:
運維
monitor_mysql[*]:是自定義key,*是傳參 是從server端自定義鍵值的時候傳參傳下來的
4.server端自定義鍵值,請參考第二篇,監控QPS和TPS的那篇
5.準備更新一個關於zabbix監控的專題,歡迎加入咱們的Linux技術交流羣:642921645,zabbix監控交流羣:832462735 ,咱們不按期去更新不少關於系統運維的資料在羣裏,期待你的加入!
6.在騰訊課堂有zabbix監控的免費技術分享,歡迎來聽!地址以下:https://ke.qq.com/course/316681?tuin=6645db32
7.若是查看51cto不方便,文章也會推送到微信公衆號