您的位置:首页 > 数据库 > SQL

开源监控解决方案:zabbix 监控mysql database(Golang)

2018-10-24 10:03 741 查看
[root@amb01 ~]# tar zxvf binutils-2.27.tar.gz
[root@amb01 ~]# cd binutils-2.27
[root@amb01 binutils-2.27]# make
[root@amb01 binutils-2.27]# make install

[root@amb01 ~]# tar -zxvf go1.4-bootstrap-20171003.tar.gz
[root@amb01 ~]# cd go/src
[root@amb01 src]# ./make.bash
[root@amb01 ~]# mv ~/go ~/go1.4
[root@amb01 ~]# export GOROOT_BOOTSTRAP=~/go1.4

[root@amb01 ~]# tar zxvf go-go1.10.3.tar.gz
[root@amb01 ~]# cd go-go1.10.3/src
[root@amb01 src]# ./all.bash
[root@amb01 ~]# mv ~/go-go1.10.3 /usr/local/go

[root@amb01 ~]# mkdir /home/go

[root@amb01 ~]# vi /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/home/go

[root@amb01 ~]# go version
go version go1.10.3 linux/amd64

https://github.com/go-sql-driver/mysql
[root@amb01 ~]# unzip mysql-master.zip 
[root@amb01 ~]# mkdir -p /home/go/src/github.com/go-sql-driver/mysql
[root@amb01 ~]# cp mysql-master/* /home/go/src/github.com/go-sql-driver/mysql/

https://github.com/actiontech/actiontech_zabbix_mysql_monitor
[root@amb01 ~]# unzip actiontech_zabbix_mysql_monitor-master.zip
[root@amb01 ~]# cd actiontech_zabbix_mysql_monitor-master
[root@amb01 actiontech_zabbix_mysql_monitor-master]# chmod a+x *.sh
[root@amb01 actiontech_zabbix_mysql_monitor-master]# ./build.sh 
[root@amb01 actiontech_zabbix_mysql_monitor-master]# ./actiontech_mysql_monitor --help  
Usage of ./actiontech_mysql_monitor:
  -cache_dir path
        A path for saving cache. if change, make sure change the wrapper.sh file too. (default "/tmp")
  -debug_log debuglog
        If debuglog is a filename, it'll be used. (default: no default)
  -discovery_port discovery mysqld port
        discovery mysqld port, print in json format (default: false)
  -get_qrt_mysql
        Whether to get response times from MySQL (default: false)
  -get_qrt_percona
        Whether to get response times from Percona Server or MariaDB (default true)
  -heartbeat
        Whether to use pt-heartbeat table for repl. delay calculation. (default: false)
  -heartbeat_server_id Server id
        Server id to associate with a heartbeat. Leave 0 if no preference. (default: 0)
  -heartbeat_table db.tbl
        db.tbl. (default "percona.heartbeat")
  -heartbeat_utc
        Whether pt-heartbeat is run with --utc option. (default: false)
  -host MySQL host
        MySQL host (default "127.0.0.1")
  -innodb
        Whether to check InnoDB statistics (default true)
  -items item
        -items <item,...> Comma-separated list of the items whose data you want (default: no default)
  -master
        Whether to check binary logging (default true)
  -nocache
        Do not cache results in a file (default: false)
  -pass MySQL password
        MySQL password (default: no default)
  -poll_time polling interval
        Adjust to match your polling interval.if change, make sure change the wrapper.sh file too. (default 30)
  -port MySQL port
        MySQL port (default "3306")
  -procs
        Whether to check SHOW PROCESSLIST (default true)
  -slave
        Whether to check slave status (default true)
  -sudo sudo netstat...
        Use sudo netstat... (default true)
  -user MySQL username
        MySQL username (default: no default)
  -version
        print version
        
        
[root@amb01 actiontech_zabbix_mysql_monitor-master]# mkdir /var/lib/zabbix/actiontech/scripts/
[root@amb01 actiontech_zabbix_mysql_monitor-master]# cp actiontech_mysql_monitor /var/lib/zabbix/actiontech/scripts/
[root@amb01 actiontech_zabbix_mysql_monitor-master]# cp userparameter_actiontech_mysql.conf /usr/local/etc/zabbix_agentd.conf.d/

[root@amb01 ~]# cd /var/lib/zabbix/actiontech/scripts
[root@amb01 scripts]# vi mysql.sh 
#!/bin/bash
sudo /var/lib/zabbix/actiontech/scripts/actiontech_mysql_monitor --host=localhost --port=$1 --user=zabbix --pass=zabbix --items=$2 | awk '{print $3}'

[root@amb01 scripts]# chmod a+x mysql.sh 
[root@amb01 scripts]# ./mysql.sh 3306 Aborted_clients
46

[root@amb01 ~]# vim /etc/sudoers
Defaults:zabbix !requiretty
zabbix          ALL=(ALL) NOPASSWD: ALL

[root@amb01 ~]# su - zabbix
[zabbix@amb01 ~]$ cd /var/lib/zabbix/actiontech/scripts
[zabbix@amb01 scripts]$ ./mysql.sh 3306 Aborted_clients
46

[root@amb01 ~]# cd /usr/local/etc/zabbix_agentd.conf.d
[root@amb01 zabbix_agentd.conf.d]# vi userparameter_actiontech_mysql.conf 
UserParameter=MySQL.[*],/var/lib/zabbix/actiontech/scripts/mysql.sh $1 $2
UserParameter=MySQL.port_discovery,/var/lib/zabbix/scripts/actiontech_mysql_monitor --discovery_port true

[root@amb01 ~]# vi /usr/local/etc/zabbix_agentd.conf
Server=192.168.40.35
Hostname=amb01
Include=/usr/local/etc/zabbix_agentd.conf.d/userparameter_actiontech_mysql.conf
[root@amb01 ~]# /etc/init.d/zabbix_agentd restart

[root@zabbix ~]# zabbix_get -s 192.168.40.34 -k MySQL.[3306,Aborted_clients] 
46

Zabbix Server
一,导入模板
二,创建主机并关联模板
三,大功告成


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  zabbix mysql golang