use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class MetricsServiceTest method testUpdatesRenderedInOrder.
@Test
public void testUpdatesRenderedInOrder() {
MetricsService metricsService = prepareMetricsService();
testProbeSource.update(1, 1.5D);
metricsService.collectMetrics(metricsCollectorMock);
testProbeSource.update(2, 5.5D);
metricsService.collectMetrics(metricsCollectorMock);
InOrder inOrderLong = inOrder(metricsCollectorMock);
InOrder inOrderDouble = inOrder(metricsCollectorMock);
MetricDescriptor descRoot = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(COUNT);
MetricDescriptor descLongValue = descRoot.copy().withMetric("longValue");
inOrderLong.verify(metricsCollectorMock).collectLong(descLongValue, 1);
inOrderLong.verify(metricsCollectorMock).collectLong(descLongValue, 2);
inOrderLong.verify(metricsCollectorMock, never()).collectLong(eq(descLongValue), anyLong());
MetricDescriptor descDoubleValue = descRoot.copy().withMetric("doubleValue");
inOrderDouble.verify(metricsCollectorMock).collectDouble(descDoubleValue, 1.5D);
inOrderDouble.verify(metricsCollectorMock).collectDouble(descDoubleValue, 5.5D);
inOrderDouble.verify(metricsCollectorMock, never()).collectDouble(eq(descDoubleValue), anyDouble());
}
use of com.hazelcast.internal.metrics.MetricDescriptor 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());
}
use of com.hazelcast.internal.metrics.MetricDescriptor 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();
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testDirectLong.
@Test
public void testDirectLong() {
CapturingCollector capturingCollector = new CapturingCollector();
MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), INFO);
metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42));
metricsRegistry.collect(capturingCollector);
MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
Number number = capturingCollector.captures().get(expectedDescriptor).singleCapturedValue();
assertInstanceOf(Long.class, number);
assertEquals(42, number.longValue());
}
use of com.hazelcast.internal.metrics.MetricDescriptor 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());
}
Aggregations