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);
});
}
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);
});
}
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);
}
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);
}
});
}
Aggregations