Search in sources :

Example 1 with LongProbeFunction

use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.

the class DoubleGaugeImpl method read.

@Override
public double read() {
    ProbeInstance probeInstance = getProbeInstance();
    ProbeFunction function = null;
    Object source = null;
    if (probeInstance != null) {
        function = probeInstance.function;
        source = probeInstance.source;
    }
    if (function == null || source == null) {
        clearProbeInstance();
        return DEFAULT_VALUE;
    }
    try {
        if (function instanceof LongProbeFunction) {
            LongProbeFunction longFunction = (LongProbeFunction) function;
            return longFunction.get(source);
        } else {
            DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
            return doubleFunction.get(source);
        }
    } catch (Exception e) {
        metricsRegistry.logger.warning("Failed to access probe:" + name, e);
        return DEFAULT_VALUE;
    }
}
Also used : LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) ProbeFunction(com.hazelcast.internal.metrics.ProbeFunction) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction)

Example 2 with LongProbeFunction

use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.

the class LongGaugeImpl method read.

@Override
public long read() {
    ProbeInstance probeInstance = getProbeInstance();
    ProbeFunction function = null;
    Object source = null;
    if (probeInstance != null) {
        function = probeInstance.function;
        source = probeInstance.source;
    }
    if (function == null || source == null) {
        clearProbeInstance();
        return DEFAULT_VALUE;
    }
    try {
        if (function instanceof LongProbeFunction) {
            LongProbeFunction longFunction = (LongProbeFunction) function;
            return longFunction.get(source);
        } else {
            DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
            double doubleResult = doubleFunction.get(source);
            return Math.round(doubleResult);
        }
    } catch (Exception e) {
        metricsRegistry.logger.warning("Failed to access probe:" + name, e);
        return DEFAULT_VALUE;
    }
}
Also used : LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) ProbeFunction(com.hazelcast.internal.metrics.ProbeFunction) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction)

Example 3 with LongProbeFunction

use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.

the class MetricsRegistryImpl method render.

private void render(ProbeRenderer renderer, ProbeInstance probeInstance) {
    ProbeFunction function = probeInstance.function;
    Object source = probeInstance.source;
    String name = probeInstance.name;
    if (function == null || source == null) {
        renderer.renderNoValue(name);
        return;
    }
    try {
        if (function instanceof LongProbeFunction) {
            LongProbeFunction longFunction = (LongProbeFunction) function;
            renderer.renderLong(name, longFunction.get(source));
        } else {
            DoubleProbeFunction doubleFunction = (DoubleProbeFunction) function;
            renderer.renderDouble(name, doubleFunction.get(source));
        }
    } catch (Exception e) {
        renderer.renderException(name, e);
    }
}
Also used : LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) ProbeFunction(com.hazelcast.internal.metrics.ProbeFunction) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction)

Example 4 with LongProbeFunction

use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.

the class DiagnosticsLogTest method testRollover.

@Test
public void testRollover() {
    String id = generateRandomString(10000);
    final List<File> files = new LinkedList<File>();
    LongProbeFunction f = new LongProbeFunction() {

        @Override
        public long get(Object source) throws Exception {
            return 0;
        }
    };
    for (int k = 0; k < 10; k++) {
        metricsRegistry.register(this, id + k, ProbeLevel.MANDATORY, f);
    }
    // we run for some time to make sure we get enough rollovers.
    while (files.size() < 3) {
        final File file = diagnosticsLogFile.file;
        if (file != null) {
            if (!files.contains(file)) {
                files.add(file);
            }
            assertTrueEventually(new AssertTask() {

                @Override
                public void run() throws Exception {
                    assertExist(file);
                }
            });
        }
        sleepMillis(100);
    }
    // eventually all these files should be gone.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (File file : files) {
                assertNotExist(file);
            }
        }
    });
}
Also used : LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) AssertTask(com.hazelcast.test.AssertTask) File(java.io.File) LinkedList(java.util.LinkedList) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with LongProbeFunction

use of com.hazelcast.internal.metrics.LongProbeFunction in project hazelcast by hazelcast.

the class LongGaugeImplTest method whenProbeThrowsException.

@Test
public void whenProbeThrowsException() {
    metricsRegistry.register(this, "foo", MANDATORY, new LongProbeFunction() {

        @Override
        public long get(Object o) {
            throw new RuntimeException();
        }
    });
    LongGauge gauge = metricsRegistry.newLongGauge("foo");
    long actual = gauge.read();
    assertEquals(0, actual);
}
Also used : LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) LongGauge(com.hazelcast.internal.metrics.LongGauge) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LongProbeFunction (com.hazelcast.internal.metrics.LongProbeFunction)11 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 DoubleProbeFunction (com.hazelcast.internal.metrics.DoubleProbeFunction)3 LongGauge (com.hazelcast.internal.metrics.LongGauge)3 ProbeFunction (com.hazelcast.internal.metrics.ProbeFunction)3 IOException (java.io.IOException)2 DoubleGauge (com.hazelcast.internal.metrics.DoubleGauge)1 AssertTask (com.hazelcast.test.AssertTask)1 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1