Java Code Examples for org.apache.flink.metrics.Gauge#getValue()
The following examples show how to use
org.apache.flink.metrics.Gauge#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricUtilsTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Tests that heap/non-heap metrics do not rely on a static MemoryUsage instance. * * <p>We can only check this easily for the currently used heap memory, so we use it this as a proxy for testing * the functionality in general. */ @Test public void testHeapMetrics() throws Exception { final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup(); MetricUtils.instantiateHeapMemoryMetrics(heapMetrics); @SuppressWarnings("unchecked") final Gauge<Long> used = (Gauge<Long>) heapMetrics.get(MetricNames.MEMORY_USED); final long usedHeapInitially = used.getValue(); // check memory usage difference multiple times since other tests may affect memory usage as well for (int x = 0; x < 10; x++) { final byte[] array = new byte[1024 * 1024 * 8]; final long usedHeapAfterAllocation = used.getValue(); if (usedHeapInitially != usedHeapAfterAllocation) { return; } Thread.sleep(50); } Assert.fail("Heap usage metric never changed it's value."); }
Example 2
Source File: AbstractPrometheusReporter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@VisibleForTesting io.prometheus.client.Gauge.Child gaugeFrom(Gauge gauge) { return new io.prometheus.client.Gauge.Child() { @Override public double get() { final Object value = gauge.getValue(); if (value == null) { log.debug("Gauge {} is null-valued, defaulting to 0.", gauge); return 0; } if (value instanceof Double) { return (double) value; } if (value instanceof Number) { return ((Number) value).doubleValue(); } if (value instanceof Boolean) { return ((Boolean) value) ? 1 : 0; } log.debug("Invalid type for Gauge {}: {}, only number types and booleans are supported by this reporter.", gauge, value.getClass().getName()); return 0; } }; }
Example 3
Source File: MetricUtilsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that heap/non-heap metrics do not rely on a static MemoryUsage instance. * * <p>We can only check this easily for the currently used heap memory, so we use it this as a proxy for testing * the functionality in general. */ @Test public void testHeapMetrics() throws Exception { final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup(); MetricUtils.instantiateHeapMemoryMetrics(heapMetrics); @SuppressWarnings("unchecked") final Gauge<Long> used = (Gauge<Long>) heapMetrics.get(MetricNames.MEMORY_USED); final long usedHeapInitially = used.getValue(); // check memory usage difference multiple times since other tests may affect memory usage as well for (int x = 0; x < 10; x++) { final byte[] array = new byte[1024 * 1024 * 8]; final long usedHeapAfterAllocation = used.getValue(); if (usedHeapInitially != usedHeapAfterAllocation) { return; } Thread.sleep(50); } Assert.fail("Heap usage metric never changed it's value."); }
Example 4
Source File: AbstractPrometheusReporter.java From flink with Apache License 2.0 | 6 votes |
@VisibleForTesting io.prometheus.client.Gauge.Child gaugeFrom(Gauge gauge) { return new io.prometheus.client.Gauge.Child() { @Override public double get() { final Object value = gauge.getValue(); if (value == null) { log.debug("Gauge {} is null-valued, defaulting to 0.", gauge); return 0; } if (value instanceof Double) { return (double) value; } if (value instanceof Number) { return ((Number) value).doubleValue(); } if (value instanceof Boolean) { return ((Boolean) value) ? 1 : 0; } log.debug("Invalid type for Gauge {}: {}, only number types and booleans are supported by this reporter.", gauge, value.getClass().getName()); return 0; } }; }
Example 5
Source File: MetricUtilsTest.java From flink with Apache License 2.0 | 6 votes |
/** * Tests that heap/non-heap metrics do not rely on a static MemoryUsage instance. * * <p>We can only check this easily for the currently used heap memory, so we use it this as a proxy for testing * the functionality in general. */ @Test public void testHeapMetrics() throws Exception { final InterceptingOperatorMetricGroup heapMetrics = new InterceptingOperatorMetricGroup(); MetricUtils.instantiateHeapMemoryMetrics(heapMetrics); @SuppressWarnings("unchecked") final Gauge<Long> used = (Gauge<Long>) heapMetrics.get(MetricNames.MEMORY_USED); final long usedHeapInitially = used.getValue(); // check memory usage difference multiple times since other tests may affect memory usage as well for (int x = 0; x < 10; x++) { final byte[] array = new byte[1024 * 1024 * 8]; final long usedHeapAfterAllocation = used.getValue(); if (usedHeapInitially != usedHeapAfterAllocation) { return; } Thread.sleep(50); } Assert.fail("Heap usage metric never changed it's value."); }
Example 6
Source File: AbstractPrometheusReporter.java From flink with Apache License 2.0 | 6 votes |
@VisibleForTesting io.prometheus.client.Gauge.Child gaugeFrom(Gauge gauge) { return new io.prometheus.client.Gauge.Child() { @Override public double get() { final Object value = gauge.getValue(); if (value == null) { log.debug("Gauge {} is null-valued, defaulting to 0.", gauge); return 0; } if (value instanceof Double) { return (double) value; } if (value instanceof Number) { return ((Number) value).doubleValue(); } if (value instanceof Boolean) { return ((Boolean) value) ? 1 : 0; } log.debug("Invalid type for Gauge {}: {}, only number types and booleans are supported by this reporter.", gauge, value.getClass().getName()); return 0; } }; }
Example 7
Source File: MetricDumpSerialization.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static void serializeGauge(DataOutput out, QueryScopeInfo info, String name, Gauge<?> gauge) throws IOException { Object value = gauge.getValue(); if (value == null) { throw new NullPointerException("Value returned by gauge " + name + " was null."); } String stringValue = value.toString(); if (stringValue == null) { throw new NullPointerException("toString() of the value returned by gauge " + name + " returned null."); } serializeMetricInfo(out, info); out.writeUTF(name); out.writeUTF(stringValue); }
Example 8
Source File: MetricMapper.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
static Point map(MeasurementInfo info, Instant timestamp, Gauge<?> gauge) { Point.Builder builder = builder(info, timestamp); Object value = gauge.getValue(); if (value instanceof Number) { builder.addField("value", (Number) value); } else { builder.addField("value", String.valueOf(value)); } return builder.build(); }
Example 9
Source File: MetricDumpSerialization.java From flink with Apache License 2.0 | 5 votes |
private static void serializeGauge(DataOutput out, QueryScopeInfo info, String name, Gauge<?> gauge) throws IOException { Object value = gauge.getValue(); if (value == null) { throw new NullPointerException("Value returned by gauge " + name + " was null."); } String stringValue = value.toString(); if (stringValue == null) { throw new NullPointerException("toString() of the value returned by gauge " + name + " returned null."); } serializeMetricInfo(out, info); out.writeUTF(name); out.writeUTF(stringValue); }
Example 10
Source File: StatsDReporter.java From flink with Apache License 2.0 | 5 votes |
private void reportGauge(final String name, final Gauge<?> gauge) { Object value = gauge.getValue(); if (value == null) { return; } if (value instanceof Number) { send(numberIsNegative((Number) value), name, value.toString()); } send(name, value.toString()); }
Example 11
Source File: MetricMapper.java From flink with Apache License 2.0 | 5 votes |
static Point map(MeasurementInfo info, Instant timestamp, Gauge<?> gauge) { Point.Builder builder = builder(info, timestamp); Object value = gauge.getValue(); if (value instanceof Number) { builder.addField("value", (Number) value); } else { builder.addField("value", String.valueOf(value)); } return builder.build(); }
Example 12
Source File: MetricDumpSerialization.java From flink with Apache License 2.0 | 5 votes |
private static void serializeGauge(DataOutput out, QueryScopeInfo info, String name, Gauge<?> gauge) throws IOException { Object value = gauge.getValue(); if (value == null) { throw new NullPointerException("Value returned by gauge " + name + " was null."); } String stringValue = value.toString(); if (stringValue == null) { throw new NullPointerException("toString() of the value returned by gauge " + name + " returned null."); } serializeMetricInfo(out, info); out.writeUTF(name); out.writeUTF(stringValue); }
Example 13
Source File: StatsDReporter.java From flink with Apache License 2.0 | 5 votes |
private void reportGauge(final String name, final Gauge<?> gauge) { Object value = gauge.getValue(); if (value == null) { return; } if (value instanceof Number) { send(numberIsNegative((Number) value), name, value.toString()); } send(name, value.toString()); }
Example 14
Source File: MetricMapper.java From flink with Apache License 2.0 | 5 votes |
static Point map(MeasurementInfo info, Instant timestamp, Gauge<?> gauge) { Point.Builder builder = builder(info, timestamp); Object value = gauge.getValue(); if (value instanceof Number) { builder.addField("value", (Number) value); } else { builder.addField("value", String.valueOf(value)); } return builder.build(); }
Example 15
Source File: StatsDReporter.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private void reportGauge(final String name, final Gauge<?> gauge) { Object value = gauge.getValue(); if (value != null) { send(name, value.toString()); } }