Search in sources :

Example 6 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class ZooKeeperClientAspectJTest method testZkOpStatsMetrics.

/**
 * Verifies that aspect-advice calculates the latency of of zk-operation and updates PulsarStats
 *
 * @throws Exception
 */
@Test(enabled = false, timeOut = 7000)
public void testZkOpStatsMetrics() throws Exception {
    OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().build();
    ZooKeeperClientFactory zkf = new ZookeeperBkClientFactoryImpl(executor);
    CompletableFuture<ZooKeeper> zkFuture = zkf.create("127.0.0.1:" + LOCAL_ZOOKEEPER_PORT, SessionType.ReadWrite, (int) ZOOKEEPER_SESSION_TIMEOUT_MILLIS);
    localZkc = zkFuture.get(ZOOKEEPER_SESSION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    MockPulsar mockPulsar = new MockPulsar(localZkc);
    mockPulsar.setup();
    try {
        PulsarClient pulsarClient = mockPulsar.getClient();
        PulsarService pulsar = mockPulsar.getPulsar();
        pulsarClient.newProducer().topic("persistent://my-property/use/my-ns/my-topic1").create();
        Metrics zkOpMetric = getMetric(pulsar, "zk_write_latency");
        Assert.assertNotNull(zkOpMetric);
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_rate_s"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_95percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_99_99_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_99_9_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_99_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_mean_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_write_time_median_ms"));
        zkOpMetric = getMetric(pulsar, "zk_read_latency");
        Assert.assertNotNull(zkOpMetric);
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_rate_s"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_95percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_99_99_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_99_9_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_99_percentile_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_mean_ms"));
        Assert.assertTrue(zkOpMetric.getMetrics().containsKey("brk_zk_read_time_median_ms"));
        CountDownLatch createLatch = new CountDownLatch(1);
        CountDownLatch deleteLatch = new CountDownLatch(1);
        CountDownLatch readLatch = new CountDownLatch(1);
        CountDownLatch existLatch = new CountDownLatch(1);
        localZkc.create("/createTest", "data".getBytes(), Acl, CreateMode.EPHEMERAL, (rc, path, ctx, name) -> {
            createLatch.countDown();
        }, "create");
        localZkc.delete("/deleteTest", -1, (rc, path, ctx) -> {
            deleteLatch.countDown();
        }, "delete");
        localZkc.exists("/createTest", null, (int rc, String path, Object ctx, Stat stat) -> {
            existLatch.countDown();
        }, null);
        localZkc.getData("/createTest", null, (int rc, String path, Object ctx, byte[] data, Stat stat) -> {
            readLatch.countDown();
        }, null);
        createLatch.await();
        deleteLatch.await();
        existLatch.await();
        readLatch.await();
        Thread.sleep(10);
        BrokerService brokerService = pulsar.getBrokerService();
        brokerService.updateRates();
        List<Metrics> metrics = brokerService.getTopicMetrics();
        AtomicDouble writeRate = new AtomicDouble();
        AtomicDouble readRate = new AtomicDouble();
        metrics.forEach(m -> {
            if ("zk_write_latency".equalsIgnoreCase(m.getDimension("metric"))) {
                writeRate.set((double) m.getMetrics().get("brk_zk_write_latency_rate_s"));
            } else if ("zk_read_latency".equalsIgnoreCase(m.getDimension("metric"))) {
                readRate.set((double) m.getMetrics().get("brk_zk_read_latency_rate_s"));
            }
        });
        Assert.assertTrue(readRate.get() > 0);
        Assert.assertTrue(writeRate.get() > 0);
    } finally {
        mockPulsar.cleanup();
        if (localZkc != null) {
            localZkc.close();
        }
        executor.shutdown();
    }
}
Also used : AtomicDouble(com.google.common.util.concurrent.AtomicDouble) CountDownLatch(java.util.concurrent.CountDownLatch) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory) Metrics(org.apache.pulsar.common.stats.Metrics) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) PulsarService(org.apache.pulsar.broker.PulsarService) ZookeeperBkClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperBkClientFactoryImpl) PulsarClient(org.apache.pulsar.client.api.PulsarClient) BrokerService(org.apache.pulsar.broker.service.BrokerService) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Test(org.testng.annotations.Test)

Example 7 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class ZooKeeperClientAspectJTest method getMetric.

private Metrics getMetric(PulsarService pulsar, String dimension) {
    BrokerService brokerService = pulsar.getBrokerService();
    brokerService.updateRates();
    for (Metrics metric : brokerService.getTopicMetrics()) {
        if (dimension.equalsIgnoreCase(metric.getDimension("metric"))) {
            return metric;
        }
    }
    return null;
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) BrokerService(org.apache.pulsar.broker.service.BrokerService)

Example 8 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class AdminTest method brokerStats.

@Test
void brokerStats() throws Exception {
    doReturn("client-id").when(brokerStats).clientAppId();
    Collection<Metrics> metrics = brokerStats.getMetrics();
    assertNotNull(metrics);
    LocalBrokerData loadReport = (LocalBrokerData) brokerStats.getLoadReport();
    assertNotNull(loadReport);
    assertNotNull(loadReport.getCpu());
    Collection<Metrics> mBeans = brokerStats.getMBeans();
    assertTrue(!mBeans.isEmpty());
    AllocatorStats allocatorStats = brokerStats.getAllocatorStats("default");
    assertNotNull(allocatorStats);
    Map<String, Map<String, PendingBookieOpsStats>> bookieOpsStats = brokerStats.getPendingBookieOpsStats();
    assertTrue(bookieOpsStats.isEmpty());
    StreamingOutput topic = brokerStats.getTopics2();
    assertNotNull(topic);
    try {
        brokerStats.getBrokerResourceAvailability("prop", "use", "ns2");
        fail("should have failed as ModularLoadManager doesn't support it");
    } catch (RestException re) {
    // Ok
    }
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) AllocatorStats(org.apache.pulsar.common.stats.AllocatorStats) RestException(org.apache.pulsar.broker.web.RestException) StreamingOutput(javax.ws.rs.core.StreamingOutput) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 9 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class MBeanStatsGenerator method generate.

private Collection<Metrics> generate() {
    List<Metrics> metricsCollection = new ArrayList<Metrics>();
    @SuppressWarnings("unchecked") Set<ObjectInstance> instances = mbs.queryMBeans(null, null);
    for (ObjectInstance instance : instances) {
        String beanName = instance.getObjectName().toString();
        // skip GC MBean to avoid recursion
        if (beanName.startsWith("java.lang:type=GarbageCollector")) {
            continue;
        }
        Metrics metrics = convert(instance);
        if (metrics != null) {
            metricsCollection.add(metrics);
        }
    }
    return metricsCollection;
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics) ArrayList(java.util.ArrayList) ObjectInstance(javax.management.ObjectInstance)

Example 10 with Metrics

use of org.apache.pulsar.common.stats.Metrics in project incubator-pulsar by apache.

the class NamespaceStats method add.

public Metrics add(String namespace) {
    Map<String, String> dimensionMap = Maps.newHashMap();
    dimensionMap.put("namespace", namespace);
    Metrics dMetrics = Metrics.create(dimensionMap);
    dMetrics.put("brk_in_rate", msgRateIn);
    dMetrics.put("brk_in_tp_rate", msgThroughputIn);
    dMetrics.put("brk_out_rate", msgRateOut);
    dMetrics.put("brk_out_tp_rate", msgThroughputOut);
    dMetrics.put("brk_storage_size", storageSize);
    dMetrics.put("brk_no_of_producers", producerCount);
    dMetrics.put("brk_no_of_subscriptions", subsCount);
    dMetrics.put("brk_no_of_replicators", replicatorCount);
    dMetrics.put("brk_no_of_consumers", consumerCount);
    dMetrics.put("brk_msg_backlog", msgBacklog);
    dMetrics.put("brk_replication_backlog", msgReplBacklog);
    return dMetrics;
}
Also used : Metrics(org.apache.pulsar.common.stats.Metrics)

Aggregations

Metrics (org.apache.pulsar.common.stats.Metrics)18 Test (org.testng.annotations.Test)4 PoolArenaMetric (io.netty.buffer.PoolArenaMetric)3 PoolChunkListMetric (io.netty.buffer.PoolChunkListMetric)3 PoolChunkMetric (io.netty.buffer.PoolChunkMetric)3 ManagedLedgerImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl)3 HashMap (java.util.HashMap)2 BrokerService (org.apache.pulsar.broker.service.BrokerService)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 ByteBuf (io.netty.buffer.ByteBuf)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1