Class Metrics
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 extendsDoFn<String, String> {
private Counter counter = Metrics.counter(SomeDoFn.class, "my-counter");
@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.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic BoundedTrie
boundedTrie
(Class<?> namespace, String name) Create a metric that accumulates and reports set of unique string values bounded to a max limit.static BoundedTrie
boundedTrie
(String namespace, String name) Create a metric that accumulates and reports set of unique string values bounded to a max limit.static Counter
Create a metric that can be incremented and decremented, and is aggregated by taking the sum.static Counter
Create a metric that can be incremented and decremented, and is aggregated by taking the sum.static Distribution
distribution
(Class<?> namespace, String name) Create a metric that records various statistics about the distribution of reported values.static Distribution
distribution
(String namespace, String name) Create a metric that records various statistics about the distribution of reported values.static Gauge
Create a metric that can have its new value set, and is aggregated by taking the last reported value.static Gauge
Create a metric that can have its new value set, and is aggregated by taking the last reported value.static Gauge
gauge
(MetricName metricName) Create a metric that can have its new value set, and is aggregated by taking the last reported value.static void
setDefaultPipelineOptions
(PipelineOptions options) Initialize metrics flags if not already done so.static StringSet
Create a metric that accumulates and reports set of unique string values.static StringSet
Create a metric that accumulates and reports set of unique string values.
-
Field Details
-
THROTTLE_TIME_NAMESPACE
- See Also:
-
THROTTLE_TIME_COUNTER_NAME
- See Also:
-
-
Method Details
-
setDefaultPipelineOptions
Initialize metrics flags if not already done so.Should be called by worker at worker harness initialization. Should not be called by user code (and it does not have an effect as the initialization completed before).
-
counter
Create a metric that can be incremented and decremented, and is aggregated by taking the sum. -
counter
Create a metric that can be incremented and decremented, and is aggregated by taking the sum. -
distribution
Create a metric that records various statistics about the distribution of reported values. -
distribution
Create a metric that records various statistics about the distribution of reported values. -
gauge
Create a metric that can have its new value set, and is aggregated by taking the last reported value. -
gauge
Create a metric that can have its new value set, and is aggregated by taking the last reported value. -
gauge
Create a metric that can have its new value set, and is aggregated by taking the last reported value. -
stringSet
Create a metric that accumulates and reports set of unique string values. -
stringSet
Create a metric that accumulates and reports set of unique string values. -
boundedTrie
Create a metric that accumulates and reports set of unique string values bounded to a max limit. -
boundedTrie
Create a metric that accumulates and reports set of unique string values bounded to a max limit.
-