use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.
the class PartitionedTopicStatsTest method testPartitionedTopicStats.
@Test
public void testPartitionedTopicStats() {
PartitionedTopicStats partitionedTopicStats = new PartitionedTopicStats();
partitionedTopicStats.msgRateIn = 1;
partitionedTopicStats.msgThroughputIn = 1;
partitionedTopicStats.msgRateOut = 1;
partitionedTopicStats.msgThroughputOut = 1;
partitionedTopicStats.averageMsgSize = 1;
partitionedTopicStats.storageSize = 1;
partitionedTopicStats.publishers.add(new PublisherStats());
partitionedTopicStats.subscriptions.put("test_ns", new SubscriptionStats());
partitionedTopicStats.replication.put("test_ns", new ReplicatorStats());
partitionedTopicStats.metadata.partitions = 1;
partitionedTopicStats.partitions.put("test", partitionedTopicStats);
partitionedTopicStats.reset();
assertEquals(partitionedTopicStats.msgRateIn, 0.0);
assertEquals(partitionedTopicStats.msgThroughputIn, 0.0);
assertEquals(partitionedTopicStats.msgRateOut, 0.0);
assertEquals(partitionedTopicStats.msgThroughputOut, 0.0);
assertEquals(partitionedTopicStats.averageMsgSize, 0.0);
assertEquals(partitionedTopicStats.storageSize, 0);
assertEquals(partitionedTopicStats.publishers.size(), 0);
assertEquals(partitionedTopicStats.subscriptions.size(), 0);
assertEquals(partitionedTopicStats.replication.size(), 0);
assertEquals(partitionedTopicStats.metadata.partitions, 0);
assertEquals(partitionedTopicStats.partitions.size(), 0);
}
use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.
the class PersistentTopic method updateRates.
public void updateRates(NamespaceStats nsStats, NamespaceBundleStats bundleStats, StatsOutputStream topicStatsStream, ClusterReplicationMetrics replStats, String namespace) {
TopicStats topicStats = threadLocalTopicStats.get();
topicStats.reset();
replicators.forEach((region, replicator) -> replicator.updateRates());
nsStats.producerCount += producers.size();
bundleStats.producerCount += producers.size();
topicStatsStream.startObject(topic);
producers.forEach(producer -> {
producer.updateRates();
PublisherStats publisherStats = producer.getStats();
topicStats.aggMsgRateIn += publisherStats.msgRateIn;
topicStats.aggMsgThroughputIn += publisherStats.msgThroughputIn;
if (producer.isRemote()) {
topicStats.remotePublishersStats.put(producer.getRemoteCluster(), publisherStats);
}
});
// Creating publishers object for backward compatibility
topicStatsStream.startList("publishers");
topicStatsStream.endList();
// Start replicator stats
topicStatsStream.startObject("replication");
nsStats.replicatorCount += topicStats.remotePublishersStats.size();
replicators.forEach((cluster, replicator) -> {
// Update replicator cursor state
((PersistentReplicator) replicator).updateCursorState();
// Update replicator stats
ReplicatorStats rStat = replicator.getStats();
// Add incoming msg rates
PublisherStats pubStats = topicStats.remotePublishersStats.get(replicator.getRemoteCluster());
if (pubStats != null) {
rStat.msgRateIn = pubStats.msgRateIn;
rStat.msgThroughputIn = pubStats.msgThroughputIn;
rStat.inboundConnection = pubStats.address;
rStat.inboundConnectedSince = pubStats.connectedSince;
}
topicStats.aggMsgRateOut += rStat.msgRateOut;
topicStats.aggMsgThroughputOut += rStat.msgThroughputOut;
// Populate replicator specific stats here
topicStatsStream.startObject(cluster);
topicStatsStream.writePair("connected", rStat.connected);
topicStatsStream.writePair("msgRateExpired", rStat.msgRateExpired);
topicStatsStream.writePair("msgRateIn", rStat.msgRateIn);
topicStatsStream.writePair("msgRateOut", rStat.msgRateOut);
topicStatsStream.writePair("msgThroughputIn", rStat.msgThroughputIn);
topicStatsStream.writePair("msgThroughputOut", rStat.msgThroughputOut);
topicStatsStream.writePair("replicationBacklog", rStat.replicationBacklog);
topicStatsStream.writePair("replicationDelayInSeconds", rStat.replicationDelayInSeconds);
topicStatsStream.writePair("inboundConnection", rStat.inboundConnection);
topicStatsStream.writePair("inboundConnectedSince", rStat.inboundConnectedSince);
topicStatsStream.writePair("outboundConnection", rStat.outboundConnection);
topicStatsStream.writePair("outboundConnectedSince", rStat.outboundConnectedSince);
topicStatsStream.endObject();
nsStats.msgReplBacklog += rStat.replicationBacklog;
if (replStats.isMetricsEnabled()) {
String namespaceClusterKey = replStats.getKeyName(namespace, cluster);
ReplicationMetrics replicationMetrics = replStats.get(namespaceClusterKey);
boolean update = false;
if (replicationMetrics == null) {
replicationMetrics = ReplicationMetrics.get();
update = true;
}
replicationMetrics.connected += rStat.connected ? 1 : 0;
replicationMetrics.msgRateOut += rStat.msgRateOut;
replicationMetrics.msgThroughputOut += rStat.msgThroughputOut;
replicationMetrics.msgReplBacklog += rStat.replicationBacklog;
if (update) {
replStats.put(namespaceClusterKey, replicationMetrics);
}
}
});
// Close replication
topicStatsStream.endObject();
// Start subscription stats
topicStatsStream.startObject("subscriptions");
nsStats.subsCount += subscriptions.size();
subscriptions.forEach((subscriptionName, subscription) -> {
double subMsgRateOut = 0;
double subMsgThroughputOut = 0;
double subMsgRateRedeliver = 0;
// Start subscription name & consumers
try {
topicStatsStream.startObject(subscriptionName);
Object[] consumers = subscription.getConsumers().array();
nsStats.consumerCount += consumers.length;
bundleStats.consumerCount += consumers.length;
topicStatsStream.startList("consumers");
for (Object consumerObj : consumers) {
Consumer consumer = (Consumer) consumerObj;
consumer.updateRates();
ConsumerStats consumerStats = consumer.getStats();
subMsgRateOut += consumerStats.msgRateOut;
subMsgThroughputOut += consumerStats.msgThroughputOut;
subMsgRateRedeliver += consumerStats.msgRateRedeliver;
// Populate consumer specific stats here
topicStatsStream.startObject();
topicStatsStream.writePair("address", consumerStats.address);
topicStatsStream.writePair("consumerName", consumerStats.consumerName);
topicStatsStream.writePair("availablePermits", consumerStats.availablePermits);
topicStatsStream.writePair("connectedSince", consumerStats.connectedSince);
topicStatsStream.writePair("msgRateOut", consumerStats.msgRateOut);
topicStatsStream.writePair("msgThroughputOut", consumerStats.msgThroughputOut);
topicStatsStream.writePair("msgRateRedeliver", consumerStats.msgRateRedeliver);
if (SubType.Shared.equals(subscription.getType())) {
topicStatsStream.writePair("unackedMessages", consumerStats.unackedMessages);
topicStatsStream.writePair("blockedConsumerOnUnackedMsgs", consumerStats.blockedConsumerOnUnackedMsgs);
}
if (consumerStats.clientVersion != null) {
topicStatsStream.writePair("clientVersion", consumerStats.clientVersion);
}
topicStatsStream.endObject();
}
// Close Consumer stats
topicStatsStream.endList();
// Populate subscription specific stats here
topicStatsStream.writePair("msgBacklog", subscription.getNumberOfEntriesInBacklog());
topicStatsStream.writePair("msgRateExpired", subscription.getExpiredMessageRate());
topicStatsStream.writePair("msgRateOut", subMsgRateOut);
topicStatsStream.writePair("msgThroughputOut", subMsgThroughputOut);
topicStatsStream.writePair("msgRateRedeliver", subMsgRateRedeliver);
topicStatsStream.writePair("numberOfEntriesSinceFirstNotAckedMessage", subscription.getNumberOfEntriesSinceFirstNotAckedMessage());
topicStatsStream.writePair("totalNonContiguousDeletedMessagesRange", subscription.getTotalNonContiguousDeletedMessagesRange());
topicStatsStream.writePair("type", subscription.getTypeString());
if (SubType.Shared.equals(subscription.getType())) {
if (subscription.getDispatcher() instanceof PersistentDispatcherMultipleConsumers) {
PersistentDispatcherMultipleConsumers dispatcher = (PersistentDispatcherMultipleConsumers) subscription.getDispatcher();
topicStatsStream.writePair("blockedSubscriptionOnUnackedMsgs", dispatcher.isBlockedDispatcherOnUnackedMsgs());
topicStatsStream.writePair("unackedMessages", dispatcher.getTotalUnackedMessages());
}
}
// Close consumers
topicStatsStream.endObject();
topicStats.aggMsgRateOut += subMsgRateOut;
topicStats.aggMsgThroughputOut += subMsgThroughputOut;
nsStats.msgBacklog += subscription.getNumberOfEntriesInBacklog();
} catch (Exception e) {
log.error("Got exception when creating consumer stats for subscription {}: {}", subscriptionName, e.getMessage(), e);
}
});
// Close subscription
topicStatsStream.endObject();
// Remaining dest stats.
topicStats.averageMsgSize = topicStats.aggMsgRateIn == 0.0 ? 0.0 : (topicStats.aggMsgThroughputIn / topicStats.aggMsgRateIn);
topicStatsStream.writePair("producerCount", producers.size());
topicStatsStream.writePair("averageMsgSize", topicStats.averageMsgSize);
topicStatsStream.writePair("msgRateIn", topicStats.aggMsgRateIn);
topicStatsStream.writePair("msgRateOut", topicStats.aggMsgRateOut);
topicStatsStream.writePair("msgThroughputIn", topicStats.aggMsgThroughputIn);
topicStatsStream.writePair("msgThroughputOut", topicStats.aggMsgThroughputOut);
topicStatsStream.writePair("storageSize", ledger.getEstimatedBacklogSize());
topicStatsStream.writePair("pendingAddEntriesCount", ((ManagedLedgerImpl) ledger).getPendingAddEntriesCount());
nsStats.msgRateIn += topicStats.aggMsgRateIn;
nsStats.msgRateOut += topicStats.aggMsgRateOut;
nsStats.msgThroughputIn += topicStats.aggMsgThroughputIn;
nsStats.msgThroughputOut += topicStats.aggMsgThroughputOut;
nsStats.storageSize += ledger.getEstimatedBacklogSize();
bundleStats.msgRateIn += topicStats.aggMsgRateIn;
bundleStats.msgRateOut += topicStats.aggMsgRateOut;
bundleStats.msgThroughputIn += topicStats.aggMsgThroughputIn;
bundleStats.msgThroughputOut += topicStats.aggMsgThroughputOut;
bundleStats.cacheSize += ((ManagedLedgerImpl) ledger).getCacheSize();
// Close topic object
topicStatsStream.endObject();
}
use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.
the class ReplicatorStatsTest method testReplicatorStatsAdd.
@Test
public void testReplicatorStatsAdd() {
ReplicatorStats replicatorStats = new ReplicatorStats();
replicatorStats.msgRateIn = 5;
replicatorStats.msgThroughputIn = 10;
replicatorStats.msgRateOut = 5;
replicatorStats.msgThroughputOut = 10;
replicatorStats.msgRateExpired = 3;
replicatorStats.replicationBacklog = 4;
replicatorStats.connected = true;
replicatorStats.replicationDelayInSeconds = 3;
replicatorStats.add(replicatorStats);
Assert.assertEquals(replicatorStats.msgRateIn, 10.0);
Assert.assertEquals(replicatorStats.msgThroughputIn, 20.0);
Assert.assertEquals(replicatorStats.msgRateOut, 10.0);
Assert.assertEquals(replicatorStats.msgThroughputOut, 20.0);
Assert.assertEquals(replicatorStats.msgRateExpired, 6.0);
Assert.assertEquals(replicatorStats.replicationBacklog, 8);
Assert.assertTrue(replicatorStats.connected);
Assert.assertEquals(replicatorStats.replicationDelayInSeconds, 3);
}
use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.
the class PersistentTopicStatsTest method testPersistentTopicStats.
@Test
public void testPersistentTopicStats() {
PersistentTopicStats persistentTopicStats = new PersistentTopicStats();
persistentTopicStats.msgRateIn = 1;
persistentTopicStats.msgThroughputIn = 1;
persistentTopicStats.msgRateOut = 1;
persistentTopicStats.msgThroughputOut = 1;
persistentTopicStats.averageMsgSize = 1;
persistentTopicStats.storageSize = 1;
persistentTopicStats.publishers.add(new PublisherStats());
persistentTopicStats.subscriptions.put("test_ns", new SubscriptionStats());
persistentTopicStats.replication.put("test_ns", new ReplicatorStats());
PersistentTopicStats target = new PersistentTopicStats();
target.add(persistentTopicStats);
assertEquals(persistentTopicStats.msgRateIn, 1.0);
assertEquals(persistentTopicStats.msgThroughputIn, 1.0);
assertEquals(persistentTopicStats.msgRateOut, 1.0);
assertEquals(persistentTopicStats.msgThroughputOut, 1.0);
assertEquals(persistentTopicStats.averageMsgSize, 1.0);
assertEquals(persistentTopicStats.storageSize, 1);
assertEquals(persistentTopicStats.publishers.size(), 1);
assertEquals(persistentTopicStats.subscriptions.size(), 1);
assertEquals(persistentTopicStats.replication.size(), 1);
persistentTopicStats.reset();
assertEquals(persistentTopicStats.msgRateIn, 0.0);
assertEquals(persistentTopicStats.msgThroughputIn, 0.0);
assertEquals(persistentTopicStats.msgRateOut, 0.0);
assertEquals(persistentTopicStats.msgThroughputOut, 0.0);
assertEquals(persistentTopicStats.averageMsgSize, 0.0);
assertEquals(persistentTopicStats.storageSize, 0);
assertEquals(persistentTopicStats.publishers.size(), 0);
assertEquals(persistentTopicStats.subscriptions.size(), 0);
assertEquals(persistentTopicStats.replication.size(), 0);
}
use of org.apache.pulsar.common.policies.data.ReplicatorStats in project incubator-pulsar by apache.
the class ReplicatorStatsTest method testReplicatorStatsNull.
@Test
public void testReplicatorStatsNull() {
ReplicatorStats rs = new ReplicatorStats();
try {
rs.add(null);
Assert.fail("Must fail.");
} catch (NullPointerException ne) {
// ok
}
}
Aggregations