zabbix獲取數據時有時會出現超時,如果一些數據需要執行比較長的時間才能獲取的話,那麼zabbix會出現異常,考慮到這種情況,zabbix增加了Trapper功能,客戶端自己提交數據給zabbix。
trapper是被監控主機主動發送數據給zabbix server,與主動模式的區別是不需要安裝客戶端;trapper方式發送數據是以主機名處理,不是IP地址,所以主機名要唯一。在配置監控項時候Type of information項要選擇text,否者會報not support錯誤.
tapper工作模式中,使用zabbix監控類型zabbix trapper(可以稱爲zabbix捕捉器),在zabbix服務器上必須有一個捕捉項目,然後需要配合zabbix_sender把數據推送給zabbix服務器,該程序由zabbix發行版自帶,源碼包解壓後在bin目錄下,配合crontab定期發送數據給zabbix server。
zabbix_sender是一個命令行工具,可以用來發送Zabbix服務器處理性能數據。該工具通常用於長時間運行的用戶腳本,用於定期發送可用性和性能數據。
zabbix_sender命令:
[root@Zabbix-Server ~]# cd /app/zabbix/bin/ [root@Zabbix-Server bin]# ./zabbix_sender usage: zabbix_sender [-Vhv] {[-zpsI] -ko | [-zpI] -T -i <file> -r} [-c <file>] 參數說明: -c --config <file> 配置文件絕對路徑 -z --zabbix-server <server> zabbix server的IP地址 -p --port <server port> zabbix server端口.默認10051 -s --host <hostname> 主機名,zabbix客戶端zabbix_agentd.conf配置文件中定義的 Hostname(不是服務器的hostname),不是客戶端主機的ip地址 -I --source-address <IP address> 源IP -k --key <key> 監控項的key -o --value <key value> key值 -i --input-file <input file> 從文件裏面讀取hostname、key、value 一行爲一條數據,使用空格作爲分隔符,如果主機名帶空格,那麼請使用雙引號包起來 -T --with-timestamps 一行一條數據,空格作爲分隔符: <hostname> <key> <timestamp> <value>,配合 --input-file option,timestamp爲unix時間戳 -r --real-time 將數據實時提交給服務器 -v --verbose 詳細模式, -vv 更詳細
監控項配置:
Configuration-Hosts-選擇(新建)一臺主機-items-Create item
客戶端使用zabbix_sender發送數據
客戶端
[root@localhost ~]# cd /usr/local/zabbix/bin/ [root@localhost bin]# ./zabbix_sender -s 10.15.98.98 -z 192.168.100.176 -k ityunwei2017 -o test Sending failed. Use option -vv for more detailed output. [root@localhost bin]# ./zabbix_sender -s 10.15.98.98 -z 192.168.100.176 -k ityunwei2017 -o test -vv zabbix_sender [1986]: DEBUG: send value error: cannot connect to [[192.168.100.176]:10051]: [111] Connection refused Sending failed. [root@localhost bin]#
-vv可以顯示具體信息,這裏提示到無法連接到zabbix server的10051端口
服務端:
[root@Zabbix-Server logs]# netstat -anop|grep -i zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 6938/zabbix_agentd off (0.00/0/0) tcp 0 0 127.0.0.1:10051 0.0.0.0:* LISTEN 15925/zabbix_server off (0.00/0/0) tcp 0 0 :::10050 :::* LISTEN 6938/zabbix_agentd off (0.00/0/0)
未開放外網的10051端口
[root@Zabbix-Server etc]# vim zabbix_server.conf ListenIP=127.0.0.1,192.168.100.176 [root@Zabbix-Server etc]# service zabbix_server restart [root@Zabbix-Server etc]# netstat -anop|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 6938/zabbix_agentd off (0.00/0/0) tcp 0 0 192.168.100.176:10051 0.0.0.0:* LISTEN 8892/zabbix_server off (0.00/0/0) tcp 0 0 127.0.0.1:10051 0.0.0.0:* LISTEN 8892/zabbix_server off (0.00/0/0)
客戶端
[root@localhost bin]# ./zabbix_sender -s 10.15.98.98 -z 192.168.100.176 -k ityunwei2017 -o test -vv zabbix_sender [2528]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000188"}] info from server: "processed: 1; failed: 0; total: 1; seconds spent: 0.000188" sent: 1; skipped: 0; total: 1 [root@localhost bin]#
這裏只是發送一個數據進行測試,實際環境中需要寫一個腳本或定時任務定期發送數據就可以了。
zabbix web端查看
Monitoring-Latest data
可以看到已經接收到客戶端sender過來的數據了,後面可以根據這些數據進行圖形配置並創建觸發器完成相關告警操作。
zabbix_sender批量傳遞key值
通過zabbix_sender可以批量傳遞key值,可以創建一個文本,每行定義一個key值,可以使用不同的主機名以及key、key值。
客戶端
[root@localhost bin]# cat a.txt 10.15.98.98 ityunwei2017 100 10.15.98.98 ityunwei2017 200 10.15.98.98 ityunwei2017 300 10.15.98.98 ityunwei2017 400 10.15.98.98 ityunwei2017 500 [root@localhost bin]# ./zabbix_sender -z 192.168.100.176 -i a.txt -vv zabbix_sender [3000]: DEBUG: answer [{"response":"success","info":"processed: 5; failed: 0; total: 5; seconds spent: 0.000247"}] info from server: "processed: 5; failed: 0; total: 5; seconds spent: 0.000247" sent: 5; skipped: 0; total: 5 [root@localhost bin]#
zabbix web端