use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.
the class TestMetricPublisher method dumpRecordings.
void dumpRecordings(String instanceName, StringBuilder sb) {
// if there is no recording we wait for bounded time to record one blob with metrics
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
while (!recordedMetrics && System.currentTimeMillis() < deadline) {
sleepMillis(250);
}
sb.append("\n");
final int oldestSlotIdx;
final byte[][] slotsCopy = new byte[slots][];
synchronized (blobs) {
oldestSlotIdx = seq % slots;
System.arraycopy(blobs, 0, slotsCopy, 0, slots);
}
for (int i = 0; i < slots; i++) {
int currentSlot = (oldestSlotIdx + i) % slots;
byte[] blob = slotsCopy[currentSlot];
if (blob != null) {
Date date = new Date(timestamps[currentSlot]);
MetricsCompressor.extractMetrics(blob, new MetricConsumer() {
@Override
public void consumeLong(MetricDescriptor descriptor, long value) {
appendMetric(sb, instanceName, date, descriptor).append(value).append("\n");
}
@Override
public void consumeDouble(MetricDescriptor descriptor, double value) {
appendMetric(sb, instanceName, date, descriptor).append(value).append("\n");
}
private StringBuilder appendMetric(StringBuilder sb, String instanceName, Date date, MetricDescriptor descriptor) {
return sb.append('[').append(instanceName).append("] ").append('[').append(formatter.format(date)).append("] ").append(descriptor.metricString()).append('=');
}
});
}
}
}
use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.
the class MetricsCompressorTest method testTwoMetrics_fullDifferent.
@Test
public void testTwoMetrics_fullDifferent() {
DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
MetricsCompressor compressor = new MetricsCompressor();
MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT).withTag("tag0", "tag0Value");
MetricDescriptor metric2 = supplier.get().withPrefix("anotherPrefix").withMetric("anotherMetricName").withDiscriminator("anotherDs", "anotherDsName1").withUnit(PERCENT).withTag("anotherTag0", "anotherTag0Value");
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.MetricConsumer in project hazelcast by hazelcast.
the class MetricsCompressorTest method when_tooLongWord_then_metricIgnored.
private void when_tooLongWord_then_metricIgnored(MetricDescriptor badDescriptor) {
MetricsCompressor compressor = new MetricsCompressor();
try {
compressor.addLong(badDescriptor, 42);
fail("should have failed");
} catch (LongWordException ignored) {
}
assertEquals(0, compressor.count());
// add a good descriptor after a bad one to check that the tmp streams are reset properly
MetricDescriptor goodDescriptor = supplier.get();
compressor.addLong(goodDescriptor, 43);
assertEquals(1, compressor.count());
byte[] blob = compressor.getBlobAndReset();
// try to decompress the metrics to see that a valid data were produced
MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
verify(metricConsumerMock).consumeLong(goodDescriptor, 43L);
verifyNoMoreInteractions(metricConsumerMock);
verify(supplierSpy, times(1)).get();
}
use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.
the class MetricsCompressorTest method testSingleMetricWithoutUnit.
@Test
public void testSingleMetricWithoutUnit() {
DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
MetricsCompressor compressor = new MetricsCompressor();
MetricDescriptor originalMetric = supplier.get().withMetric("metricName").withMetric("metricName").withDiscriminator("ds", "dsName1").withTag("tag0", "tag0Value");
compressor.addLong(originalMetric, 42L);
byte[] blob = compressor.getBlobAndReset();
MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
verify(metricConsumerMock).consumeLong(originalMetric, 42L);
verifyNoMoreInteractions(metricConsumerMock);
verify(supplierSpy, only()).get();
}
use of com.hazelcast.internal.metrics.MetricConsumer in project hazelcast by hazelcast.
the class MetricsServiceTest method testReadMetricsReadsOnlyLastCollection.
@Test
public void testReadMetricsReadsOnlyLastCollection() throws Exception {
// configure metrics to keep the result only of the last collection cycle
config.getMetricsConfig().setCollectionFrequencySeconds(5).getManagementCenterConfig().setRetentionSeconds(1);
MetricsService metricsService = prepareMetricsService();
// this collection will be dropped
testProbeSource.update(1, 1.5D);
metricsService.collectMetrics();
testProbeSource.update(2, 5.5D);
metricsService.collectMetrics();
MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
readMetrics(metricsService, 0, metricConsumerMock);
InOrder inOrderLong = inOrder(metricConsumerMock);
InOrder inOrderDouble = inOrder(metricConsumerMock);
MetricDescriptor doubleDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("doubleValue").withUnit(COUNT);
inOrderDouble.verify(metricConsumerMock).consumeDouble(doubleDescriptor, 5.5D);
inOrderDouble.verify(metricConsumerMock, never()).consumeDouble(eq(doubleDescriptor), anyDouble());
MetricDescriptor longDescriptor = DEFAULT_DESCRIPTOR_SUPPLIER.get().withPrefix("test").withMetric("longValue").withUnit(COUNT);
inOrderLong.verify(metricConsumerMock).consumeLong(longDescriptor, 2);
inOrderLong.verify(metricConsumerMock, never()).consumeLong(eq(longDescriptor), anyLong());
}
Aggregations