为Zabbix配置RabbitMQ监控模板

时间:2023-03-09 07:30:54
为Zabbix配置RabbitMQ监控模板

RabbitMQ的配置参考 https://github.com/jasonmcintosh/rabbitmq-zabbix

简而言之,具体分为几个步骤:

1. 将脚本文件(scripts文件夹)和配置文件(zabbix_agent.d/zabbix-rabbitmq.conf)拷贝至/etc/zabbix/ 文件夹,按需修改文件夹权限给zabbix用户(自测环境是使用root用户,所以不需要修改权限)

2. 配置。不建议使用guest用户,而是新建用户,并赋予其“只读权限”,即仅有几项监控相关的API可以访问,以下仅是一个参考:

rabbitmqctl add_user zabbix pass
rabbitmqctl set_user_tags zabbix monitoring
rabbitmqctl set_permissions -p / zabbix '^aliveness-test$' '^amq\.default$' '^aliveness-test$’

编辑/etc/zabbix/scripts/rabbitmq/.rab.auth文件,填写如下内容:

USERNAME=guest
PASSWORD=******
CONF=/etc/zabbix/zabbix_agent.conf
LOGLEVEL=DEBUG
LOGFILE=/var/log/zabbix/rabbitmq_zabbix.log
HOSTNAME=192.168.122.208
PORT=

3. 在Zabbix Dashboard上导入模板,配置给相关主机

4. 重启zabbix-agent
注意,因为我们是直接root用户,所以暂时可不需要创建zabbix用户,只需要确保.rab.auth文件中的配置是正确的即可。当然,最最最重要的是要确保rabbitmq-plugins中启用了rabbitmq-management: 
[root@f-q ~(keystone_admin)]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
mochiweb
webmachine
rabbitmq_web_dispatch
amqp_client
rabbitmq_management_agent
rabbitmq_management
Applying plugin configuration to rabbit@f-q... started plugins.
检查rabbitmq-plugins插件列表可发现:
为Zabbix配置RabbitMQ监控模板
这个问题的排查来自于最开始配置了模板之后,提示Dead RabbitMQ,但是RabbitMQ服务正常。于是简单的尝试http api,看下效果:
[root@f-q ~(keystone_admin)]#  curl -i -u guest:***** http://192.168.122.208:15672/api/vhosts
curl: () Failed connect to 192.168.122.208:; Connection refused
[root@f-q ~(keystone_admin)]# curl -i -u guest:***** http://192.168.122.208:5672/api/vhosts
AMQP
[root@f-q ~(keystone_admin)]# curl curl -i -u guest:***** http://192.168.122.208:25672/api/
curl: () Could not resolve host: curl; Name or service not known
curl: () Empty reply from server
[root@f-q ~(keystone_admin)]#
其实这里由于对rabbitmq的了解不够,所以没有第一时间看到问题——即模板配置说明中明确默认使用的是15672的端口,而我们的15672的端口并不连通,说明这个端口背后的服务是没启动的,那么这个端口是干嘛的呢?通过Google,我们查到RabbitMQ的官方文档中的说明:
: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
, : used by AMQP -- and 1.0 clients without and with TLS
: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + ). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
-: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + through server distribution port + ). See networking guide for details.
: HTTP API clients, management UI and rabbitmqadmin (only if the management pluginis enabled)
, : STOMP clients without and with TLS (only if the STOMP plugin is enabled)
, : (MQTT clients without and with TLS, if the MQTT plugin is enabled
: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
也就是说,我们必须要启用rabbitmq_management插件,才能保证15672,HTTP API客户端可用!
那么完成脚本和参数配置,并导入模板后,试着创建主机(虽然是fake driver),看到zabbix dashboard上的变化:
为Zabbix配置RabbitMQ监控模板
有数据变化就是好的……虽然只有message count和message rates,没有我们想要的连接数等信息……