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

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


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

commit 0310c9e09417c5c0e821fb553f02099ccb7fa716
Author: huxihx <[email protected]>
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 <[email protected]>
    
    Reviewers: Dong Lin <[email protected]>
    
    Closes #5584 from huxihx/KAFKA-7354
    
    (cherry picked from commit d0fcf12832d9d383a5c76c174119e96e36d94eaf)
    Signed-off-by: Dong Lin <[email protected]>
---
 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 62fc7a5..81b1474 100644
--- a/core/src/main/scala/kafka/network/SocketServer.scala
+++ b/core/src/main/scala/kafka/network/SocketServer.scala
@@ -105,7 +105,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
         }
       }
@@ -531,7 +531,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