use of org.apache.ignite.spi.metric.HistogramMetric in project ignite by apache.
the class MetricRegistryMBean method searchHistogram.
/**
* Parse attribute name for a histogram and search it's value.
*
* @param name Attribute name.
* @param mreg Metric registry to search histogram in.
* @return Specific bucket value or {@code null} if not found.
* @see MetricUtils#histogramBucketNames(HistogramMetric)
*/
public static Long searchHistogram(String name, ReadOnlyMetricRegistry mreg) {
int highBoundIdx;
boolean isInf = name.endsWith(INF);
if (isInf)
highBoundIdx = name.length() - 4;
else {
highBoundIdx = name.lastIndexOf(HISTOGRAM_NAME_DIVIDER);
if (highBoundIdx == -1)
return null;
}
int lowBoundIdx = name.lastIndexOf(HISTOGRAM_NAME_DIVIDER, highBoundIdx - 1);
if (lowBoundIdx == -1)
return null;
Metric m = mreg.findMetric(name.substring(0, lowBoundIdx));
if (!(m instanceof HistogramMetric))
return null;
HistogramMetric h = (HistogramMetric) m;
long[] bounds = h.bounds();
long[] values = h.value();
long lowBound;
try {
lowBound = Long.parseLong(name.substring(lowBoundIdx + 1, highBoundIdx));
} catch (NumberFormatException e) {
return null;
}
if (isInf) {
if (bounds[bounds.length - 1] == lowBound)
return values[values.length - 1];
return null;
}
long highBound;
try {
highBound = Long.parseLong(name.substring(highBoundIdx + 1));
} catch (NumberFormatException e) {
return null;
}
int idx = binarySearch(bounds, highBound);
if (idx < 0)
return null;
if ((idx == 0 && lowBound != 0) || (idx != 0 && bounds[idx - 1] != lowBound))
return null;
return values[idx];
}
Aggregations