@Experimental(value=METRICS) public class Metrics extends java.lang.Object
Metrics
is a utility class for producing various kinds of metrics for
reporting properties of an executing pipeline.
Metrics are created by calling one of the static methods in this class. Each metric is associated with a namespace and a name. The namespace allows grouping related metrics together based on the definition while also disambiguating common names based on where they are defined.
Reported metrics are implicitly scoped to the transform within the pipeline that reported them. This allows reporting the same metric name in multiple places and identifying the value each transform reported, as well as aggregating the metric across
It is runner-dependent whether Metrics are accessible during pipeline execution or only after jobs have completed.
Example:
class SomeDoFn extends DoFn<String, String> {
private Counter counter = Metrics.counter(SomeDoFn.class, "my-counter");
{@literal @}ProcessElement
public void processElement(ProcessContext c) {
counter.inc();
Metrics.counter(SomeDoFn.class, "my-counter2").inc();
}
}
See MetricResults
(available from the PipelineResults
interface) for an
example off how to query metrics.
Modifier and Type | Method and Description |
---|---|
static Counter |
counter(java.lang.Class<?> namespace,
java.lang.String name)
Create a metric that can be incremented and decremented, and is aggregated by taking the sum.
|
static Counter |
counter(java.lang.String namespace,
java.lang.String name)
Create a metric that can be incremented and decremented, and is aggregated by taking the sum.
|
static Distribution |
distribution(java.lang.Class<?> namespace,
java.lang.String name)
Create a metric that records various statistics about the distribution of reported values.
|
static Distribution |
distribution(java.lang.String namespace,
java.lang.String name)
Create a metric that records various statistics about the distribution of reported values.
|
static Gauge |
gauge(java.lang.Class<?> namespace,
java.lang.String name)
Create a metric that can have its new value set, and is aggregated by taking the last reported
value.
|
static Gauge |
gauge(java.lang.String namespace,
java.lang.String name)
Create a metric that can have its new value set, and is aggregated by taking the last reported
value.
|
public static Counter counter(java.lang.String namespace, java.lang.String name)
public static Counter counter(java.lang.Class<?> namespace, java.lang.String name)
public static Distribution distribution(java.lang.String namespace, java.lang.String name)
public static Distribution distribution(java.lang.Class<?> namespace, java.lang.String name)
public static Gauge gauge(java.lang.String namespace, java.lang.String name)
public static Gauge gauge(java.lang.Class<?> namespace, java.lang.String name)