Zabbix Series zabbix3.4 Monitoring mysql5.7

Source: Internet
Author: User
Tags python script

Would like to use a Python script to monitor MySQL, did not find relevant information, lazy toss, using the official self-monitoring template to monitor MySQL

Add a zabbix-agent configuration file

Replace the default userparameter_mysql.conf file with the content
[email protected] zabbix_agentd.d]# cat userparameter_mysql.conf

#UserParameter=mysql.status[*],echo "show global status where Variable_name=‘$1‘;" | HOME=/var/lib/zabbix mysql -N | awk ‘{print $$2}‘UserParameter=mysql.status[*],/etc/zabbix/script/mysql/chk_mysql.sh $1#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=/var/lib/zabbix mysql -N‘#UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c aliveUserParameter=mysql.ping,mysqladmin -u root -pRoo -P3306 -h192.168.2.252  ping | grep -c aliveUserParameter=mysql.version,mysql -V
Add chk_mysql.sh script File

/etc/zabbix/script/mysql/chk_mysql.sh

#!/bin/bash#-------------------------------------------------------------------------------# Filename:check_ mysql.sh# revision:1.0# date:2018/01/31# author:chunk# Email: # Website: # Description: # Note S: ~#-------------------------------------------------------------------------------# Copyright: # license:g pl# username mysql_user= ' root ' # password mysql_pwd= ' root ' # host address/ipmysql_host= ' 192.168.2.252 ' # port mysql_port= ' 3306 ' # data connection Mysql_     Conn= "/usr/bin/mysqladmin-u${mysql_user}-p${mysql_pwd}-h${mysql_host}-p${mysql_port}" # parameter is correct if [$#-ne "1"];then         echo "arg error!" FI # Get Data case $ in Uptime) result= ' ${mysql_conn} status|cut-f2-d ":" |cut-f1-d "T" '     echo $result;;         com_update) result= ' ${mysql_conn} extended-status |grep-w "Com_update" |cut-d "|"-f3 ' echo $result     ;;     slow_queries) result= ' ${mysql_conn} status |cut-f5-d ":" |cut-f1-d "O" ' echo $result;; Com_selECT) result= ' ${mysql_conn} extended-status |grep-w "Com_select" |cut-d "|"-f3 ' echo $result     ;; Com_rollback) result= ' ${mysql_conn} extended-status |grep-w "Com_rollback" |cut-d "|"-f3 ' echo $r     Esult;;                 Questions) result= ' ${mysql_conn} status|cut-f4-d ":" |cut-f1-d "S" ' Echo $result     ;; Com_insert) result= ' ${mysql_conn} extended-status |grep-w "Com_insert" |cut-d "|"-f3 ' echo $resul     t;; Com_delete) result= ' ${mysql_conn} extended-status |grep-w "Com_delete" |cut-d "|"-f3 ' echo $resul     t;; Com_commit) result= ' ${mysql_conn} extended-status |grep-w "Com_commit" |cut-d "|"-f3 ' echo $resul     t;; bytes_sent) result= ' ${mysql_conn} extended-status |grep-w "bytes_sent" |cut-d "|"-f3 ' echo $resu    lt;; bytes_received) result= ' ${mysql_conn} extended-status |grep-w "bytes_received" |cut-d "|"-f3 ' E     Cho $result;;                 Com_begin) result= ' ${mysql_conn} extended-status |grep-w "Com_begin" |cut-d "|"-f3 ' echo $result         ;; *) echo "usage:$0 (uptime| com_update| slow_queries| Com_select| com_rollback| questions| Com_insert| com_delete| Com_commit| Bytes_sent| bytes_received| Com_begin) ";; Esac
Add a template link to a zabbix-web-side host

Restart the monitoring side agent
service zabbix-agent restart


Zabbix Series zabbix3.4 Monitoring mysql5.7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.