ispsh 发表于 2019-1-19 12:27:27

zabbix企业级监控之监控数据库大小、表大小

  1.怎么去获取到数据库大小、表大小?
  information_schema数据库存储了关于数据库的信息
http://s1.运维网.com/images/20180731/1533007625411610.png
  使用information_schema数据库
MariaDB [(none)]> use information_schema ;  查询数据库总大小

MariaDB > select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;http://s1.运维网.com/images/20180731/1533007863984055.png
  查询指定数据库zabbix的大小
MariaDB > select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix';http://s1.运维网.com/images/20180731/1533007967132441.png
  查询指定数据库的指定表的大小(zabbix数据库的items表的大小)
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix' and table_name='items';http://s1.运维网.com/images/20180731/1533008175620086.png
  2.如何通过shell 脚本去获取?
  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定义模板

vim userparameter_my.confUserParameter=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.如果查看运维网不方便,文章也会推送到微信公众号
http://s1.运维网.com/images/20180731/1533009804136696.jpg



页: [1]
查看完整版本: zabbix企业级监控之监控数据库大小、表大小