use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats 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;
}
use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats 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;
}
use of org.apache.pulsar.websocket.stats.ProxyTopicStat.ProducerStats 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);
}
Aggregations