Search in sources :

Example 6 with ConsumerStats

use of org.apache.pulsar.common.policies.data.ConsumerStats in project incubator-pulsar by apache.

the class NonPersistentTopic 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();
    // 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");
            subscription.getDispatcher().getMesssageDropRate().calculateRate();
            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("type", subscription.getTypeString());
            if (subscription.getDispatcher() != null) {
                topicStatsStream.writePair("msgDropRate", subscription.getDispatcher().getMesssageDropRate().getRate());
            }
            // 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);
    nsStats.msgRateIn += topicStats.aggMsgRateIn;
    nsStats.msgRateOut += topicStats.aggMsgRateOut;
    nsStats.msgThroughputIn += topicStats.aggMsgThroughputIn;
    nsStats.msgThroughputOut += topicStats.aggMsgThroughputOut;
    bundleStats.msgRateIn += topicStats.aggMsgRateIn;
    bundleStats.msgRateOut += topicStats.aggMsgRateOut;
    bundleStats.msgThroughputIn += topicStats.aggMsgThroughputIn;
    bundleStats.msgThroughputOut += topicStats.aggMsgThroughputOut;
    // Close topic object
    topicStatsStream.endObject();
}
Also used : Consumer(org.apache.pulsar.broker.service.Consumer) NonPersistentPublisherStats(org.apache.pulsar.common.policies.data.NonPersistentPublisherStats) PublisherStats(org.apache.pulsar.common.policies.data.PublisherStats) ConsumerStats(org.apache.pulsar.common.policies.data.ConsumerStats) NonPersistentTopicStats(org.apache.pulsar.common.policies.data.NonPersistentTopicStats) NamingException(org.apache.pulsar.broker.service.BrokerServiceException.NamingException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) UnsupportedVersionException(org.apache.pulsar.broker.service.BrokerServiceException.UnsupportedVersionException) ProducerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ProducerBusyException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) ServerMetadataException(org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException) KeeperException(org.apache.zookeeper.KeeperException) BrokerServiceException(org.apache.pulsar.broker.service.BrokerServiceException) TopicFencedException(org.apache.pulsar.broker.service.BrokerServiceException.TopicFencedException) TopicBusyException(org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException) ConsumerBusyException(org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)

Example 7 with ConsumerStats

use of org.apache.pulsar.common.policies.data.ConsumerStats in project incubator-pulsar by apache.

the class NonPersistentSubscription method getStats.

public NonPersistentSubscriptionStats getStats() {
    NonPersistentSubscriptionStats subStats = new NonPersistentSubscriptionStats();
    NonPersistentDispatcher dispatcher = this.dispatcher;
    if (dispatcher != null) {
        dispatcher.getConsumers().forEach(consumer -> {
            ConsumerStats consumerStats = consumer.getStats();
            subStats.consumers.add(consumerStats);
            subStats.msgRateOut += consumerStats.msgRateOut;
            subStats.msgThroughputOut += consumerStats.msgThroughputOut;
            subStats.msgRateRedeliver += consumerStats.msgRateRedeliver;
        });
    }
    subStats.type = getType();
    subStats.msgDropRate = dispatcher.getMesssageDropRate().getRate();
    return subStats;
}
Also used : NonPersistentSubscriptionStats(org.apache.pulsar.common.policies.data.NonPersistentSubscriptionStats) ConsumerStats(org.apache.pulsar.common.policies.data.ConsumerStats)

Aggregations

ConsumerStats (org.apache.pulsar.common.policies.data.ConsumerStats)7 PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)3 BrokerServiceException (org.apache.pulsar.broker.service.BrokerServiceException)2 ConsumerBusyException (org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException)2 NamingException (org.apache.pulsar.broker.service.BrokerServiceException.NamingException)2 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)2 ProducerBusyException (org.apache.pulsar.broker.service.BrokerServiceException.ProducerBusyException)2 ServerMetadataException (org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException)2 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)2 TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)2 TopicFencedException (org.apache.pulsar.broker.service.BrokerServiceException.TopicFencedException)2 UnsupportedVersionException (org.apache.pulsar.broker.service.BrokerServiceException.UnsupportedVersionException)2 Consumer (org.apache.pulsar.broker.service.Consumer)2 PublisherStats (org.apache.pulsar.common.policies.data.PublisherStats)2 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)2 KeeperException (org.apache.zookeeper.KeeperException)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 ManagedLedgerAlreadyClosedException (org.apache.bookkeeper.mledger.ManagedLedgerException.ManagedLedgerAlreadyClosedException)1