Search in sources :

Example 1 with ConsumerStats

use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats in project incubator-pulsar by apache.

the class WebSocketProxyStats method getStat.

public ProxyTopicStat getStat(String topicName) {
    if (!service().getProducers().containsKey(topicName) && !service().getConsumers().containsKey(topicName) && !service().getReaders().containsKey(topicName)) {
        LOG.warn("topic doesn't exist {}", topicName);
        throw new RestException(Status.NOT_FOUND, "Topic does not exist");
    }
    ProxyTopicStat topicStat = new ProxyTopicStat();
    if (service().getProducers().containsKey(topicName)) {
        service().getProducers().get(topicName).forEach(handler -> {
            ProducerStats stat = new ProducerStats(handler);
            topicStat.producerStats.add(stat);
        });
    }
    if (service().getConsumers().containsKey(topicName)) {
        service().getConsumers().get(topicName).forEach(handler -> {
            topicStat.consumerStats.add(new ConsumerStats(handler));
        });
    }
    if (service().getReaders().containsKey(topicName)) {
        service().getReaders().get(topicName).forEach(handler -> {
            topicStat.consumerStats.add(new ConsumerStats(handler));
        });
    }
    return topicStat;
}
Also used : ProxyTopicStat(org.apache.pulsar.websocket.stats.ProxyTopicStat) ProducerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats) ConsumerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats)

Example 2 with ConsumerStats

use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats in project incubator-pulsar by apache.

the class WebSocketProxyStats method getStat.

public Map<String, ProxyTopicStat> getStat() {
    Map<String, ProxyTopicStat> statMap = Maps.newHashMap();
    service().getProducers().forEach((topicName, handlers) -> {
        ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat());
        handlers.forEach(handler -> topicStat.producerStats.add(new ProducerStats(handler)));
        statMap.put(topicName, topicStat);
    });
    service().getConsumers().forEach((topicName, handlers) -> {
        ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat());
        handlers.forEach(handler -> topicStat.consumerStats.add(new ConsumerStats(handler)));
        statMap.put(topicName, topicStat);
    });
    service().getReaders().forEach((topicName, handlers) -> {
        ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat());
        handlers.forEach(handler -> topicStat.consumerStats.add(new ConsumerStats(handler)));
        statMap.put(topicName, topicStat);
    });
    return statMap;
}
Also used : ProxyTopicStat(org.apache.pulsar.websocket.stats.ProxyTopicStat) ProducerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats) ConsumerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats)

Example 3 with ConsumerStats

use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats in project incubator-pulsar by apache.

the class ProxyPublishConsumeTest method verifyProxyStats.

private void verifyProxyStats(Client client, String baseUrl, String topic) {
    String statUrl = baseUrl + "stats";
    WebTarget webTarget = client.target(statUrl);
    Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
    Response response = (Response) invocationBuilder.get();
    String responseStr = response.readEntity(String.class);
    final Gson gson = new Gson();
    final Map<String, ProxyTopicStat> data = gson.fromJson(responseStr, new TypeToken<Map<String, ProxyTopicStat>>() {
    }.getType());
    // number of topic is loaded = 1
    Assert.assertEquals(data.size(), 1);
    Entry<String, ProxyTopicStat> entry = data.entrySet().iterator().next();
    Assert.assertEquals(entry.getKey(), "persistent://" + topic);
    ProxyTopicStat stats = entry.getValue();
    // number of consumers are connected = 2 (one is reader)
    Assert.assertEquals(stats.consumerStats.size(), 2);
    ConsumerStats consumerStats = stats.consumerStats.iterator().next();
    // Assert.assertTrue(consumerStats.numberOfMsgDelivered > 0);
    Assert.assertNotNull(consumerStats.remoteConnection);
    // number of producers are connected = 1
    Assert.assertEquals(stats.producerStats.size(), 1);
    ProducerStats producerStats = stats.producerStats.iterator().next();
    // Assert.assertTrue(producerStats.numberOfMsgPublished > 0);
    Assert.assertNotNull(producerStats.remoteConnection);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) ProxyTopicStat(org.apache.pulsar.websocket.stats.ProxyTopicStat) ProducerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) ConsumerStats(org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

ProxyTopicStat (org.apache.pulsar.websocket.stats.ProxyTopicStat)3 ConsumerStats (org.apache.pulsar.websocket.stats.ProxyTopicStat.ConsumerStats)3 ProducerStats (org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats)3 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Invocation (javax.ws.rs.client.Invocation)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1