zoukankan      html  css  js  c++  java
  • zabbix自定义监控mysql

    创建用户:
    use mysql;
    grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbixpasswd';
    grant all privileges on *.* to 'zabbix'@'localhost' identified by 'zabbixpasswd';
    flush privileges;
     
     
    修改 /etc/zabbix/zabbix_agentd.conf
    Include=/etc/zabbix/zabbix_agentd.d/*.conf
     
     
    vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
    UserParameter=mysql.alive,/usr/local/mysql/bin/mysqladmin ping 2>/dev/null |grep -c "alive" 
    UserParameter=mysql.processlist_count,/usr/local/mysql/bin/mysql -e "select count(*) from information_schema.processlist where command !='Sleep' " |grep -v "count"
    UserParameter=mysql.Slave_IO_Running,/usr/local/mysql/bin/mysql -e "show slave statusG"|grep Slave_IO_Running|grep -c "Yes"
    UserParameter=mysql.Slave_SQL_Running,/usr/local/mysql/bin/mysql -e "show slave statusG"|grep Slave_SQL_Running|grep -c "Yes"
    UserParameter=mysql.Seconds_Behind_Master,/usr/local/mysql/bin/mysql -e "show slave statusG"|grep Seconds_Behind_Master |awk '{print $2}'
    UserParameter=mysql.innodb_lock,/usr/local/mysql/bin/mysql -e "SELECT count(*) FROM information_schema.INNODB_LOCK_WAITS w INNER JOIN information_schema.INNODB_TRX b ON b.trx_id= w.blocking_trx_id INNER JOIN information_schema.INNODB_TRX r ON r.trx_id= w.requesting_trx_id "|grep -v "count" 
     
     
     
     
    手工添加监控项和触发器。
    监控项的键值就是 userparameter_mysql.conf 文件中 等号右边第一个值,比如 mysql.processlist_count 
     
    添加触发器时,添加的表达式就是来自上述添加的监控项。
    注意N值来源,先运行一下监控项的返回值,比如 mysql -e "select count(*) from information_schema.processlist where command !='Sleep' " |grep -v "count" 
     
     
    添加触发器时,添加的表达式就是来自上述添加的监控项。
     
    注意N值来源,先运行一下监控项的返回值,比如 mysqladmin extended-status|grep Threads_connected |awk '{print $4}' 
    关于触发器的设置,可参考官方文档:https://www.zabbix.com/documentation/3.4/zh/manual/config/triggers
     
    修改 /etc/my.cnf
     
    user=zabbix
    password=zabbixpasswd
    [client]
    user=zabbix
    password=zabbixpasswd
    [mysqladmin]
    user=zabbix
    password=zabbixpasswd
     
     
    重启 agent
    systemctl restart zabbix-agent
     
     
    验证
    zabbix_get -s 192.168.16.16 -k "mysql.processlist_count"
     
     
     
  • 相关阅读:
    nodejs中处理回调函数的异常
    Web前端开发十日谈
    Android 高仿微信6.0主界面 带你玩转切换图标变色
    Android EventBus源码解析 带你深入理解EventBus
    Android EventBus实战 没听过你就out了
    究竟谁在绑架中国的4G政策?
    Android 实战美女拼图游戏 你能坚持到第几关
    oracle学习
    his使用-重置密码
    oracle中的DDL、DML、DCL
  • 原文地址:https://www.cnblogs.com/l10n/p/9405382.html
Copyright © 2011-2022 走看看