Search in sources :

Example 26 with MetricDescriptor

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)))));
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with MetricDescriptor

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)))));
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with MetricDescriptor

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);
        }
    });
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ClientEngine(com.hazelcast.client.impl.ClientEngine) ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics) CapturingCollector(com.hazelcast.internal.metrics.impl.CapturingCollector) Client(com.hazelcast.client.Client) UUID(java.util.UUID)

Example 29 with MetricDescriptor

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);
    }
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics)

Example 30 with MetricDescriptor

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);
    }
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor)

Aggregations

MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)58 QuickTest (com.hazelcast.test.annotation.QuickTest)27 Test (org.junit.Test)27 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)19 CPGroupId (com.hazelcast.cp.CPGroupId)7 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)6 Map (java.util.Map)4 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)3 InOrder (org.mockito.InOrder)3 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)2 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)2 ProbeUnit (com.hazelcast.internal.metrics.ProbeUnit)2 UUID (java.util.UUID)2 Client (com.hazelcast.client.Client)1 ClientEngine (com.hazelcast.client.impl.ClientEngine)1 ClientContext (com.hazelcast.client.impl.spi.ClientContext)1 ProxyManager (com.hazelcast.client.impl.spi.ProxyManager)1 Member (com.hazelcast.cluster.Member)1 IAtomicLong (com.hazelcast.cp.IAtomicLong)1