Search in sources :

Example 1 with ClientStatistics

use of com.hazelcast.client.impl.statistics.ClientStatistics in project hazelcast by hazelcast.

the class ClientEngineImpl method getClientStatistics.

@Override
public Map<UUID, ClientStatistics> getClientStatistics() {
    Collection<ClientEndpoint> clientEndpoints = endpointManager.getEndpoints();
    Map<UUID, ClientStatistics> statsMap = createHashMap(clientEndpoints.size());
    for (ClientEndpoint e : clientEndpoints) {
        ClientStatistics statistics = e.getClientStatistics();
        if (null != statistics) {
            statsMap.put(e.getUuid(), statistics);
        }
    }
    return statsMap;
}
Also used : ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics) UUID(java.util.UUID)

Example 2 with ClientStatistics

use of com.hazelcast.client.impl.statistics.ClientStatistics 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 3 with ClientStatistics

use of com.hazelcast.client.impl.statistics.ClientStatistics 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 4 with ClientStatistics

use of com.hazelcast.client.impl.statistics.ClientStatistics in project hazelcast by hazelcast.

the class ClientStatisticsMessageTask method call.

@Override
protected Object call() throws Exception {
    ClientStatistics clientStatistics = new ClientStatistics(parameters.timestamp, parameters.clientAttributes, parameters.metricsBlob);
    endpoint.setClientStatistics(clientStatistics);
    return null;
}
Also used : ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics)

Example 5 with ClientStatistics

use of com.hazelcast.client.impl.statistics.ClientStatistics in project hazelcast by hazelcast.

the class TimedMemberStateFactory method getClientAttributes.

private Map<UUID, String> getClientAttributes(Map<UUID, ClientStatistics> allClientStatistics) {
    Map<UUID, String> statsMap = createHashMap(allClientStatistics.size());
    for (Map.Entry<UUID, ClientStatistics> entry : allClientStatistics.entrySet()) {
        UUID uuid = entry.getKey();
        ClientStatistics statistics = entry.getValue();
        if (statistics != null) {
            statsMap.put(uuid, statistics.clientAttributes());
        }
    }
    return statsMap;
}
Also used : ClientStatistics(com.hazelcast.client.impl.statistics.ClientStatistics) UUID(java.util.UUID) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap)

Aggregations

ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)7 UUID (java.util.UUID)5 ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)2 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Map (java.util.Map)2 Test (org.junit.Test)2 Client (com.hazelcast.client.Client)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientEngine (com.hazelcast.client.impl.ClientEngine)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)1 CapturingCollector (com.hazelcast.internal.metrics.impl.CapturingCollector)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 IMap (com.hazelcast.map.IMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1