Search in sources :

Example 1 with CompositeMetricsCollector

use of com.hazelcast.internal.metrics.impl.CompositeMetricsCollector in project hazelcast by hazelcast.

the class ClientStatisticsService method schedulePeriodicStatisticsSendTask.

/**
 * @param periodSeconds the interval at which the statistics collection and send is being run
 */
private void schedulePeriodicStatisticsSendTask(long periodSeconds) {
    ClientMetricCollector clientMetricCollector = new ClientMetricCollector();
    CompositeMetricsCollector compositeMetricsCollector = new CompositeMetricsCollector(clientMetricCollector, publisherMetricsCollector);
    client.getTaskScheduler().scheduleWithRepetition(() -> {
        long collectionTimestamp = System.currentTimeMillis();
        metricsRegistry.collect(compositeMetricsCollector);
        publisherMetricsCollector.publishCollectedMetrics();
        TcpClientConnection connection = getConnection();
        if (connection == null) {
            logger.finest("Cannot send client statistics to the server. No connection found.");
            return;
        }
        final StringBuilder clientAttributes = new StringBuilder();
        periodicStats.fillMetrics(collectionTimestamp, clientAttributes, connection);
        addNearCacheStats(clientAttributes);
        byte[] metricsBlob = clientMetricCollector.getBlob();
        sendStats(collectionTimestamp, clientAttributes.toString(), metricsBlob, connection);
    }, 0, periodSeconds, SECONDS);
}
Also used : CompositeMetricsCollector(com.hazelcast.internal.metrics.impl.CompositeMetricsCollector) TcpClientConnection(com.hazelcast.client.impl.connection.tcp.TcpClientConnection)

Aggregations

TcpClientConnection (com.hazelcast.client.impl.connection.tcp.TcpClientConnection)1 CompositeMetricsCollector (com.hazelcast.internal.metrics.impl.CompositeMetricsCollector)1