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.

Like Collector, but collecting multiple Snapshots at once.
  • 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

      default MetricSnapshots collect(Predicate<String> includedNames)
      Like collect(), but returns only the snapshots where includedNames.test(name) is true.

      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)
      Like collect(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:
      1. During registration to check if a metric with that name already exists.
      2. 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

      @Nullable default MetricType getMetricType(String prometheusName)
      Returns the metric type for the given Prometheus name.

      This is used for per-name type validation during registration. Returning null means 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 null to skip validation
    • getLabelNames

      @Nullable default Set<String> getLabelNames(String prometheusName)
      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 null is treated as an empty label set: the registry normalizes it to Collections.emptySet() and performs full label-schema validation and duplicate detection. Two collectors with the same name, type, and null (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

      @Nullable default MetricMetadata getMetadata(String prometheusName)
      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 null means help/unit validation is skipped for that name.

      Parameters:
      prometheusName - the Prometheus metric name
      Returns:
      the metric metadata for that name, or null to skip help/unit validation