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
2a309d71cc
commit
2d493556f3
|
@ -387,23 +387,53 @@ public class CacheStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitRatio() {
|
public double getHitRatio() {
|
||||||
return ((float)getHitCount()/(float)getRequestCount());
|
double requestCount = getRequestCount();
|
||||||
|
|
||||||
|
if (requestCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getHitCount() / requestCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitCachingRatio() {
|
public double getHitCachingRatio() {
|
||||||
return ((float)getHitCachingCount()/(float)getRequestCachingCount());
|
double requestCachingCount = getRequestCachingCount();
|
||||||
|
|
||||||
|
if (requestCachingCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getHitCachingCount() / requestCachingCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMissRatio() {
|
public double getMissRatio() {
|
||||||
return ((float)getMissCount()/(float)getRequestCount());
|
double requestCount = getRequestCount();
|
||||||
|
|
||||||
|
if (requestCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMissCount() / requestCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMissCachingRatio() {
|
public double getMissCachingRatio() {
|
||||||
return ((float)getMissCachingCount()/(float)getRequestCachingCount());
|
double requestCachingCount = getRequestCachingCount();
|
||||||
|
|
||||||
|
if (requestCachingCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getMissCachingCount() / requestCachingCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double evictedPerEviction() {
|
public double evictedPerEviction() {
|
||||||
return ((float)getEvictedCount()/(float)getEvictionCount());
|
double evictionCount = getEvictionCount();
|
||||||
|
|
||||||
|
if (evictionCount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getEvictedCount() / evictionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFailedInserts() {
|
public long getFailedInserts() {
|
||||||
|
|
|
@ -317,7 +317,12 @@ 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());
|
double doubleValue = n.doubleValue();
|
||||||
|
if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) {
|
||||||
|
jg.writeString(n.toString());
|
||||||
|
} else {
|
||||||
|
jg.writeNumber(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);
|
||||||
|
|
Loading…
Reference in New Issue