use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class JmxPublisherTest method when_singleMetricWithModule.
@Test
public void when_singleMetricWithModule() throws Exception {
MetricDescriptor descriptor = newDescriptor().withMetric("c").withTag("tag1", "a").withTag("module", MODULE_NAME);
jmxPublisher.publishLong(descriptor, 1L);
helper.assertMBeans(singletonList(metric(domainPrefix + "." + MODULE_NAME + ":type=Metrics,instance=inst1,tag0=\"tag1=a\"", singletonList(longValue("c", 1L)))));
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class JmxPublisherTest method when_singleMetricUpdates.
@Test
public void when_singleMetricUpdates() throws Exception {
MetricDescriptor descriptor = newDescriptor().withMetric("c").withTag("tag1", "a").withTag("tag2", "b");
jmxPublisher.publishLong(descriptor, 1L);
jmxPublisher.whenComplete();
helper.assertMBeans(singletonList(metric(domainPrefix + ":type=Metrics,instance=inst1,tag0=\"tag1=a\",tag1=\"tag2=b\"", singletonList(longValue("c", 1L)))));
jmxPublisher.publishLong(descriptor, 2L);
helper.assertMBeans(singletonList(metric(domainPrefix + ":type=Metrics,instance=inst1,tag0=\"tag1=a\",tag1=\"tag2=b\"", singletonList(longValue("c", 2L)))));
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class ClientMetricsTest method assertClientMetricsObservedEventually.
private void assertClientMetricsObservedEventually(HazelcastInstance memberInstance, MetricsRegistry metricsRegistry, String prefix, String metric, ProbeUnit unit) {
assertTrueEventually(() -> {
CapturingCollector collector = new CapturingCollector();
metricsRegistry.collect(collector);
ClientEngine clientEngine = getNode(memberInstance).getClientEngine();
Collection<Client> clients = clientEngine.getClients();
assertEquals(2, clients.size());
for (Client client : clients) {
UUID clientUuid = client.getUuid();
ClientStatistics clientStatistics = clientEngine.getClientStatistics().get(clientUuid);
assertNotNull(clientStatistics);
long timestamp = clientStatistics.timestamp();
MetricDescriptor expectedDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix(prefix).withMetric(metric).withUnit(unit).withTag("client", clientUuid.toString()).withTag("clientname", client.getName()).withTag("timestamp", Long.toString(timestamp)).withExcludedTargets(asList(MetricTarget.values())).withIncludedTarget(MANAGEMENT_CENTER);
assertContains(collector.captures().keySet(), expectedDescriptor);
}
});
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class ClientEndpointImpl method provideDynamicMetrics.
@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
ClientStatistics clientStatistics = statsRef.get();
if (clientStatistics != null && clientStatistics.metricsBlob() != null) {
byte[] metricsBlob = clientStatistics.metricsBlob();
if (metricsBlob.length == 0) {
// zero length means that the client does not support the new format
return;
}
long timestamp = clientStatistics.timestamp();
MetricConsumer consumer = new MetricConsumer() {
@Override
public void consumeLong(MetricDescriptor descriptor, long value) {
context.collect(enhanceDescriptor(descriptor, timestamp), value);
}
@Override
public void consumeDouble(MetricDescriptor descriptor, double value) {
context.collect(enhanceDescriptor(descriptor, timestamp), value);
}
private MetricDescriptor enhanceDescriptor(MetricDescriptor descriptor, long timestamp) {
return descriptor.withExcludedTargets(MetricTarget.ALL_TARGETS).withIncludedTarget(MANAGEMENT_CENTER).withTag(METRICS_TAG_CLIENT, getUuid().toString()).withTag(METRICS_TAG_CLIENTNAME, clientName).withTag(METRICS_TAG_TIMESTAMP, Long.toString(timestamp));
}
};
MetricsCompressor.extractMetrics(metricsBlob, consumer);
}
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class OperationRunnerImpl method provideStaticMetrics.
@Override
public void provideStaticMetrics(MetricsRegistry registry) {
if (partitionId >= 0) {
MetricDescriptor descriptor = registry.newMetricDescriptor().withPrefix(OPERATION_PREFIX_PARTITION).withDiscriminator(OPERATION_DISCRIMINATOR_PARTITIONID, String.valueOf(partitionId));
registry.registerStaticMetrics(descriptor, this);
} else if (partitionId == -1) {
MetricDescriptor descriptor = registry.newMetricDescriptor().withPrefix(OPERATION_PREFIX_GENERIC).withDiscriminator(OPERATION_DISCRIMINATOR_GENERICID, String.valueOf(genericId));
registry.registerStaticMetrics(descriptor, this);
} else {
registry.registerStaticMetrics(this, OPERATION_PREFIX_ADHOC);
}
}
Aggregations