Search in sources :

Example 1 with CursorStats

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

the class PersistentTopic method getInternalStats.

public PersistentTopicInternalStats getInternalStats() {
    PersistentTopicInternalStats stats = new PersistentTopicInternalStats();
    ManagedLedgerImpl ml = (ManagedLedgerImpl) ledger;
    stats.entriesAddedCounter = ml.getEntriesAddedCounter();
    stats.numberOfEntries = ml.getNumberOfEntries();
    stats.totalSize = ml.getTotalSize();
    stats.currentLedgerEntries = ml.getCurrentLedgerEntries();
    stats.currentLedgerSize = ml.getCurrentLedgerSize();
    stats.lastLedgerCreatedTimestamp = DateFormatter.format(ml.getLastLedgerCreatedTimestamp());
    if (ml.getLastLedgerCreationFailureTimestamp() != 0) {
        stats.lastLedgerCreationFailureTimestamp = DateFormatter.format(ml.getLastLedgerCreationFailureTimestamp());
    }
    stats.waitingCursorsCount = ml.getWaitingCursorsCount();
    stats.pendingAddEntriesCount = ml.getPendingAddEntriesCount();
    stats.lastConfirmedEntry = ml.getLastConfirmedEntry().toString();
    stats.state = ml.getState().toString();
    stats.ledgers = Lists.newArrayList();
    ml.getLedgersInfo().forEach((id, li) -> {
        LedgerInfo info = new LedgerInfo();
        info.ledgerId = li.getLedgerId();
        info.entries = li.getEntries();
        info.size = li.getSize();
        stats.ledgers.add(info);
    });
    stats.cursors = Maps.newTreeMap();
    ml.getCursors().forEach(c -> {
        ManagedCursorImpl cursor = (ManagedCursorImpl) c;
        CursorStats cs = new CursorStats();
        cs.markDeletePosition = cursor.getMarkDeletedPosition().toString();
        cs.readPosition = cursor.getReadPosition().toString();
        cs.waitingReadOp = cursor.hasPendingReadRequest();
        cs.pendingReadOps = cursor.getPendingReadOpsCount();
        cs.messagesConsumedCounter = cursor.getMessagesConsumedCounter();
        cs.cursorLedger = cursor.getCursorLedger();
        cs.cursorLedgerLastEntry = cursor.getCursorLedgerLastEntry();
        cs.individuallyDeletedMessages = cursor.getIndividuallyDeletedMessages();
        cs.lastLedgerSwitchTimestamp = DateFormatter.format(cursor.getLastLedgerSwitchTimestamp());
        cs.state = cursor.getState();
        cs.numberOfEntriesSinceFirstNotAckedMessage = cursor.getNumberOfEntriesSinceFirstNotAckedMessage();
        cs.totalNonContiguousDeletedMessagesRange = cursor.getTotalNonContiguousDeletedMessagesRange();
        cs.properties = cursor.getProperties();
        stats.cursors.put(cursor.getName(), cs);
    });
    return stats;
}
Also used : LedgerInfo(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.LedgerInfo) ManagedLedgerImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl) ManagedCursorImpl(org.apache.bookkeeper.mledger.impl.ManagedCursorImpl) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) CursorStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats)

Example 2 with CursorStats

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

the class PulsarBrokerStatsClientTest method testTopicInternalStats.

@Test
public void testTopicInternalStats() throws Exception {
    log.info("-- Starting {} test --", methodName);
    final String topicName = "persistent://my-property/use/my-ns/my-topic1";
    final String subscriptionName = "my-subscriber-name";
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subscriptionName).subscribe();
    Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).create();
    final int numberOfMsgs = 1000;
    for (int i = 0; i < numberOfMsgs; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Message<byte[]> msg = null;
    int count = 0;
    for (int i = 0; i < numberOfMsgs; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        if (msg != null && count++ % 2 == 0) {
            consumer.acknowledge(msg);
        }
    }
    PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getTopic(topicName).get();
    PersistentTopicInternalStats internalStats = topic.getInternalStats();
    CursorStats cursor = internalStats.cursors.get(subscriptionName);
    assertEquals(cursor.numberOfEntriesSinceFirstNotAckedMessage, numberOfMsgs);
    assertTrue(cursor.totalNonContiguousDeletedMessagesRange > 0 && (cursor.totalNonContiguousDeletedMessagesRange) < numberOfMsgs / 2);
    producer.close();
    consumer.close();
    log.info("-- Exiting {} test --", methodName);
}
Also used : PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) CursorStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats) Test(org.testng.annotations.Test)

Example 3 with CursorStats

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

the class NonPersistentTopic method getInternalStats.

public PersistentTopicInternalStats getInternalStats() {
    PersistentTopicInternalStats stats = new PersistentTopicInternalStats();
    stats.entriesAddedCounter = ENTRIES_ADDED_COUNTER_UPDATER.get(this);
    stats.cursors = Maps.newTreeMap();
    subscriptions.forEach((name, subs) -> stats.cursors.put(name, new CursorStats()));
    replicators.forEach((name, subs) -> stats.cursors.put(name, new CursorStats()));
    return stats;
}
Also used : PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) CursorStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats)

Aggregations

PersistentTopicInternalStats (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats)3 CursorStats (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.CursorStats)3 ManagedCursorImpl (org.apache.bookkeeper.mledger.impl.ManagedCursorImpl)1 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1 LedgerInfo (org.apache.pulsar.common.policies.data.PersistentTopicInternalStats.LedgerInfo)1 Test (org.testng.annotations.Test)1