private void verifyAllocations() { if (this.bufferFactory instanceof NettyDataBufferFactory) { ByteBufAllocator allocator = ((NettyDataBufferFactory) this.bufferFactory).getByteBufAllocator(); if (allocator instanceof PooledByteBufAllocator) { PooledByteBufAllocatorMetric metric = ((PooledByteBufAllocator) allocator).metric(); long total = getAllocations(metric.directArenas()) + getAllocations(metric.heapArenas()); assertEquals("ByteBuf Leak: " + total + " unreleased allocations", 0, total); } } }
public static AllocatorStats generate(String allocatorName) { PooledByteBufAllocator allocator = null; if ("default".equals(allocatorName)) { allocator = PooledByteBufAllocator.DEFAULT; } else if ("ml-cache".equals(allocatorName)) { allocator = EntryCacheImpl.ALLOCATOR; } else { throw new IllegalArgumentException("Invalid allocator name : " + allocatorName); } AllocatorStats stats = new AllocatorStats(); stats.directArenas = allocator.metric().directArenas().stream() .map(AllocatorStatsGenerator::newPoolArenaStats) .collect(Collectors.toList()); stats.heapArenas = allocator.metric().heapArenas().stream() .map(AllocatorStatsGenerator::newPoolArenaStats) .collect(Collectors.toList()); stats.numDirectArenas = allocator.metric().numDirectArenas(); stats.numHeapArenas = allocator.metric().numHeapArenas(); stats.numThreadLocalCaches = allocator.metric().numThreadLocalCaches(); stats.normalCacheSize = allocator.metric().normalCacheSize(); stats.smallCacheSize = allocator.metric().smallCacheSize(); stats.tinyCacheSize = allocator.metric().tinyCacheSize(); return stats; }
private void registerMetrics(PooledByteBufAllocator allocator) { PooledByteBufAllocatorMetric pooledAllocatorMetric = allocator.metric(); // Register general metrics. allMetrics.put(MetricRegistry.name(metricPrefix, "usedHeapMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedHeapMemory()); allMetrics.put(MetricRegistry.name(metricPrefix, "usedDirectMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedDirectMemory()); if (verboseMetricsEnabled) { int directArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.directArenas()) { registerArenaMetric(metric, "directArena" + directArenaIndex); directArenaIndex++; } int heapArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.heapArenas()) { registerArenaMetric(metric, "heapArena" + heapArenaIndex); heapArenaIndex++; } } }
private void registerMetrics(PooledByteBufAllocator allocator) { PooledByteBufAllocatorMetric pooledAllocatorMetric = allocator.metric(); // Register general metrics. allMetrics.put(MetricRegistry.name(metricPrefix, "usedHeapMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedHeapMemory()); allMetrics.put(MetricRegistry.name(metricPrefix, "usedDirectMemory"), (Gauge<Long>) () -> pooledAllocatorMetric.usedDirectMemory()); if (verboseMetricsEnabled) { int directArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.directArenas()) { registerArenaMetric(metric, "directArena" + directArenaIndex); directArenaIndex++; } int heapArenaIndex = 0; for (PoolArenaMetric metric : pooledAllocatorMetric.heapArenas()) { registerArenaMetric(metric, "heapArena" + heapArenaIndex); heapArenaIndex++; } } }
public Metrics generate() { Map<String, String> dimensionMap = Maps.newHashMap(); dimensionMap.put("system", "jvm"); Metrics m = create(dimensionMap); Runtime r = Runtime.getRuntime(); m.put("jvm_heap_used", r.totalMemory() - r.freeMemory()); m.put("jvm_max_memory", r.maxMemory()); m.put("jvm_total_memory", r.totalMemory()); m.put("jvm_max_direct_memory", PlatformDependent.maxDirectMemory()); m.put("jvm_thread_cnt", getThreadCount()); m.put("jvm_gc_young_pause", currentYoungGcTime); m.put("jvm_gc_young_count", currentYoungGcCount); m.put("jvm_gc_old_pause", currentOldGcTime); m.put("jvm_gc_old_count", currentOldGcCount); long totalAllocated = 0; long totalUsed = 0; for (PoolArenaMetric arena : PooledByteBufAllocator.DEFAULT.metric().directArenas()) { for (PoolChunkListMetric list : arena.chunkLists()) { for (PoolChunkMetric chunk : list) { int size = chunk.chunkSize(); int used = size - chunk.freeBytes(); totalAllocated += size; totalUsed += used; } } } m.put("proxy_default_pool_allocated", totalAllocated); m.put("proxy_default_pool_used", totalUsed); return m; }
private static void registerJvmMetrics(MetricRegistry metricRegistry) { RuntimeMXBean runtimeMxBean = getRuntimeMXBean(); MetricRegistry scoped = metricRegistry.scope("jvm"); scoped.register("bufferpool", new BufferPoolMetricSet(getPlatformMBeanServer())); scoped.register("memory", new MemoryUsageGaugeSet()); scoped.register("thread", new ThreadStatesGaugeSet()); scoped.register("gc", new GarbageCollectorMetricSet()); scoped.register("uptime", (Gauge<Long>) runtimeMxBean::getUptime); scoped.register("uptime.formatted", (Gauge<String>) () -> formatTime(runtimeMxBean.getUptime())); scoped.register("netty", new NettyAllocatorMetricSet("pooled-allocator", PooledByteBufAllocator.DEFAULT.metric())); scoped.register("netty", new NettyAllocatorMetricSet("unpooled-allocator", UnpooledByteBufAllocator.DEFAULT.metric())); }
long totalUsed = 0; for (PoolArenaMetric arena : allocator.metric().directArenas()) { activeAllocations += arena.numActiveAllocations(); activeAllocationsTiny += arena.numActiveTinyAllocations();