Search in sources :

Example 1 with NearCacheStatsImpl

use of com.hazelcast.internal.monitor.impl.NearCacheStatsImpl in project hazelcast by hazelcast.

the class NearCacheMetricsProvider method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    descriptor.withPrefix(NEARCACHE_PREFIX);
    ClientContext clientContext = proxyManager.getContext();
    if (clientContext == null) {
        return;
    }
    clientContext.getNearCacheManagers().values().stream().flatMap(nearCacheManager -> nearCacheManager.listAllNearCaches().stream()).forEach(nearCache -> {
        String nearCacheName = nearCache.getName();
        NearCacheStatsImpl nearCacheStats = (NearCacheStatsImpl) nearCache.getNearCacheStats();
        context.collect(descriptor.copy().withDiscriminator(NEARCACHE_DISCRIMINATOR_NAME, nearCacheName), nearCacheStats);
    });
}
Also used : MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ClientContext(com.hazelcast.client.impl.spi.ClientContext) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) ProxyManager(com.hazelcast.client.impl.spi.ProxyManager) NEARCACHE_DISCRIMINATOR_NAME(com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_DISCRIMINATOR_NAME) NEARCACHE_PREFIX(com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_PREFIX) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) ClientContext(com.hazelcast.client.impl.spi.ClientContext)

Example 2 with NearCacheStatsImpl

use of com.hazelcast.internal.monitor.impl.NearCacheStatsImpl in project hazelcast by hazelcast.

the class AbstractNearCacheBasicTest method testNearCacheExpiration.

@SuppressWarnings("UnnecessaryLocalVariable")
private void testNearCacheExpiration() {
    NearCacheTestContext<Integer, String, NK, NV> context = createContext();
    populateDataAdapter(context, DEFAULT_RECORD_COUNT);
    populateNearCache(context);
    assertTrueEventually(() -> {
        NearCacheStatsImpl stats = context.stats;
        // make assertions over near cache's backing map size.
        long nearCacheSize = context.nearCache.size();
        assertEquals(format("Expected zero near cache size but found: %d, [%s] ", nearCacheSize, stats), 0, nearCacheSize);
        // make assertions over near cache stats.
        long ownedEntryCount = stats.getOwnedEntryCount();
        assertEquals(format("Expected no owned entry but found: %d, [%s]", ownedEntryCount, stats), 0, ownedEntryCount);
        long ownedEntryMemoryCost = stats.getOwnedEntryMemoryCost();
        assertEquals(format("Expected zero memory cost but found: %d, [%s]", ownedEntryMemoryCost, stats), 0, ownedEntryMemoryCost);
        long expiredCount = stats.getExpirations();
        assertEquals(format("Expected to see all entries as expired but found: %d, [%s]", expiredCount, stats), DEFAULT_RECORD_COUNT, expiredCount);
        long evictedCount = context.stats.getEvictions();
        assertEquals(format("Expiration should not trigger eviction stat but found: %d, [%s]", evictedCount, stats), 0, evictedCount);
    });
}
Also used : NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl)

Example 3 with NearCacheStatsImpl

use of com.hazelcast.internal.monitor.impl.NearCacheStatsImpl in project hazelcast by hazelcast.

the class NearCacheTestUtils method assertNearCacheStats.

/**
 * Asserts the {@link NearCacheStats} for expected values.
 *
 * @param context                 the {@link NearCacheTestContext} to retrieve the stats from
 * @param expectedOwnedEntryCount the expected owned entry count
 * @param expectedHits            the expected Near Cache hits
 * @param expectedMisses          the expected Near Cache misses
 * @param expectedEvictions       the expected Near Cache evictions
 * @param expectedExpirations     the expected Near Cache expirations
 */
public static void assertNearCacheStats(NearCacheTestContext<?, ?, ?, ?> context, long expectedOwnedEntryCount, long expectedHits, long expectedMisses, long expectedEvictions, long expectedExpirations) {
    NearCacheStats stats = new NearCacheStatsImpl(context.stats);
    assertEqualsFormat("Near Cache entry count should be %d, but was %d (%s)", expectedOwnedEntryCount, stats.getOwnedEntryCount(), stats);
    assertEqualsFormat("Near Cache hits should be %d, but were %d (%s)", expectedHits, stats.getHits(), stats);
    assertEqualsFormat("Near Cache misses should be %d, but were %d (%s)", expectedMisses, stats.getMisses(), stats);
    assertEqualsFormat("Near Cache evictions should be %d, but were %d (%s)", expectedEvictions, stats.getEvictions(), stats);
    assertEqualsFormat("Near Cache expirations should be %d, but were %d (%s)", expectedExpirations, stats.getExpirations(), stats);
}
Also used : NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) NearCacheStats(com.hazelcast.nearcache.NearCacheStats)

Example 4 with NearCacheStatsImpl

use of com.hazelcast.internal.monitor.impl.NearCacheStatsImpl in project hazelcast by hazelcast.

the class ClientStatisticsService method addNearCacheStats.

private void addNearCacheStats(final StringBuilder stats) {
    ProxyManager proxyManager = client.getProxyManager();
    ClientContext context = proxyManager.getContext();
    if (context == null) {
        return;
    }
    context.getNearCacheManagers().values().stream().flatMap(nearCacheManager -> nearCacheManager.listAllNearCaches().stream()).forEach(nearCache -> {
        String nearCacheName = nearCache.getName();
        StringBuilder nearCacheNameWithPrefix = getNameWithPrefix(nearCacheName);
        nearCacheNameWithPrefix.append('.');
        NearCacheStatsImpl nearCacheStats = (NearCacheStatsImpl) nearCache.getNearCacheStats();
        String prefix = nearCacheNameWithPrefix.toString();
        addStat(stats, prefix, "creationTime", nearCacheStats.getCreationTime());
        addStat(stats, prefix, "evictions", nearCacheStats.getEvictions());
        addStat(stats, prefix, "hits", nearCacheStats.getHits());
        addStat(stats, prefix, "lastPersistenceDuration", nearCacheStats.getLastPersistenceDuration());
        addStat(stats, prefix, "lastPersistenceKeyCount", nearCacheStats.getLastPersistenceKeyCount());
        addStat(stats, prefix, "lastPersistenceTime", nearCacheStats.getLastPersistenceTime());
        addStat(stats, prefix, "lastPersistenceWrittenBytes", nearCacheStats.getLastPersistenceWrittenBytes());
        addStat(stats, prefix, "misses", nearCacheStats.getMisses());
        addStat(stats, prefix, "ownedEntryCount", nearCacheStats.getOwnedEntryCount());
        addStat(stats, prefix, "expirations", nearCacheStats.getExpirations());
        addStat(stats, prefix, "invalidations", nearCacheStats.getInvalidations());
        addStat(stats, prefix, "invalidationRequests", nearCacheStats.getInvalidationRequests());
        addStat(stats, prefix, "ownedEntryMemoryCost", nearCacheStats.getOwnedEntryMemoryCost());
        String persistenceFailure = nearCacheStats.getLastPersistenceFailure();
        if (persistenceFailure != null && !persistenceFailure.isEmpty()) {
            addStat(stats, prefix, "lastPersistenceFailure", persistenceFailure);
        }
    });
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientStatisticsCodec(com.hazelcast.client.impl.protocol.codec.ClientStatisticsCodec) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricsCompressor(com.hazelcast.internal.metrics.impl.MetricsCompressor) ConnectionType(com.hazelcast.internal.nio.ConnectionType) BuildInfoProvider(com.hazelcast.instance.BuildInfoProvider) ArrayList(java.util.ArrayList) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) JmxPublisher(com.hazelcast.internal.metrics.jmx.JmxPublisher) ClientMetricsConfig(com.hazelcast.client.config.ClientMetricsConfig) ILogger(com.hazelcast.logging.ILogger) ClientContext(com.hazelcast.client.impl.spi.ClientContext) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Logger(com.hazelcast.logging.Logger) TcpClientConnection(com.hazelcast.client.impl.connection.tcp.TcpClientConnection) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) CompositeMetricsCollector(com.hazelcast.internal.metrics.impl.CompositeMetricsCollector) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) Credentials(com.hazelcast.security.Credentials) List(java.util.List) Gauge(com.hazelcast.internal.metrics.Gauge) PublisherMetricsCollector(com.hazelcast.internal.metrics.impl.PublisherMetricsCollector) ProxyManager(com.hazelcast.client.impl.spi.ProxyManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) NearCacheStatsImpl(com.hazelcast.internal.monitor.impl.NearCacheStatsImpl) ClientContext(com.hazelcast.client.impl.spi.ClientContext) ProxyManager(com.hazelcast.client.impl.spi.ProxyManager)

Aggregations

NearCacheStatsImpl (com.hazelcast.internal.monitor.impl.NearCacheStatsImpl)4 ClientContext (com.hazelcast.client.impl.spi.ClientContext)2 ProxyManager (com.hazelcast.client.impl.spi.ProxyManager)2 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)2 ClientMetricsConfig (com.hazelcast.client.config.ClientMetricsConfig)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 TcpClientConnection (com.hazelcast.client.impl.connection.tcp.TcpClientConnection)1 TcpClientConnectionManager (com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientStatisticsCodec (com.hazelcast.client.impl.protocol.codec.ClientStatisticsCodec)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 BuildInfoProvider (com.hazelcast.instance.BuildInfoProvider)1 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)1 Gauge (com.hazelcast.internal.metrics.Gauge)1 NEARCACHE_DISCRIMINATOR_NAME (com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_DISCRIMINATOR_NAME)1 NEARCACHE_PREFIX (com.hazelcast.internal.metrics.MetricDescriptorConstants.NEARCACHE_PREFIX)1 MetricsCollectionContext (com.hazelcast.internal.metrics.MetricsCollectionContext)1 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)1 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)1 CompositeMetricsCollector (com.hazelcast.internal.metrics.impl.CompositeMetricsCollector)1