diff --git a/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsConstant.java b/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsConstant.java index 0af2ac616c4..4b319f12f6f 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsConstant.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsConstant.java @@ -21,6 +21,8 @@ public class BrokerMetricsConstant { public static final String GAUGE_PROCESSOR_WATERMARK = "rocketmq_processor_watermark"; public static final String GAUGE_BROKER_PERMISSION = "rocketmq_broker_permission"; + public static final String GAUGE_TOPIC_NUM = "rocketmq_topic_number"; + public static final String GAUGE_CONSUMER_GROUP_NUM = "rocketmq_consumer_group_number"; public static final String COUNTER_MESSAGES_IN_TOTAL = "rocketmq_messages_in_total"; public static final String COUNTER_MESSAGES_OUT_TOTAL = "rocketmq_messages_out_total"; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java b/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java index 0050a0dcd4c..d8d94f8e69a 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/metrics/BrokerMetricsManager.java @@ -81,6 +81,8 @@ import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.COUNTER_ROLLBACK_MESSAGES_TOTAL; import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.COUNTER_THROUGHPUT_IN_TOTAL; import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.COUNTER_THROUGHPUT_OUT_TOTAL; +import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.GAUGE_TOPIC_NUM; +import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.GAUGE_CONSUMER_GROUP_NUM; import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.GAUGE_BROKER_PERMISSION; import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.GAUGE_CONSUMER_CONNECTIONS; import static org.apache.rocketmq.broker.metrics.BrokerMetricsConstant.GAUGE_CONSUMER_INFLIGHT_MESSAGES; @@ -131,6 +133,9 @@ public class BrokerMetricsManager { // broker stats metrics public static ObservableLongGauge processorWatermark = new NopObservableLongGauge(); public static ObservableLongGauge brokerPermission = new NopObservableLongGauge(); + public static ObservableLongGauge topicNum = new NopObservableLongGauge(); + public static ObservableLongGauge consumerGroupNum = new NopObservableLongGauge(); + // request metrics public static LongCounter messagesInTotal = new NopLongCounter(); @@ -490,6 +495,16 @@ private void initStatsMetrics() { .setDescription("Broker permission") .ofLongs() .buildWithCallback(measurement -> measurement.record(brokerConfig.getBrokerPermission(), newAttributesBuilder().build())); + + topicNum = brokerMeter.gaugeBuilder(GAUGE_TOPIC_NUM) + .setDescription("Active topic number") + .ofLongs() + .buildWithCallback(measurement -> measurement.record(brokerController.getTopicConfigManager().getTopicConfigTable().size(), newAttributesBuilder().build())); + + consumerGroupNum = brokerMeter.gaugeBuilder(GAUGE_CONSUMER_GROUP_NUM) + .setDescription("Active subscription group number") + .ofLongs() + .buildWithCallback(measurement -> measurement.record(brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable().size(), newAttributesBuilder().build())); } private void initRequestMetrics() {