songxiaosheng commented on code in PR #12695:
URL: https://github.com/apache/dubbo/pull/12695#discussion_r1266651692
##########
dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java:
##########
@@ -109,6 +115,27 @@ protected void doOpen() throws Throwable {
channelFuture.syncUninterruptibly();
channel = channelFuture.channel();
+ // metrics
+ ApplicationModel applicationModel = ApplicationModel.defaultModel();
+ if(isSupportMetrics()){
+ MetricsEventBus.post(NettyEvent.toNettyEvent(applicationModel), ()
-> {
+ Map<String, Long> dataMap = new HashMap<>();
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_MEMORY_USED.getName(),
PooledByteBufAllocator.DEFAULT.metric().usedHeapMemory());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_MEMORY_USED.getName(),
PooledByteBufAllocator.DEFAULT.metric().usedDirectMemory());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_ARENAS_NUM.getName(), (long)
PooledByteBufAllocator.DEFAULT.numHeapArenas());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_ARENAS_NUM.getName(), (long)
PooledByteBufAllocator.DEFAULT.numDirectArenas());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_NORMAL_CACHE_SIZE.getName(), (long)
PooledByteBufAllocator.DEFAULT.normalCacheSize());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_SMALL_CACHE_SIZE.getName(), (long)
PooledByteBufAllocator.DEFAULT.smallCacheSize());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_THREAD_LOCAL_CACHES_NUM.getName(),
(long) PooledByteBufAllocator.DEFAULT.numThreadLocalCaches());
+ dataMap.put(MetricsKey.NETTY_ALLOCATOR_CHUNK_SIZE.getName(),
(long) PooledByteBufAllocator.DEFAULT.chunkSize());
+ return dataMap;
+ });
+ }
+ }
+
+ private boolean isSupportMetrics() {
+ return
ClassUtils.isPresent("io.netty.buffer.PooledByteBufAllocatorMetric",
NettyServer.class.getClassLoader()) &&
+
ClassUtils.isPresent("io.netty.handler.codec.compression.EncoderUtil",
NettyServer.class.getClassLoader());
Review Comment:
这里为何要判断EncoderUtil这个类型,没看到后面指标使用了这个类型,
##########
dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java:
##########
@@ -109,6 +115,27 @@ protected void doOpen() throws Throwable {
channelFuture.syncUninterruptibly();
channel = channelFuture.channel();
+ // metrics
+ ApplicationModel applicationModel = ApplicationModel.defaultModel();
+ if(isSupportMetrics()){
+ MetricsEventBus.post(NettyEvent.toNettyEvent(applicationModel), ()
-> {
+ Map<String, Long> dataMap = new HashMap<>();
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_MEMORY_USED.getName(),
PooledByteBufAllocator.DEFAULT.metric().usedHeapMemory());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_MEMORY_USED.getName(),
PooledByteBufAllocator.DEFAULT.metric().usedDirectMemory());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_ARENAS_NUM.getName(), (long)
PooledByteBufAllocator.DEFAULT.numHeapArenas());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_ARENAS_NUM.getName(), (long)
PooledByteBufAllocator.DEFAULT.numDirectArenas());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_NORMAL_CACHE_SIZE.getName(), (long)
PooledByteBufAllocator.DEFAULT.normalCacheSize());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_SMALL_CACHE_SIZE.getName(), (long)
PooledByteBufAllocator.DEFAULT.smallCacheSize());
+
dataMap.put(MetricsKey.NETTY_ALLOCATOR_THREAD_LOCAL_CACHES_NUM.getName(),
(long) PooledByteBufAllocator.DEFAULT.numThreadLocalCaches());
+ dataMap.put(MetricsKey.NETTY_ALLOCATOR_CHUNK_SIZE.getName(),
(long) PooledByteBufAllocator.DEFAULT.chunkSize());
+ return dataMap;
+ });
+ }
+ }
+
+ private boolean isSupportMetrics() {
+ return
ClassUtils.isPresent("io.netty.buffer.PooledByteBufAllocatorMetric",
NettyServer.class.getClassLoader()) &&
+
ClassUtils.isPresent("io.netty.handler.codec.compression.EncoderUtil",
NettyServer.class.getClassLoader());
Review Comment:
这里为何要判断EncoderUtil这个类型,没看到后面指标使用了这个类型,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]