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
8c9825a030
commit
6148b4785d
|
@ -310,7 +310,11 @@ public class JSONBean {
|
|||
jg.writeEndArray();
|
||||
} else if(value instanceof Number) {
|
||||
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) {
|
||||
Boolean b = (Boolean)value;
|
||||
jg.writeBoolean(b);
|
||||
|
|
|
@ -388,23 +388,53 @@ public class CacheStats {
|
|||
}
|
||||
|
||||
public double getHitRatio() {
|
||||
return ((double) getHitCount() / (double) getRequestCount());
|
||||
double requestCount = getRequestCount();
|
||||
|
||||
if (requestCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getHitCount() / requestCount;
|
||||
}
|
||||
|
||||
public double getHitCachingRatio() {
|
||||
return ((double) getHitCachingCount() / (double) getRequestCachingCount());
|
||||
double requestCachingCount = getRequestCachingCount();
|
||||
|
||||
if (requestCachingCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getHitCachingCount() / requestCachingCount;
|
||||
}
|
||||
|
||||
public double getMissRatio() {
|
||||
return ((double) getMissCount() / (double) getRequestCount());
|
||||
double requestCount = getRequestCount();
|
||||
|
||||
if (requestCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getMissCount() / requestCount;
|
||||
}
|
||||
|
||||
public double getMissCachingRatio() {
|
||||
return ((double) getMissCachingCount() / (double) getRequestCachingCount());
|
||||
double requestCachingCount = getRequestCachingCount();
|
||||
|
||||
if (requestCachingCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getMissCachingCount() / requestCachingCount;
|
||||
}
|
||||
|
||||
public double evictedPerEviction() {
|
||||
return ((double) getEvictedCount() / (double) getEvictionCount());
|
||||
double evictionCount = getEvictionCount();
|
||||
|
||||
if (evictionCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getEvictedCount() / evictionCount;
|
||||
}
|
||||
|
||||
public long getFailedInserts() {
|
||||
|
|
Loading…
Reference in New Issue