Search in sources :

Example 6 with MetricConsumer

use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.

the class MetricsServiceTest method testReadMetricsThrowsOnFutureSequence.

@Test
public void testReadMetricsThrowsOnFutureSequence() throws Exception {
    MetricsService metricsService = prepareMetricsService();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    long futureSequence = 42;
    long headSequence = 0;
    expectedException.expect(ExecutionException.class);
    expectedException.expectCause(Is.is(CoreMatchers.instanceOf(IllegalArgumentException.class)));
    expectedException.expectMessage(Long.toString(futureSequence));
    expectedException.expectMessage(Long.toString(headSequence));
    readMetrics(metricsService, futureSequence, metricConsumerMock);
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with MetricConsumer

use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.

the class MetricsServiceTest method testExclusion.

@Test
public void testExclusion() throws Exception {
    // configure metrics to keep the result only of the last collection cycle
    config.getMetricsConfig().setCollectionFrequencySeconds(5).getManagementCenterConfig().setRetentionSeconds(1);
    ExclusionProbeSource metricsSource = new ExclusionProbeSource();
    metricsRegistry.registerStaticMetrics(metricsSource, "testExclusion");
    MetricsService metricsService = prepareMetricsService();
    metricsSource.update(1, 2, 1.5D, 2.5D);
    metricsService.collectMetrics();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    readMetrics(metricsService, 0, metricConsumerMock);
    MetricDescriptor longRoot = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("testExclusion").withUnit(COUNT);
    verify(metricConsumerMock).consumeLong(longRoot.copy().withMetric("notExcludedLong"), 1);
    verify(metricConsumerMock, never()).consumeLong(eq(longRoot.copy().withMetric("excludedLong")), anyLong());
    MetricDescriptor doubleRoot = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("testExclusion").withUnit(COUNT);
    verify(metricConsumerMock).consumeDouble(doubleRoot.copy().withMetric("notExcludedDouble"), 1.5D);
    verify(metricConsumerMock, never()).consumeDouble(eq(doubleRoot.copy().withMetric("excludedDouble")), anyDouble());
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with MetricConsumer

use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.

the class MetricsCompressorTest method testTwoMetrics_secondWithoutTags.

@Test
public void testTwoMetrics_secondWithoutTags() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT);
    MetricDescriptor metric2 = metric1.copy().withMetric("metricName2");
    metric1.withTag("tag0", "tag0Value");
    compressor.addLong(metric1, 42L);
    compressor.addLong(metric2, 43L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeLong(metric1, 42L);
    verify(metricConsumerMock).consumeLong(metric2, 43L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, times(2)).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with MetricConsumer

use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.

the class MetricsServiceTest method testReadMetricsReadsLastTwoCollections.

@Test
public void testReadMetricsReadsLastTwoCollections() throws Exception {
    // configure metrics to keep the result of the last 2 collection cycles
    config.getMetricsConfig().setCollectionFrequencySeconds(1).getManagementCenterConfig().setRetentionSeconds(2);
    MetricsService metricsService = prepareMetricsService();
    testProbeSource.update(1, 1.5D);
    metricsService.collectMetrics();
    testProbeSource.update(2, 5.5D);
    metricsService.collectMetrics();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    InOrder inOrderLong = inOrder(metricConsumerMock);
    InOrder inOrderDouble = inOrder(metricConsumerMock);
    readMetrics(metricsService, 0, metricConsumerMock);
    MetricDescriptor longDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("longValue").withUnit(COUNT);
    inOrderLong.verify(metricConsumerMock).consumeLong(longDescriptor, 1);
    inOrderLong.verify(metricConsumerMock).consumeLong(longDescriptor, 2);
    inOrderLong.verify(metricConsumerMock, never()).consumeLong(eq(longDescriptor), anyLong());
    MetricDescriptor doubleDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("doubleValue").withUnit(COUNT);
    inOrderDouble.verify(metricConsumerMock).consumeDouble(doubleDescriptor, 1.5D);
    inOrderDouble.verify(metricConsumerMock).consumeDouble(doubleDescriptor, 5.5D);
    inOrderDouble.verify(metricConsumerMock, never()).consumeDouble(eq(doubleDescriptor), anyDouble());
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) InOrder(org.mockito.InOrder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with MetricConsumer

use of com.hazelcast.internal.metrics.MetricConsumer 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)

Aggregations

MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)19 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)16 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 InOrder (org.mockito.InOrder)2 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)1 ProbeUnit (com.hazelcast.internal.metrics.ProbeUnit)1 Date (java.util.Date)1