Search in sources :

Example 41 with MetricDescriptor

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

the class MetricsCollectionCycle method extractAndCollectDynamicMetrics.

private void extractAndCollectDynamicMetrics(MetricDescriptor descriptor, Object source) {
    SourceMetadata metadata = lookupMetadataFn.apply(source.getClass());
    for (MethodProbe methodProbe : metadata.methods()) {
        if (methodProbe.probe.level().isEnabled(minimumLevel)) {
            MetricDescriptor descriptorCopy = descriptor.copy().withUnit(methodProbe.probe.unit()).withMetric(methodProbe.getProbeName()).withExcludedTargets(extractExcludedTargets(methodProbe));
            lookupMetricValueCatcher(descriptorCopy).catchMetricValue(collectionId, source, methodProbe);
            collect(descriptorCopy, source, methodProbe);
        }
    }
    for (FieldProbe fieldProbe : metadata.fields()) {
        if (fieldProbe.probe.level().isEnabled(minimumLevel)) {
            MetricDescriptor descriptorCopy = descriptor.copy().withUnit(fieldProbe.probe.unit()).withMetric(fieldProbe.getProbeName()).withExcludedTargets(extractExcludedTargets(fieldProbe));
            lookupMetricValueCatcher(descriptorCopy).catchMetricValue(collectionId, source, fieldProbe);
            collect(descriptorCopy, source, fieldProbe);
        }
    }
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor)

Example 42 with MetricDescriptor

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

the class NioNetworking method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    for (Channel channel : channels) {
        String pipelineId = channel.localSocketAddress() + "->" + channel.remoteSocketAddress();
        MetricDescriptor descriptorIn = descriptor.copy().withPrefix(TCP_PREFIX_CONNECTION_IN).withDiscriminator(TCP_DISCRIMINATOR_PIPELINEID, pipelineId);
        context.collect(descriptorIn, channel.inboundPipeline());
        MetricDescriptor descriptorOut = descriptor.copy().withPrefix(TCP_PREFIX_CONNECTION_OUT).withDiscriminator(TCP_DISCRIMINATOR_PIPELINEID, pipelineId);
        context.collect(descriptorOut, channel.outboundPipeline());
    }
    NioThread[] inputThreads = this.inputThreads;
    if (inputThreads != null) {
        for (NioThread nioThread : inputThreads) {
            MetricDescriptor descriptorInThread = descriptor.copy().withPrefix(TCP_PREFIX_INPUTTHREAD).withDiscriminator(TCP_DISCRIMINATOR_THREAD, nioThread.getName());
            context.collect(descriptorInThread, nioThread);
        }
    }
    NioThread[] outputThreads = this.outputThreads;
    if (outputThreads != null) {
        for (NioThread nioThread : outputThreads) {
            MetricDescriptor descriptorOutThread = descriptor.copy().withPrefix(TCP_PREFIX_OUTPUTTHREAD).withDiscriminator(TCP_DISCRIMINATOR_THREAD, nioThread.getName());
            context.collect(descriptorOutThread, nioThread);
        }
    }
    IOBalancer ioBalancer = this.ioBalancer;
    if (ioBalancer != null) {
        MetricDescriptor descriptorBalancer = descriptor.copy().withPrefix(TCP_PREFIX_BALANCER);
        context.collect(descriptorBalancer, ioBalancer);
    }
    MetricDescriptor descriptorTcp = descriptor.copy().withPrefix(TCP_PREFIX);
    context.collect(descriptorTcp, this);
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) IOBalancer(com.hazelcast.internal.networking.nio.iobalancer.IOBalancer) SocketChannel(java.nio.channels.SocketChannel) Channel(com.hazelcast.internal.networking.Channel)

Example 43 with MetricDescriptor

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

the class TcpServerConnectionManager method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    MetricDescriptor rootDescriptor = descriptor.withPrefix(TCP_PREFIX_CONNECTION);
    if (endpointQualifier == null) {
        context.collect(rootDescriptor.copy(), this);
    } else {
        context.collect(rootDescriptor.copy().withDiscriminator(TCP_DISCRIMINATOR_ENDPOINT, endpointQualifier.toMetricsPrefixString()), this);
    }
    for (TcpServerConnection connection : connections) {
        if (connection.getRemoteAddress() != null) {
            context.collect(rootDescriptor.copy().withDiscriminator(TCP_DISCRIMINATOR_ENDPOINT, connection.getRemoteAddress().toString()), connection);
        }
    }
    int clientCount = 0;
    int textCount = 0;
    for (Plane plane : planes) {
        for (Map.Entry<UUID, TcpServerConnection> entry : plane.connections()) {
            UUID uuid = entry.getKey();
            TcpServerConnection connection = entry.getValue();
            if (connection.isClient()) {
                clientCount++;
                String connectionType = connection.getConnectionType();
                if (REST_CLIENT.equals(connectionType) || MEMCACHE_CLIENT.equals(connectionType)) {
                    textCount++;
                }
            }
            if (connection.getRemoteAddress() != null) {
                context.collect(rootDescriptor.copy().withDiscriminator(TCP_DISCRIMINATOR_BINDADDRESS, uuid.toString()).withTag(TCP_TAG_ENDPOINT, connection.getRemoteAddress().toString()), connection);
            }
        }
    }
    if (endpointConfig == null) {
        context.collect(rootDescriptor.copy(), TCP_METRIC_CLIENT_COUNT, MANDATORY, COUNT, clientCount);
        context.collect(rootDescriptor.copy(), TCP_METRIC_TEXT_COUNT, MANDATORY, COUNT, textCount);
    }
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) UUID(java.util.UUID) Map(java.util.Map)

Example 44 with MetricDescriptor

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

the class MetricsCompressorTest method testLongTagValue.

@Test
public void testLongTagValue() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    String longPrefix = Stream.generate(() -> "a").limit(MetricsDictionary.MAX_WORD_LENGTH - 1).collect(Collectors.joining());
    MetricDescriptor metric1 = supplier.get().withMetric("metricName").withTag("tag0", longPrefix + "0").withTag("tag1", longPrefix + "1");
    compressor.addLong(metric1, 42);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumer = new MetricConsumer() {

        @Override
        public void consumeLong(MetricDescriptor descriptor, long value) {
            assertEquals(42, value);
            assertEquals("metricName", descriptor.metric());
            assertEquals(longPrefix + "0", descriptor.tagValue("tag0"));
            assertEquals(longPrefix + "1", descriptor.tagValue("tag1"));
        }

        @Override
        public void consumeDouble(MetricDescriptor descriptor, double value) {
            fail("Restored a double metric");
        }
    };
    MetricConsumer metricConsumerSpy = spy(metricConsumer);
    MetricsCompressor.extractMetrics(blob, metricConsumerSpy, supplierSpy);
}
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 45 with MetricDescriptor

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

the class DynamicMetricsCollectionTest method testDirectLongProveLevelFilters.

@Test
public void testDirectLongProveLevelFilters() {
    MetricsCollector collectorMock = mock(MetricsCollector.class);
    MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
    metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42));
    metricsRegistry.collect(collectorMock);
    MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
    verify(collectorMock, never()).collectLong(expectedDescriptor, 42);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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