Skip to content

Commit

Permalink
fixed monitor data for keyspace_hits_ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay.H.Zou authored and Jay.H.Zou committed Nov 27, 2019
1 parent b239680 commit 00011d8
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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();
}

Expand Down

0 comments on commit 00011d8

Please sign in to comment.