From 00011d8ea026d856d64adca2701dbed213e07be8 Mon Sep 17 00:00:00 2001 From: "Jay.H.Zou" Date: Thu, 28 Nov 2019 01:16:40 +0800 Subject: [PATCH] fixed monitor data for keyspace_hits_ratio --- .../java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java index d5c9b389..2c809381 100644 --- a/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java +++ b/redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java @@ -5,7 +5,6 @@ import com.google.common.base.Strings; import com.newegg.ec.redis.entity.NodeInfo; -import java.io.IOException; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; @@ -231,7 +230,7 @@ private static double truncatedPercentSign(String originalData) { */ private static NodeInfo calculateCumulativeData(NodeInfo nodeInfo, NodeInfo lastTimeNodeInfo) { if (lastTimeNodeInfo != null) { - double keyspaceHitRatio = calculateKeyspaceHitRatio(lastTimeNodeInfo, nodeInfo); + double keyspaceHitRatio = calculateKeyspaceHitRatio(nodeInfo, lastTimeNodeInfo); nodeInfo.setKeyspaceHitsRatio(keyspaceHitRatio); nodeInfo.setCommandsProcessed(nodeInfo.getTotalCommandsProcessed() - lastTimeNodeInfo.getTotalCommandsProcessed()); nodeInfo.setConnectionsReceived(nodeInfo.getTotalConnectionsReceived() - lastTimeNodeInfo.getTotalConnectionsReceived()); @@ -244,13 +243,13 @@ private static NodeInfo calculateCumulativeData(NodeInfo nodeInfo, NodeInfo last } private static double calculateKeyspaceHitRatio(NodeInfo nodeInfo, NodeInfo lastTimeNodeInfo) { - long keyspaceHit = nodeInfo.getKeyspaceHits() - lastTimeNodeInfo.getKeyspaceHits(); + long keyspaceHits = nodeInfo.getKeyspaceHits() - lastTimeNodeInfo.getKeyspaceHits(); long keyspaceMisses = nodeInfo.getKeyspaceMisses() - lastTimeNodeInfo.getKeyspaceMisses(); - BigDecimal hitAndMiss = BigDecimal.valueOf(keyspaceHit + keyspaceMisses); + BigDecimal hitAndMiss = BigDecimal.valueOf(keyspaceHits + keyspaceMisses); if (hitAndMiss.longValue() == 0) { return 0; } - BigDecimal divide = BigDecimal.valueOf(keyspaceHit).divide(hitAndMiss, 2, BigDecimal.ROUND_HALF_UP); + BigDecimal divide = BigDecimal.valueOf(keyspaceHits).divide(hitAndMiss, 4, BigDecimal.ROUND_HALF_UP); return divide.doubleValue(); }