Search in sources :

Example 11 with HistogramMetric

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];
}
Also used : HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric)

Aggregations

HistogramMetric (org.apache.ignite.spi.metric.HistogramMetric)11 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 IgniteEx (org.apache.ignite.internal.IgniteEx)5 Metric (org.apache.ignite.spi.metric.Metric)5 ArrayList (java.util.ArrayList)3 GridMetricManager (org.apache.ignite.internal.processors.metric.GridMetricManager)3 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)3 BooleanMetric (org.apache.ignite.spi.metric.BooleanMetric)3 DoubleMetric (org.apache.ignite.spi.metric.DoubleMetric)3 IntMetric (org.apache.ignite.spi.metric.IntMetric)3 LongMetric (org.apache.ignite.spi.metric.LongMetric)3 ObjectMetric (org.apache.ignite.spi.metric.ObjectMetric)3 List (java.util.List)2 AtomicLongMetric (org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric)2 ReadOnlyMetricManager (org.apache.ignite.spi.metric.ReadOnlyMetricManager)2 Iterables (com.google.common.collect.Iterables)1 Scope (io.opencensus.common.Scope)1 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Measure (io.opencensus.stats.Measure)1