Interface MultiCollector
- All Known Implementing Classes:
AbstractDropwizardExports, CacheMetricsCollector, CacheMetricsCollector, DropwizardExports, DropwizardExports, SimpleclientCollector
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Collector, but collecting multiple Snapshots at once.-
Method Summary
Modifier and TypeMethodDescriptioncollect()Called when the Prometheus server scrapes metrics.default MetricSnapshotscollect(PrometheusScrapeRequest scrapeRequest) Provides Collector with the details of the request issued by Prometheus to allow multi-target pattern implementation Override to implement request dependent logic to provide MetricSnapshotdefault MetricSnapshotsdefault MetricSnapshotscollect(Predicate<String> includedNames, PrometheusScrapeRequest scrapeRequest) Likecollect(Predicate), but with support for multi-target pattern.getLabelNames(String prometheusName) Returns the complete set of label names for the given Prometheus name.default MetricMetadatagetMetadata(String prometheusName) Returns the metric metadata (name, help, unit) for the given Prometheus name.default MetricTypegetMetricType(String prometheusName) Returns the metric type for the given Prometheus name.This is called in two places: During registration to check if a metric with that name already exists.
-
Method Details
-
collect
Called when the Prometheus server scrapes metrics. -
collect
Provides Collector with the details of the request issued by Prometheus to allow multi-target pattern implementation Override to implement request dependent logic to provide MetricSnapshot -
collect
Likecollect(), but returns only the snapshots whereincludedNames.test(name)istrue.Override this if there is a more efficient way than first collecting all snapshot and then discarding the excluded ones.
-
collect
default MetricSnapshots collect(Predicate<String> includedNames, @Nullable PrometheusScrapeRequest scrapeRequest) Likecollect(Predicate), but with support for multi-target pattern.Override this if there is a more efficient way than first collecting the snapshot and then discarding it.
-
getPrometheusNames
This is called in two places:- During registration to check if a metric with that name already exists.
- During scrape to check if the collector can be skipped because a name filter is present and all names are excluded.
Returning an empty list means checks are omitted (registration metric always succeeds), and the collector is always scraped (if a name filter is present and all names are excluded the result is dropped).
If your collector returns a constant list of metrics that have names that do not change at runtime it is a good idea to overwrite this and return the names.
-
getMetricType
Returns the metric type for the given Prometheus name.This is used for per-name type validation during registration. Returning
nullmeans type validation is skipped for that specific metric name.Validation is performed only at registration time. If this method returns
null, no type validation is performed for that name, and duplicate or conflicting metrics may result in invalid exposition output.- Parameters:
prometheusName- the Prometheus metric name- Returns:
- the metric type for the given name, or
nullto skip validation
-
getLabelNames
Returns the complete set of label names for the given Prometheus name.This includes both dynamic label names and constant label names. Label names are normalized using Prometheus naming conventions (dots converted to underscores).
This is used for per-name label schema validation during registration. Two collectors with the same name and type can coexist if they have different label name sets.
Returning
nullis treated as an empty label set: the registry normalizes it toCollections.emptySet()and performs full label-schema validation and duplicate detection. Two collectors with the same name, type, andnull(or empty) label names are considered duplicate and registration of the second will fail.- Parameters:
prometheusName- the Prometheus metric name- Returns:
- the set of all label names for the given name, or
null(treated as empty) for a metric with no labels
-
getMetadata
Returns the metric metadata (name, help, unit) for the given Prometheus name.When non-null, the registry uses this to validate that metrics with the same name have consistent help and unit. Returning
nullmeans help/unit validation is skipped for that name.- Parameters:
prometheusName- the Prometheus metric name- Returns:
- the metric metadata for that name, or
nullto skip help/unit validation
-