Tài liệu này hướng dẫn cấu hình Alloy để thu thập Metrics từ ứng dụng RabbitMQ

1. Chuẩn bị

  • Thực hiện cài đặt Alloy Agent trên máy chủ Linux bằng lệnh sau:
/bin/sh -c "$(curl -fsSL https://s3hn.smartcloud.vn/agent/alloy/linux/releases/v1.8.3/install-linux.sh)"
  • Đã cài RabbitMQ (version 3.8.0 trở lên) trên VM
  • Để thu thập metrics từ Cluster RabbitMQ
rabbitmq-plugins enable rabbitmq_prometheus 

2. Cấu hình tích hợp

Tại đường dẫn /etc/alloy/config.alloy, chỉnh sửa Alloy để tích hợp RabbitMQ:

sudo vi /etc/alloy/config.alloy
TrườngÝ nghĩaGiá trị mẫu
urlEndpoint của dịch vụ APM trên giao diện Consolehttps://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push
AuthorizationToken của dịch vụ APM trên giao diện Consolea5130b91-ff9b-41ef-8722-9d923a574123
tenantTên dịch vụ APMapm-postgre
__address__Địa chỉ node cài RabbitMQ10.168.12.59

Thay các trường trong cấu hình trên, trong đó:

prometheus.remote_write "metrics_integrations_rabbitmq" {
    endpoint {
        url = "<endpoint dịch vụ APM>"
        headers = {
            "Authorization" = "<token dịch vụ APM>",
        }
        tls_config {
            insecure_skip_verify = true
        }
    }
    external_labels = {
        tenant = "<tên dịch vụ APM>",
    }
}

discovery.relabel "metrics_integrations_rabbitmq_node1" {
    targets = [{
        __address__ = "<rabbitmq-node1:15692>",
    }]

    rule {
        source_labels = ["__address__"]
        regex         = "([^:]+):[0-9]+"
        target_label  = "instance"
        replacement   = "$1"
        action        = "replace"
    }
}

discovery.relabel "metrics_integrations_rabbitmq_node2" {
    targets = [{
        __address__ = "<rabbitmq-node2:15692>",
    }]

    rule {
        source_labels = ["__address__"]
        regex         = "([^:]+):[0-9]+"
        target_label  = "instance"
        replacement   = "$1"
        action        = "replace"
    }
}

discovery.relabel "metrics_integrations_rabbitmq_node3" {
    targets = [{
        __address__ = "<rabbitmq-node3:15692>",
    }]

    rule {
        source_labels = ["__address__"]
        regex         = "([^:]+):[0-9]+"
        target_label  = "instance"
        replacement   = "$1"
        action        = "replace"
    }
}

prometheus.relabel "metrics_integrations_rabbitmq" {
    forward_to = [prometheus.remote_write.metrics_integrations_rabbitmq.receiver]

    rule {
        source_labels = ["__name__"]
        regex         = "up|erlang_vm_allocators|erlang_vm_dist_node_state|rabbitmq_build_info|rabbitmq_channel_consumers|rabbitmq_channel_get_ack_total|rabbitmq_channel_get_empty_total|rabbitmq_channel_get_total|rabbitmq_channel_messages_acked_total|rabbitmq_channel_messages_confirmed_total|rabbitmq_channel_messages_delivered_ack_total|rabbitmq_channel_messages_delivered_total|rabbitmq_channel_messages_published_total|rabbitmq_channel_messages_redelivered_total|rabbitmq_channel_messages_unconfirmed|rabbitmq_channel_messages_unroutable_dropped_total|rabbitmq_channel_messages_unroutable_returned_total|rabbitmq_channels|rabbitmq_channels_closed_total|rabbitmq_channels_opened_total|rabbitmq_connections|rabbitmq_connections_closed_total|rabbitmq_connections_opened_total|rabbitmq_disk_space_available_bytes|rabbitmq_identity_info|rabbitmq_process_max_fds|rabbitmq_process_max_tcp_sockets|rabbitmq_process_open_fds|rabbitmq_process_open_tcp_sockets|rabbitmq_process_resident_memory_bytes|rabbitmq_queue_messages_published_total|rabbitmq_queue_messages_ready|rabbitmq_queue_messages_unacked|rabbitmq_queues|rabbitmq_queues_created_total|rabbitmq_queues_declared_total|rabbitmq_queues_deleted_total|rabbitmq_resident_memory_limit_bytes"
        action        = "keep"
    }
}

prometheus.scrape "metrics_integrations_rabbitmq" {
    targets    = concat(discovery.relabel.metrics_integrations_rabbitmq_node1.output, discovery.relabel.metrics_integrations_rabbitmq_node2.output, discovery.relabel.metrics_integrations_rabbitmq_node3.output)
    forward_to = [prometheus.relabel.metrics_integrations_rabbitmq.receiver]
    job_name   = "integrations/rabbitmq"
}

3. Cài đặt

Thực hiện lệnh sau để khởi động Alloy:

sudo systemctl start alloy 

4. Kiểm tra

4.1 Kiểm tra dịch vụ

Thực hiện lệnh sau:

 sudo systemctl status alloy 

Hệ thống trả về như sau nếu thành công:

● alloy.service - Vendor-agnostic OpenTelemetry Collector distribution with programmable pipelines
     Loaded: loaded (/lib/systemd/system/alloy.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2025-04-24 18:25:30 +07; 14h ago
       Docs: https://grafana.com/docs/alloy
    Process: 312064 ExecReload=/usr/bin/env kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
   Main PID: 4041003 (alloy)
      Tasks: 18 (limit: 9385)
     Memory: 80.3M
        CPU: 38min 6.739s
     CGroup: /system.slice/alloy.service
             └─4041003 /usr/bin/alloy run --server.http.listen-addr=0.0.0.0:30000 --storage.path=/var/lib/alloy/data /e>

Nếu không thành công, xem log Alloy:

sudo journalctl -u alloy -ex 

Sau đó chỉnh sửa cấu hình nếu cần và khởi động lại:

sudo systemctl restart alloy 

4.2 Kiểm tra tích hợp

Tham khảo hướng dẫn tích hợp dashboard, kiểm tra metrics RabbitMQ trên giao diện Dashboard:

Một số dashboard mẫu khi tích hợp thành công:

RabbitMQ.png