/** * Visibility of this method must not be changed * since we deliberately not map it to json object in a Datadog-defined format. */ @Override public Number getMetricValue() { return gauge.getValue(); } }
@Override public Object getValue() { return gauge.getValue(); } }
@Override public T getValue() { return this.gauge.getValue(); }
private void reportGauge(final String name, final Gauge<?> gauge) { Object value = gauge.getValue(); if (value != null) { send(name, value.toString()); } }
@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; } };
for (Map.Entry<Gauge<?>, String> metric : gauges.entrySet()) { builder .append(metric.getValue()).append(": ").append(metric.getKey().getValue()) .append(lineSeparator);
assertEquals(0L, entry.getKey().getValue()); } else if (entry.getValue().contains(MetricNames.TASK_SLOTS_TOTAL)) { assertEquals(1L, entry.getKey().getValue()); } else if (entry.getValue().contains(MetricNames.NUM_REGISTERED_TASK_MANAGERS)) { assertEquals(1L, entry.getKey().getValue()); } else if (entry.getValue().contains(MetricNames.NUM_RUNNING_JOBS)) { assertEquals(1L, entry.getKey().getValue());
Assert.assertEquals(Long.MIN_VALUE, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInput1WatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInput2WatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, headInput1WatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInput2WatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, headInput1WatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headInput2WatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, chainedOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(3L, headInput1WatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headInput2WatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headOutputWatermarkGauge.getValue().longValue());
.size()); Assert.assertEquals(Long.MIN_VALUE, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(Long.MIN_VALUE, chainedOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(1L, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(4L, chainedOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, taskInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(2L, headInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(4L, headOutputWatermarkGauge.getValue().longValue()); Assert.assertEquals(4L, chainedInputWatermarkGauge.getValue().longValue()); Assert.assertEquals(8L, chainedOutputWatermarkGauge.getValue().longValue());
@Override public Object getValue() { return gauge.getValue(); } }
@Override public T getValue() { return this.gauge.getValue(); }
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 = gauge.getValue().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); }
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); }
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); }
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); }
public static String toString(Metric metric) { if (metric instanceof Counter) { return Long.toString(((Counter) metric).getCount()); } else if (metric instanceof Gauge) { return ((Gauge) metric).getValue().toString(); } else if (metric instanceof Meter) { return Double.toString(((Meter) metric).getRate()); } else if (metric instanceof Histogram) { HistogramStatistics stats = ((Histogram) metric).getStatistics(); return String.format( "count=%d, min=%d, max=%d, mean=%f, stddev=%f, p50=%f, p75=%f, p95=%f", stats.size(), stats.getMin(), stats.getMax(), stats.getMean(), stats.getStdDev(), stats.getQuantile(0.5), stats.getQuantile(0.75), stats.getQuantile(0.95)); } else { throw new IllegalStateException( String.format( "Cannot remove unknown metric type %s. This indicates that the reporter " + "does not support this metric type.", metric.getClass().getName())); } } }