@Override public void set(long value) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getGauge(name).set(value); } }
/** Increment the counter by the given amount. */ @Override public void inc(long n) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getCounter(name).inc(n); } }
@Override public void update(long value) { MetricsContainer container = MetricsEnvironment.getCurrentContainer(); if (container != null) { container.getDistribution(name).update(value); } }
public static void queryMetrics(PipelineResult result) { MetricQueryResults metrics = result.metrics().queryMetrics( MetricsFilter.builder().addNameFilter(MetricNameFilter.inNamespace("PollingExample")).build()); Iterable<MetricResult<Long>> counters = metrics.getCounters(); for (MetricResult<Long> counter : counters) { System.out.println(counter.getName().name() + " : " + counter.getAttempted() + " " + Instant.now()); } }
private static MetricQueryResults queryTestMetrics(PipelineResult result) { return result .metrics() .queryMetrics( MetricsFilter.builder() .addNameFilter(MetricNameFilter.inNamespace(MetricsTest.class)) .build()); }
@SuppressWarnings("unused") @ProcessElement public void processElement(ProcessContext c) { Distribution values = Metrics.distribution(MetricsTest.class, "input"); Gauge gauge = Metrics.gauge(MetricsTest.class, "my-gauge"); Integer element = c.element(); count.inc(); values.update(element); gauge.set(12L); c.output(element); c.output(output2, element); } })
private static String getFlinkMetricNameString(String prefix, MetricResult<?> metricResult) { return prefix + METRIC_KEY_SEPARATOR + metricResult.getStep() + METRIC_KEY_SEPARATOR + metricResult.getName().getNamespace() + METRIC_KEY_SEPARATOR + metricResult.getName().getName(); }
@SuppressWarnings("unused") @ProcessElement public void processElement(ProcessContext c) { Distribution values = Metrics.distribution(MetricsTest.class, "input"); count.inc(); values.update(c.element()); c.output(c.element()); c.output(c.element()); }
/** * Counter of elements read by a source split. * * <p>Should only be used when there is a small, fixed set of split IDs so as not to overload * metrics backends. */ public static Counter elementsReadBySplit(String splitId) { return Metrics.counter(SOURCE_SPLITS_NAMESPACE, renderName(splitId, ELEMENTS_READ)); }
/** * Create a metric that can have its new value set, and is aggregated by taking the last reported * value. */ public static Gauge gauge(String namespace, String name) { return new DelegatingGauge(MetricName.named(namespace, name)); }
/** * Create a metric that can be incremented and decremented, and is aggregated by taking the sum. */ public static Counter counter(Class<?> namespace, String name) { return new DelegatingCounter(MetricName.named(namespace, name)); }
/** Create a metric that records various statistics about the distribution of reported values. */ public static Distribution distribution(String namespace, String name) { return new DelegatingDistribution(MetricName.named(namespace, name)); }
/** * Gauge for source split backlog in bytes. * * <p>Should only be used when there is a small, fixed set of split IDs so as not to overload * metrics backends. */ public static Gauge backlogBytesOfSplit(String splitId) { return Metrics.gauge(SOURCE_SPLITS_NAMESPACE, renderName(splitId, BACKLOG_BYTES)); }
/** Increment the counter. */ @Override public void inc() { inc(1); }
/** * Counter of bytes read by a source split. * * <p>Should only be used when there is a small, fixed set of split IDs so as not to overload * metrics backends. */ public static Counter bytesReadBySplit(String splitId) { return Metrics.counter(SOURCE_SPLITS_NAMESPACE, renderName(splitId, BYTES_READ)); }
/** * Create a metric that can have its new value set, and is aggregated by taking the last reported * value. */ public static Gauge gauge(Class<?> namespace, String name) { return new DelegatingGauge(MetricName.named(namespace, name)); }
/** * Create a metric that can be incremented and decremented, and is aggregated by taking the sum. */ public static Counter counter(String namespace, String name) { return new DelegatingCounter(MetricName.named(namespace, name)); }
/** Create a metric that records various statistics about the distribution of reported values. */ public static Distribution distribution(Class<?> namespace, String name) { return new DelegatingDistribution(MetricName.named(namespace, name)); }
/** * Gauge for source split backlog in elements. * * <p>Should only be used when there is a small, fixed set of split IDs so as not to overload * metrics backends. */ public static Gauge backlogElementsOfSplit(String splitId) { return Metrics.gauge(SOURCE_SPLITS_NAMESPACE, renderName(splitId, BACKLOG_ELEMENTS)); }