1
0
Fork 0
forked from infra/ansible

RabbitMQ: setup sending the queue metrix to CentOS

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
Aurélien Bompard 2025-07-21 15:23:42 +02:00
commit a51c0ea353
Signed by untrusted user: abompard
GPG key ID: 31584CFEB9BF64AD
7 changed files with 53 additions and 21 deletions

View file

@ -43,3 +43,11 @@ zabbix_templates:
template: "RabbitMQ node by Zabbix agent" # Template name in roles/zabbix/zabbix_templates/files/templatename.json
custom_template: false # Is the template official template bundled with Zabbix or one of our custom templates
hostgroup: "fedora rabbitmq" # Zabbix hostgroup
## CentOS monitoring
# Zabbix server instance
centos_zabbix_server: mon.centos.org
# Name of the RabbitMQ host in Zabbix
centos_zabbix_host: rabbitmq.fedora
centos_zabbix_queues:
- centos-stream-robosignatory

View file

@ -1,3 +1,10 @@
---
# https://www.rabbitmq.com/production-checklist.html#resource-limits-file-handle-limit
rabbitmq_cluster_file_limit: 500000
## CentOS monitoring
# Zabbix server instance
centos_zabbix_server: mon.centos.org
# Name of the RabbitMQ host in Zabbix
centos_zabbix_host: "{{ inventory_hostname }}"
centos_zabbix_queues: []

View file

@ -30,6 +30,7 @@ def parse_args():
"--conf", default=CONF_PATH, help="path to NRPE's rabbitmq_args.ini file"
)
parser.add_argument("--vhost", default=VHOST, help="the rabbitmq vhost")
parser.add_argument("-z", "--zabbix", help="the Zabbix server")
parser.add_argument(
"-s", "--host", default=getfqdn(), help="the server name in Zabbix"
)
@ -49,7 +50,11 @@ def main():
args = parse_args()
http = get_http_client(args.conf)
vhost = quote(args.vhost, safe="")
zabbix_sender_args = []
zabbix_sender_args = [
"-v",
"-z",
args.zabbix,
]
if args.tls_psk_identity:
zabbix_sender_args.extend(
[
@ -65,16 +70,16 @@ def main():
for queue_name in args.queue_name:
data = get_queue_values(http, vhost, queue_name)
for metric, value in data.items():
command = [
"zabbit_sender",
cmd = [
"zabbix_sender",
*zabbix_sender_args,
"--key",
f"rabbitmq.queue.{queue_name}.{metric}"
f"rabbitmq.queue.{queue_name}.{metric}",
"--value",
str(value),
]
print(" ".join(command))
# run(command, check=True)
print(" ".join(cmd))
run(cmd)
if __name__ == "__main__":

View file

@ -1,8 +0,0 @@
[Unit]
Description=Send queue metrics to Zabbix
[Service]
Type=oneshot
ExecStart=/usr/local/bin/send-rabbitmq-queue --tls-psk-identity foo --tls-psk-file bar centos-stream-robosignatory
User=nrpe
Group=nrpe

View file

@ -1,3 +1,11 @@
- name: Copy zabbix-agend.conf psk config
ansible.builtin.copy:
src: "{{ private }}/files/zabbix/centos{{env_suffix}}.psk"
dest: /etc/zabbix/centos.psk
owner: nrpe
group: nrpe
mode: "0600"
- name: Copy over the check script
ansible.builtin.copy:
src: send-rabbitmq-queue.py
@ -6,13 +14,17 @@
owner: root
group: nrpe
- name: Setup systemd unit files
- name: Setup systemd service file
ansible.builtin.template:
src: send-rabbitmq-queue.service
dest: /etc/systemd/system/send-rabbitmq-queue.service
notify:
- Reload systemd
- name: Setup systemd timer file
ansible.builtin.copy:
src: send-rabbitmq-queue.{{item}}
dest: /etc/systemd/system/send-rabbitmq-queue.{{item}}
with_items:
- service
- timer
src: send-rabbitmq-queue.timer
dest: /etc/systemd/system/send-rabbitmq-queue.timer
notify:
- Reload systemd

View file

@ -451,7 +451,7 @@
# Queue monitoring for CentOS Zabbix
- import_tasks: centos-monitoring.yml
when: inventory_hostname.startswith('rabbitmq03')
when: inventory_hostname.startswith('rabbitmq03') and env == 'production'
tags:
- rabbitmq_cluster
- config

View file

@ -0,0 +1,8 @@
[Unit]
Description=Send queue metrics to Zabbix
[Service]
Type=oneshot
ExecStart=/usr/local/bin/send-rabbitmq-queue -z {{centos_zabbix_server}} -s {{centos_zabbix_host}} --tls-psk-identity "Fedora RabbitMQ" --tls-psk-file /etc/zabbix/centos.psk {{ centos_zabbix_queues | join(" ") }}
User=nrpe
Group=nrpe