This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new be97a4c [stats] Expose namespace topics count when exposing topic
level metrics (#3849)
be97a4c is described below
commit be97a4c66312c3a0e6b7d1b115dddffa68ad4ec8
Author: Sijie Guo <[email protected]>
AuthorDate: Tue Mar 19 21:08:05 2019 +0800
[stats] Expose namespace topics count when exposing topic level metrics
(#3849)
*Motivation*
Topics count is a namespace level metric. Currently if
`exposeTopicLevelMetricsInPrometheus=true`
we don't expose `pulsar_topics_count`. However `pulsar_topics_count` is a
very useful metric for
monitoring the healthy of the cluster.
*Modifications*
if `exposeTopicLevelMetricsInPrometheus=true`, we expose namespace level
metrics that are not
exposed at topic level. e.g. `pulsar_topics_count`.
---
.../broker/stats/prometheus/NamespaceStatsAggregator.java | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java
index e3a0091..2e7836b 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java
@@ -18,6 +18,7 @@
*/
package org.apache.pulsar.broker.stats.prometheus;
+import java.util.concurrent.atomic.LongAdder;
import org.apache.bookkeeper.mledger.impl.ManagedLedgerMBeanImpl;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.service.Topic;
@@ -50,6 +51,8 @@ public class NamespaceStatsAggregator {
printDefaultBrokerStats(stream, cluster);
+ LongAdder topicsCount = new LongAdder();
+
pulsar.getBrokerService().getMultiLayerTopicMap().forEach((namespace,
bundlesMap) -> {
namespaceStats.reset();
@@ -58,6 +61,7 @@ public class NamespaceStatsAggregator {
getTopicStats(topic, topicStats, includeConsumerMetrics);
if (includeTopicMetrics) {
+ topicsCount.add(1);
TopicStats.printTopicStats(stream, cluster, namespace,
name, topicStats);
} else {
namespaceStats.updateStats(topicStats);
@@ -69,6 +73,8 @@ public class NamespaceStatsAggregator {
// Only include namespace level stats if we don't have the
per-topic, otherwise we're going to report
// the same data twice, and it will make the aggregation
difficult
printNamespaceStats(stream, cluster, namespace,
namespaceStats);
+ } else {
+ printTopicsCountStats(stream, cluster, namespace, topicsCount);
}
});
}
@@ -170,6 +176,11 @@ public class NamespaceStatsAggregator {
metric(stream, cluster, "pulsar_msg_backlog", 0);
}
+ private static void printTopicsCountStats(SimpleTextOutputStream stream,
String cluster, String namespace,
+ LongAdder topicsCount) {
+ metric(stream, cluster, namespace, "pulsar_topics_count",
topicsCount.sum());
+ }
+
private static void printNamespaceStats(SimpleTextOutputStream stream,
String cluster, String namespace,
AggregatedNamespaceStats stats) {
metric(stream, cluster, namespace, "pulsar_topics_count",
stats.topicsCount);