Skip to content

MQTT Specific Metrics ​

RobustMQ exposes MQTT protocol, connection, message, delay-queue, and connector metrics through the Prometheus /metrics endpoint. The names below are the names emitted by Prometheus. Counter families are registered without _total in Rust; prometheus-client adds that suffix to the exposed name.

Packet Metrics ​

Received packets ​

Metric NameTypeLabelsDescription
mqtt_packets_received_totalCounternetworkMQTT packets received
mqtt_packets_connect_received_totalCounternetworkCONNECT packets received
mqtt_packets_publish_received_totalCounternetworkPUBLISH packets received
mqtt_packets_connack_received_totalCounternetworkCONNACK packets received
mqtt_packets_puback_received_totalCounternetworkPUBACK packets received
mqtt_packets_pubrec_received_totalCounternetworkPUBREC packets received
mqtt_packets_pubrel_received_totalCounternetworkPUBREL packets received
mqtt_packets_pubcomp_received_totalCounternetworkPUBCOMP packets received
mqtt_packets_subscribe_received_totalCounternetworkSUBSCRIBE packets received
mqtt_packets_unsubscribe_received_totalCounternetworkUNSUBSCRIBE packets received
mqtt_packets_pingreq_received_totalCounternetworkPINGREQ packets received
mqtt_packets_disconnect_received_totalCounternetworkDISCONNECT packets received
mqtt_packets_auth_received_totalCounternetworkAUTH packets received
mqtt_packets_received_error_totalCounternetworkPackets rejected during receive or decoding
mqtt_packets_connack_auth_error_totalCounternetworkCONNACK packets rejected for authorization
mqtt_packets_connack_error_totalCounternetworkCONNACK packets with an error result
mqtt_bytes_received_totalCounternetworkMQTT bytes received

Sent packets ​

Metric NameTypeLabelsDescription
mqtt_packets_sent_totalCounternetwork, qosMQTT packets sent
mqtt_packets_connack_sent_totalCounternetwork, qosCONNACK packets sent
mqtt_packets_publish_sent_totalCounternetwork, qosPUBLISH packets sent
mqtt_packets_puback_sent_totalCounternetwork, qosPUBACK packets sent
mqtt_packets_pubrec_sent_totalCounternetwork, qosPUBREC packets sent
mqtt_packets_pubrel_sent_totalCounternetwork, qosPUBREL packets sent
mqtt_packets_pubcomp_sent_totalCounternetwork, qosPUBCOMP packets sent
mqtt_packets_suback_sent_totalCounternetwork, qosSUBACK packets sent
mqtt_packets_unsuback_sent_totalCounternetwork, qosUNSUBACK packets sent
mqtt_packets_pingresp_sent_totalCounternetwork, qosPINGRESP packets sent
mqtt_packets_disconnect_sent_totalCounternetwork, qosDISCONNECT packets sent
mqtt_packets_auth_sent_totalCounternetwork, qosAUTH packets sent; qos is -1 because AUTH is not a PUBLISH packet
mqtt_bytes_sent_totalCounternetwork, qosMQTT bytes sent
mqtt_retain_packets_received_totalCounterqosRetained messages received
mqtt_retain_packets_sent_totalCounterqosRetained messages sent

Cross-network totals ​

These unlabeled counters aggregate packet and byte totals across all network types.

Metric NameTypeDescription
mqtt_total_bytes_received_totalCounterMQTT bytes received across all network types
mqtt_total_bytes_sent_totalCounterMQTT bytes sent across all network types
mqtt_total_packets_received_totalCounterMQTT packets received across all network types
mqtt_total_packets_sent_totalCounterMQTT packets sent across all network types
mqtt_total_packets_connect_totalCounterCONNECT packets received
mqtt_total_packets_connack_totalCounterCONNACK packets sent
mqtt_total_packets_publish_received_totalCounterPUBLISH packets received
mqtt_total_packets_publish_sent_totalCounterPUBLISH packets sent
mqtt_total_packets_puback_received_totalCounterPUBACK packets received
mqtt_total_packets_puback_sent_totalCounterPUBACK packets sent
mqtt_total_packets_pubrec_received_totalCounterPUBREC packets received
mqtt_total_packets_pubrec_sent_totalCounterPUBREC packets sent
mqtt_total_packets_pubrel_received_totalCounterPUBREL packets received
mqtt_total_packets_pubrel_sent_totalCounterPUBREL packets sent
mqtt_total_packets_pubcomp_received_totalCounterPUBCOMP packets received
mqtt_total_packets_pubcomp_sent_totalCounterPUBCOMP packets sent
mqtt_total_packets_subscribe_totalCounterSUBSCRIBE packets received
mqtt_total_packets_suback_totalCounterSUBACK packets sent
mqtt_total_packets_unsubscribe_totalCounterUNSUBSCRIBE packets received
mqtt_total_packets_unsuback_totalCounterUNSUBACK packets sent
mqtt_total_packets_pingreq_totalCounterPINGREQ packets received
mqtt_total_packets_pingresp_totalCounterPINGRESP packets sent
mqtt_total_packets_disconnect_received_totalCounterDISCONNECT packets received
mqtt_total_packets_disconnect_sent_totalCounterDISCONNECT packets sent
mqtt_total_packets_auth_totalCounterAUTH packets received
mqtt_total_packets_auth_sent_totalCounterAUTH packets sent

Packet timing ​

Metric NameTypeLabelsDescription
mqtt_packet_process_duration_msHistogramnetwork, packetMQTT packet processing duration in milliseconds
mqtt_packet_send_duration_msHistogramnetwork, packetMQTT packet sending duration in milliseconds

network values are Tcp, Tls, Websocket, Websockets, Quic, and Unknown when the connection type is unavailable. The qos value is 0, 1, or 2 for PUBLISH packets and -1 for non-PUBLISH packets. Packet names are lowercase values such as connect, publish, and subscribe.

Connection and Authentication Metrics ​

Metric NameTypeLabelsDescription
client_connections_totalCountertenant, client_idClient connection attempts, regardless of outcome
mqtt_connection_success_totalCounter—Successful MQTT connections
mqtt_connection_failed_totalCounter—Failed MQTT connections
mqtt_disconnect_success_totalCounter—Successful MQTT disconnections
mqtt_connection_expired_totalCounter—Expired MQTT connections
mqtt_auth_success_totalCounter—Successful MQTT authentication checks
mqtt_auth_failed_totalCounter—Failed MQTT authentication checks
mqtt_acl_success_totalCounter—Successful MQTT ACL checks
mqtt_acl_failed_totalCounter—Failed MQTT ACL checks
mqtt_blacklist_blocked_totalCounter—Connections blocked by the MQTT blacklist
mqtt_subscribe_success_totalCounter—Successful subscriptions
mqtt_subscribe_failed_totalCounter—Failed subscriptions
mqtt_unsubscribe_success_totalCounter—Successful unsubscriptions

Session and Message Metrics ​

Metric NameTypeLabelsDescription
mqtt_session_created_totalCounter—MQTT sessions created
mqtt_session_deleted_totalCounter—MQTT sessions deleted
session_messages_in_totalCountertenant, client_idMessages received per session
session_messages_out_totalCountertenant, client_idMessages sent per session
connection_messages_in_totalCounterconnection_idMessages received per connection
connection_messages_out_totalCounterconnection_idMessages sent per connection
mqtt_messages_received_totalCounter—Messages received from clients
mqtt_messages_sent_totalCounter—Messages sent to clients
mqtt_message_bytes_received_totalCounter—Message bytes received from clients
mqtt_message_bytes_sent_totalCounter—Message bytes sent to clients
mqtt_messages_delayed_totalCounter—Delayed publish messages
mqtt_messages_dropped_no_subscribers_totalCounter—Messages dropped because there were no subscribers

Resource Statistics ​

Metric NameTypeLabelsDescription
mqtt_connections_countGauge—Current MQTT connection count
mqtt_sessions_countGauge—Current MQTT session count
mqtt_topics_countGauge—Current MQTT topic count
mqtt_subscribers_countGauge—Current MQTT subscriber count
mqtt_subscriptions_exclusive_countGauge—Current exclusive subscription count
mqtt_subscriptions_shared_countGauge—Current shared subscription count
mqtt_subscriptions_shared_group_countGauge—Current shared subscription-group count
mqtt_retained_countGauge—Current retained-message count
mqtt_delay_queue_total_capacityGaugeshard_noTotal delay-queue capacity
mqtt_delay_queue_used_capacityGaugeshard_noUsed delay-queue capacity
mqtt_delay_queue_remaining_capacityGaugeshard_noRemaining delay-queue capacity

Topic and Subscription Metrics ​

Metric NameTypeLabelsDescription
topic_messages_written_totalCountertenant, topicMessages written to a topic
topic_bytes_written_totalCountertenant, topicBytes written to a topic
topic_messages_sent_totalCountertenant, topicMessages sent from a topic
topic_bytes_sent_totalCountertenant, topicBytes sent from a topic
subscribe_messages_sent_totalCountertenant, client_id, path, statusMessages sent to a subscription path
subscribe_topic_messages_sent_totalCountertenant, client_id, path, topic_name, statusMessages sent to a subscription path and topic
subscribe_bytes_sent_totalCountertenant, client_id, path, statusBytes sent to a subscription path
subscribe_topic_bytes_sent_totalCountertenant, client_id, path, topic_name, statusBytes sent to a subscription path and topic

Subscription status values are success and failed.

Delay Message and Connector Metrics ​

Metric NameTypeLabelsDescription
delay_msg_enqueue_totalCounter—Delay messages enqueued
delay_msg_deliver_totalCounter—Delay messages delivered
delay_msg_deliver_fail_totalCounter—Delay-message delivery failures
delay_msg_recover_totalCounter—Delay messages recovered at startup
delay_msg_recover_expired_totalCounter—Expired messages found during recovery
delay_message_retry_totalCounterstatusRetry attempts; status is success or failed
delay_message_retry_count_totalCounterattemptRetry attempts grouped by numeric attempt value
delay_message_reenqueued_totalCounter—Messages re-enqueued after a failed delivery
delay_message_dead_letter_totalCounter—Messages sent to the dead-letter queue
delay_msg_enqueue_duration_msHistogram—Delay-message enqueue duration
delay_msg_deliver_duration_msHistogram—Delay-message delivery duration
delay_task_created_totalCounter—Delay tasks created
delay_task_executed_totalCountertask_typeDelay tasks executed successfully
delay_task_execute_failed_totalCountertask_typeDelay-task execution failures
delay_task_schedule_latency_secondsHistogramtask_typeDifference between actual and target execution time
mqtt_connector_messages_sent_success_totalCountertenant, connector_type, connector_nameMessages sent successfully by a connector
mqtt_connector_messages_sent_failure_totalCountertenant, connector_type, connector_nameMessages that failed to send
mqtt_connector_send_duration_msHistogramtenant, connector_type, connector_nameConnector send duration
mqtt_connector_retry_totalCountertenant, connector_type, connector_name, strategyConnector retry attempts
mqtt_connector_messages_discarded_totalCountertenant, connector_type, connector_name, strategyMessages discarded by terminal strategy
mqtt_connector_dlq_messages_totalCountertenant, connector_type, connector_name, resultDLQ write attempts by result
mqtt_connector_offset_commit_failure_totalCountertenant, connector_type, connector_nameConnector offset-commit failures
mqtt_connector_source_read_failure_totalCountertenant, connector_type, connector_nameConnector source-read failures
mqtt_connector_upGaugetenant, connector_type, connector_nameConnector status: 1 running, 0 stopped
mqtt_connector_messages_sent_success_agg_totalCounter—Successful sends across all connectors
mqtt_connector_messages_sent_failure_agg_totalCounter—Failed sends across all connectors
mqtt_connector_send_duration_ms_aggHistogram—Aggregate connector send duration

Usage Examples ​

rust
use common_metrics::mqtt::{auth, event, time};
use metadata_struct::connection::NetworkConnectionType;

event::record_mqtt_connection_success();
auth::record_mqtt_auth_failed();
time::record_packet_process_duration(
    &NetworkConnectionType::Tcp,
    "publish",
    15.5,
);

Example PromQL queries:

promql
rate(mqtt_packets_publish_received_total[5m])
rate(mqtt_packets_publish_sent_total[5m])
rate(mqtt_auth_failed_total[5m]) /
  (rate(mqtt_auth_success_total[5m]) + rate(mqtt_auth_failed_total[5m]))
histogram_quantile(0.95, sum by (le) (rate(mqtt_packet_process_duration_ms_bucket[5m])))
mqtt_delay_queue_used_capacity / mqtt_delay_queue_total_capacity

Grafana Dashboard Configuration ​

The repository includes an importable dashboard at grafana/robustmq-broker.json. For setup and import instructions, see the Grafana Configuration Guide. The examples below are panel query snippets, not a complete dashboard JSON document.

Connection Overview Panel ​

json
{
  "title": "MQTT Connection Overview",
  "targets": [
    {
      "expr": "mqtt_connections_count",
      "legendFormat": "Current Connections"
    },
    {
      "expr": "rate(mqtt_connection_success_total[5m])",
      "legendFormat": "Connection Success Rate/sec"
    },
    {
      "expr": "rate(mqtt_connection_failed_total[5m])",
      "legendFormat": "Connection Failure Rate/sec"
    }
  ]
}

Message Throughput Panel ​

The packet and byte counters have network labels. The sum by (network) aggregation combines sent QoS series while preserving the transport type in the legend.

json
{
  "title": "MQTT Message Throughput",
  "targets": [
    {
      "expr": "sum by (network) (rate(mqtt_packets_publish_received_total[5m]))",
      "legendFormat": "PUBLISH Received/sec ({{network}})"
    },
    {
      "expr": "sum by (network) (rate(mqtt_packets_publish_sent_total[5m]))",
      "legendFormat": "PUBLISH Sent/sec ({{network}})"
    },
    {
      "expr": "sum by (network) (rate(mqtt_bytes_received_total[5m]))",
      "legendFormat": "Bytes Received/sec ({{network}})"
    },
    {
      "expr": "sum by (network) (rate(mqtt_bytes_sent_total[5m]))",
      "legendFormat": "Bytes Sent/sec ({{network}})"
    }
  ]
}

Performance Monitoring Panel ​

Histogram buckets must be aggregated by le before calculating a percentile.

json
{
  "title": "MQTT Performance Monitoring",
  "targets": [
    {
      "expr": "histogram_quantile(0.95, sum by (le) (rate(mqtt_packet_process_duration_ms_bucket[5m])))",
      "legendFormat": "P95 Processing Duration (ms)"
    },
    {
      "expr": "histogram_quantile(0.99, sum by (le) (rate(mqtt_packet_process_duration_ms_bucket[5m])))",
      "legendFormat": "P99 Processing Duration (ms)"
    }
  ]
}

MQTT Alert Rules ​

The Prometheus rule examples below use metric names exposed by the current implementation. The repository also provides a broader alert rules file at grafana/robustmq-alerts.yml; see the Grafana Configuration Guide for setup. These snippets show MQTT-specific alert conditions and are not a replacement for the complete file.

Connection Alerts ​

yaml
- alert: RobustMQHighConnectionFailureRate
  expr: (sum(rate(mqtt_connection_failed_total[5m])) / clamp_min(sum(rate(mqtt_connection_success_total[5m])) + sum(rate(mqtt_connection_failed_total[5m])), 1e-9)) > 0.1
  for: 2m
  labels:
    severity: warning
  annotations:
    summary: "High MQTT connection failure rate"
    description: "MQTT connection failure ratio is {{ $value | humanizePercentage }}."

- alert: RobustMQHighConnectionCount
  expr: mqtt_connections_count > 5000
  for: 5m
  labels:
    severity: warning
  annotations:
    summary: "High MQTT connection count"
    description: "Current MQTT connections: {{ $value }}"

Performance and Error Alerts ​

Histogram buckets are aggregated by le and grouped by the available network and packet labels so the alert identifies the affected transport and packet type.

yaml
- alert: RobustMQHighMqttPacketProcessingLatency
  expr: histogram_quantile(0.95, sum by (le, network, packet) (rate(mqtt_packet_process_duration_ms_bucket[5m]))) > 100
  for: 3m
  labels:
    severity: warning
  annotations:
    summary: "High MQTT packet processing latency"
    description: "P95 latency is {{ $value }}ms for {{ $labels.packet }} on {{ $labels.network }}."

- alert: RobustMQPacketErrors
  expr: sum by (network) (rate(mqtt_packets_received_error_total[5m])) > 1
  for: 5m
  labels:
    severity: warning
  annotations:
    summary: "High MQTT packet error rate"
    description: "Packet errors are {{ $value }} per second on {{ $labels.network }}."

Authentication and Capacity Alerts ​

yaml
- alert: RobustMQHighMqttAuthenticationFailureRatio
  expr: (sum(rate(mqtt_auth_failed_total[5m])) / clamp_min(sum(rate(mqtt_auth_success_total[5m])) + sum(rate(mqtt_auth_failed_total[5m])), 1e-9)) > 0.2
  for: 1m
  labels:
    severity: warning
  annotations:
    summary: "High MQTT authentication failure ratio"
    description: "Authentication failure ratio is {{ $value | humanizePercentage }}."

- alert: RobustMQDelayQueueNearFull
  expr: (mqtt_delay_queue_total_capacity > 0) and ((mqtt_delay_queue_used_capacity / mqtt_delay_queue_total_capacity) > 0.9)
  for: 2m
  labels:
    severity: critical
  annotations:
    summary: "MQTT delay queue near capacity"
    description: "Shard {{ $labels.shard_no }} is using {{ $value | humanizePercentage }} of capacity."

- alert: RobustMQTooManyRetainedMessages
  expr: mqtt_retained_count > 100000
  for: 5m
  labels:
    severity: warning
  annotations:
    summary: "Too many MQTT retained messages"
    description: "Current retained message count: {{ $value }}"
🎉 既然都登录了 GitHub,不如顺手给我们点个 Star 吧!⭐ 你的支持是我们最大的动力 🚀