普拉多VX

人生一路,不问来时,不知归期

0%

zabbix sender和get使用方法

zabbix_sender

zabbix_sender 是用于将监视数据发送到Zabbix服务器或代理的命令行实用程序。也就是说可以在客户端主动上报数据给zabbix服务器,前提需要配置具体的监控项(items)。

zabbix_sender安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]# yum install zabbix-sender -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* centos-sclo-rh: mirrors.huaweicloud.com
* centos-sclo-sclo: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package zabbix-sender.x86_64 0:5.0.3-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================
Installing:
zabbix-sender x86_64 5.0.3-1.el7 zabbix 348 k

Transaction Summary
=====================================================================================================================================================================
Install 1 Package

Total download size: 348 k
Installed size: 1.5 M
Downloading packages:
zabbix-sender-5.0.3-1.el7.x86_64.rpm | 348 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zabbix-sender-5.0.3-1.el7.x86_64 1/1
Verifying : zabbix-sender-5.0.3-1.el7.x86_64 1/1

Installed:
zabbix-sender.x86_64 0:5.0.3-1.el7

Complete!
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]#

用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Example(s):
zabbix_sender -z 127.0.0.1 -s "Linux DB3" -k db.connections -o 43

zabbix_sender -z 127.0.0.1 -s "Linux DB3" -k db.connections -o 43 \
--tls-connect cert --tls-ca-file /home/zabbix/zabbix_ca_file \
--tls-server-cert-issuer \
"CN=Signing CA,OU=IT operations,O=Example Corp,DC=example,DC=com" \
--tls-server-cert-subject \
"CN=Zabbix proxy,OU=IT operations,O=Example Corp,DC=example,DC=com" \
--tls-cert-file /home/zabbix/zabbix_agentd.crt \
--tls-key-file /home/zabbix/zabbix_agentd.key

zabbix_sender -z 127.0.0.1 -s "Linux DB3" -k db.connections -o 43 \
--tls-connect psk --tls-psk-identity "PSK ID Zabbix agentd" \
--tls-psk-file /home/zabbix/zabbix_agentd.psk

常见参数说明,具体参考文档:https://www.zabbix.com/documentation/current/manpages/zabbix_sender?s[]=sender

1
2
3
4
5
6
7
8
-z 	指定zabbix server ip
-s 指定zabbix 客户端配置文件中的hostname
-k 指监控项对应的key值
-o 则表示要主动推送的数据
-r 将数据实时提交给服务器
-v 详细模式, -vv 更详细
-p zabbix server端口,默认10051
-i 从输入文件读取数据

参考实例

上报游戏客户端连接数量给zabbix服务端

1.创建一个模版

2.创建监控项

3.关联模版

4.发送测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@iZ2zecgq3cou36re3sxh4bZ ~]# zabbix_sender -s "webserver.roddypy.com" -z 47.93.184.140 -p 10051 -k "UsersCount" -o 1 -vv
zabbix_sender [21938]: DEBUG: answer [{"response":"success","info":"processed: 0; failed: 1; total: 1; seconds spent: 0.000071"}]
Response from "47.93.184.140:10051": "processed: 0; failed: 1; total: 1; seconds spent: 0.000071"
sent: 1; skipped: 0; total: 1

[root@iZ2zecgq3cou36re3sxh4bZ ~]# zabbix_sender -s "webserver.roddypy.com" -z 47.93.184.140 -p 10051 -k "UsersCount" -o 1 -vv
zabbix_sender [21940]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000087"}]
Response from "47.93.184.140:10051": "processed: 1; failed: 0; total: 1; seconds spent: 0.000087"
sent: 1; skipped: 0; total: 1

[root@iZ2zecgq3cou36re3sxh4bZ ~]# zabbix_sender -s "webserver.roddypy.com" -z 47.93.184.140 -p 10051 -k "UsersCount" -o 500 -vv
zabbix_sender [21946]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000092"}]
Response from "47.93.184.140:10051": "processed: 1; failed: 0; total: 1; seconds spent: 0.000092"
sent: 1; skipped: 0; total: 1

[root@iZ2zecgq3cou36re3sxh4bZ ~]# zabbix_sender -s "webserver.roddypy.com" -z 47.93.184.140 -p 10051 -k "UsersCount" -o 501 -vv
zabbix_sender [21951]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000029"}]
Response from "47.93.184.140:10051": "processed: 1; failed: 0; total: 1; seconds spent: 0.000029"
sent: 1; skipped: 0; total: 1

[root@iZ2zecgq3cou36re3sxh4bZ ~]# zabbix_sender -s "webserver.roddypy.com" -z 47.93.184.140 -p 10051 -k "UsersCount" -o 505 -vv
zabbix_sender [21953]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000091"}]
Response from "47.93.184.140:10051": "processed: 1; failed: 0; total: 1; seconds spent: 0.000091"
sent: 1; skipped: 0; total: 1
[root@iZ2zecgq3cou36re3sxh4bZ ~]#

4.通过最新数据获取结果

说明

  • 此时可以把命令写成脚本文件定时执行
  • 可以添加一个触发器进行报警

zabbix_get

zabbix_get 是用于从Zabbix代理获取数据的命令行实用程序。 就是从服务端获取客户端的数据,主要用于测试两边连通行和监控项是否正确。

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]# yum install zabbix-get -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* centos-sclo-rh: mirror.bit.edu.cn
* centos-sclo-sclo: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package zabbix-get.x86_64 0:5.0.3-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================================================
Installing:
zabbix-get x86_64 5.0.3-1.el7 zabbix 315 k

Transaction Summary
=====================================================================================================================================================================
Install 1 Package

Total download size: 315 k
Installed size: 1.3 M
Downloading packages:
zabbix-get-5.0.3-1.el7.x86_64.rpm | 315 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zabbix-get-5.0.3-1.el7.x86_64 1/1
Verifying : zabbix-get-5.0.3-1.el7.x86_64 1/1

Installed:
zabbix-get.x86_64 0:5.0.3-1.el7

Complete!
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]#

用法

1
2
Example(s):
zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"
1
2
3
4
5
6
7
General options:
-s --host host-name-or-IP 指定客户端主机名或者IP
-p --port port-number 客户端端口,默认10050
-I --source-address IP-address 指定源IP,写上zabbix server的ip地址即可,一般留空
-k --key item-key 你想获取的key
-h --help 打印帮助信息
-V --version 显示版本

官方文档:https://www.zabbix.com/documentation/current/manpages/zabbix_get

参考实例

1.获取客户端CPU负载

1
2
3
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]# zabbix_get -s 59.110.115.72 -p 10050 -k "system.cpu.load[all,avg5]"
0.020000
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]#

2.创建一个自定义监控,并通过zabbix_get获取数据

在客户端的zabbix_agentd.conf中增加自定义监控项

1
2
3
4
5
6
7
8
### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
UserParameter=Echo[*],echo $1

重启客户端

1
2
[root@iZ2zecgq3cou36re3sxh4bZ ~]# systemctl  restart zabbix-agent 
[root@iZ2zecgq3cou36re3sxh4bZ ~]#

在服务端测试,输入什么参数就会回显什么

1
2
3
4
5
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]# zabbix_get -s 59.110.115.72 -p 10050 -k "Echo[c]"                  
c
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]# zabbix_get -s 59.110.115.72 -p 10050 -k "Echo[ewewe]"
ewewe
[root@iZ2ze7k1pc9lk7pay5rcawZ ~]#