HBASE-20571 JMXJsonServlet generates invalid JSON if it has NaN in metrics
- CacheStats won't generate NaN metrics. - JSONBean class will serialize special floating point values as "NaN", "Infinity" or "-Infinity" Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
61f2b5f071
commit
39ea1efa88
|
@ -310,7 +310,11 @@ public class JSONBean {
|
||||||
jg.writeEndArray();
|
jg.writeEndArray();
|
||||||
} else if(value instanceof Number) {
|
} else if(value instanceof Number) {
|
||||||
Number n = (Number)value;
|
Number n = (Number)value;
|
||||||
jg.writeNumber(n.toString());
|
if (Double.isFinite(n.doubleValue())) {
|
||||||
|
jg.writeNumber(n.toString());
|
||||||
|
} else {
|
||||||
|
jg.writeString(n.toString());
|
||||||
|
}
|
||||||
} else if(value instanceof Boolean) {
|
} else if(value instanceof Boolean) {
|
||||||
Boolean b = (Boolean)value;
|
Boolean b = (Boolean)value;
|
||||||
jg.writeBoolean(b);
|
jg.writeBoolean(b);
|
||||||
|
|
|
@ -388,23 +388,53 @@ public class CacheStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitRatio() {
|
public double getHitRatio() {
|
||||||
return ((double) getHitCount() / (double) getRequestCount());
|
double requestCount = getRequestCount();
|
||||||
|
|
||||||
|
if (requestCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getHitCount() / requestCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitCachingRatio() {
|
public double getHitCachingRatio() {
|
||||||
return ((double) getHitCachingCount() / (double) getRequestCachingCount());
|
double requestCachingCount = getRequestCachingCount();
|
||||||
|
|
||||||
|
if (requestCachingCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getHitCachingCount() / requestCachingCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMissRatio() {
|
public double getMissRatio() {
|
||||||
return ((double) getMissCount() / (double) getRequestCount());
|
double requestCount = getRequestCount();
|
||||||
|
|
||||||
|
if (requestCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMissCount() / requestCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMissCachingRatio() {
|
public double getMissCachingRatio() {
|
||||||
return ((double) getMissCachingCount() / (double) getRequestCachingCount());
|
double requestCachingCount = getRequestCachingCount();
|
||||||
|
|
||||||
|
if (requestCachingCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMissCachingCount() / requestCachingCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double evictedPerEviction() {
|
public double evictedPerEviction() {
|
||||||
return ((double) getEvictedCount() / (double) getEvictionCount());
|
double evictionCount = getEvictionCount();
|
||||||
|
|
||||||
|
if (evictionCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getEvictedCount() / evictionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFailedInserts() {
|
public long getFailedInserts() {
|
||||||
|
|
Loading…
Reference in New Issue