vim /etc/zabbix/zabbix_agentd.d/mystat.conf
UserParameter=mystat[*],/server/scripts/chk_mysql.sh '$1' # 鍵值是mystat[]
[root@zabbix ~]# zabbix_get -s 172.16.1.51 -k mystat[Uptime]
496
[root@db01 log]# cat /server/scripts/chk_mysql.sh
1 #!/bin/bash 2 # ------------------------------------------------------------------------------- 3 # FileName: check_mysql.sh 4 # Revision: 1.0 5 # Date: 2018/01/31 6 # Author: chunk 7 # Email: 8 # Website: 9 # Description: 10 # Notes: ~ 11 # ------------------------------------------------------------------------------- 12 # Copyright: 13 # License: GPL 14 15 # 用戶名 16 MYSQL_USER='root' 17 18 # 密碼 19 MYSQL_PWD='oldboy123' 20 21 # 主機地址/IP 22 MYSQL_HOST='10.0.0.51' 23 24 # 端口 25 MYSQL_PORT='3306' 26 27 # 數據鏈接 28 MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}" 29 30 # 參數是否正確 31 if [ $# -ne "1" ];then 32 echo "arg error!" 33 fi 34 35 # 獲取數據 36 case $1 in 37 Uptime) 38 result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` 39 echo $result 40 ;; 41 Com_update) 42 result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` 43 echo $result 44 ;; 45 Slow_queries) 46 result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` 47 echo $result 48 ;; 49 Com_select) 50 result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` 51 echo $result 52 ;; 53 Com_rollback) 54 result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` 55 echo $result 56 ;; 57 Questions) 58 result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` 59 echo $result 60 ;; 61 Com_insert) 62 result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` 63 echo $result 64 ;; 65 Com_delete) 66 result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` 67 echo $result 68 ;; 69 Com_commit) 70 result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` 71 echo $result 72 ;; 73 Bytes_sent) 74 result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` 75 echo $result 76 ;; 77 Bytes_received) 78 result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` 79 echo $result 80 ;; 81 Com_begin) 82 result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3` 83 echo $result 84 ;; 85 86 *) 87 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)" 88 ;; 89 esac
建立1個監控項以後就點擊克隆修更名稱和鍵值mysql
1,方法:一:映射值:nginx
0就是down 1就是upweb
2 ,方法 不用值映射sql
前提,要改客戶端2個配置文件數據庫
zabbix-agent配置文件中開啓遠程命令vim
EnableRemoteCommands=1
visudo 中添加zabbix用戶免密bash
以前測試這樣寫成功啓動myslq ,啓動nginx就失敗不知道怎麼回事ide
visudo
## Same thing without a password
#%wheel ALL=(ALL) NOPASSWD: ALL zabbix ALL=(ALL) NOPASSWD: ALL
中止nginx,沒有遠程執行命令測試
[root@web01 ~]# systemctl stop nginx
查看日誌ui
Jan 12 04:03:42 web01 sudo: pam_unix(sudo:auth): conversation failed Jan 12 04:03:42 web01 sudo: pam_unix(sudo:auth): auth could not identify password for [zabbix] Jan 12 04:03:42 web01 sudo: pam_succeed_if(sudo:auth): requirement "uid >= 1000" not met by user "zabbix"
後來改了visudo文件
[root@web01 ~]# visudo ## Same thing without a password #%wheel ALL=(ALL) NOPASSWD: ALL zabbix ALL=NOPASSWD: ALL
查看日誌,遠程支持命令成功
[root@web01 ~]# tail -f /var/log/secure
ticationAgent, locale en_US.UTF-8) (disconnected from bus)Jan 12 15:04:26 web01 sudo: zabbix : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/systemctl restart nginx.service