This is an automated email from the ASF dual-hosted git repository.

lindong pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d0fcf12  KAFKA-7354; Fix IdlePercent and 
NetworkProcessorAvgIdlePercent metric
d0fcf12 is described below

commit d0fcf12832d9d383a5c76c174119e96e36d94eaf
Author: huxihx <huxi...@hotmail.com>
AuthorDate: Wed Aug 29 08:29:59 2018 -0700

    KAFKA-7354; Fix IdlePercent and NetworkProcessorAvgIdlePercent metric
    
    Currently, MBean 
`kafka.network:type=Processor,name=IdlePercent,networkProcessor=*` and 
`afka.network:type=SocketServer,name=NetworkProcessorAvgIdlePercent` could be 
greater than 1. However, these two values represent a percentage which should 
not exceed 1.
    
    Author: huxihx <huxi...@hotmail.com>
    
    Reviewers: Dong Lin <lindon...@gmail.com>
    
    Closes #5584 from huxihx/KAFKA-7354
---
 core/src/main/scala/kafka/network/SocketServer.scala | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/src/main/scala/kafka/network/SocketServer.scala 
b/core/src/main/scala/kafka/network/SocketServer.scala
index 749c921..96feee8 100644
--- a/core/src/main/scala/kafka/network/SocketServer.scala
+++ b/core/src/main/scala/kafka/network/SocketServer.scala
@@ -102,7 +102,7 @@ class SocketServer(val config: KafkaConfig, val metrics: 
Metrics, val time: Time
             metrics.metricName("io-wait-ratio", "socket-server-metrics", 
p.metricTags)
           }
           ioWaitRatioMetricNames.map { metricName =>
-            Option(metrics.metric(metricName)).fold(0.0)(_.value)
+            Option(metrics.metric(metricName)).fold(0.0)(m => 
Math.min(m.metricValue.asInstanceOf[Double], 1.0))
           }.sum / processors.size
         }
       }
@@ -538,7 +538,8 @@ private[kafka] class Processor(val id: Int,
   newGauge(IdlePercentMetricName,
     new Gauge[Double] {
       def value = {
-        Option(metrics.metric(metrics.metricName("io-wait-ratio", 
"socket-server-metrics", metricTags))).fold(0.0)(_.value)
+        Option(metrics.metric(metrics.metricName("io-wait-ratio", 
"socket-server-metrics", metricTags)))
+          .fold(0.0)(m => Math.min(m.metricValue.asInstanceOf[Double], 1.0))
       }
     },
     // for compatibility, only add a networkProcessor tag to the Yammer 
Metrics alias (the equivalent Selector metric

Reply via email to