Class PrometheusMeterRegistry

java.lang.Object
io.micrometer.core.instrument.MeterRegistry
io.micrometer.prometheus.PrometheusMeterRegistry

public class PrometheusMeterRegistry extends io.micrometer.core.instrument.MeterRegistry
MeterRegistry for Prometheus.
  • Nested Class Summary

    Nested classes/interfaces inherited from class io.micrometer.core.instrument.MeterRegistry

    io.micrometer.core.instrument.MeterRegistry.Config, io.micrometer.core.instrument.MeterRegistry.More
  • Field Summary

    Fields inherited from class io.micrometer.core.instrument.MeterRegistry

    clock
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    PrometheusMeterRegistry(PrometheusConfig config, io.prometheus.client.CollectorRegistry registry, io.micrometer.core.instrument.Clock clock)
     
    PrometheusMeterRegistry(PrometheusConfig config, io.prometheus.client.CollectorRegistry registry, io.micrometer.core.instrument.Clock clock, io.prometheus.client.exemplars.ExemplarSampler exemplarSampler)
    Create a PrometheusMeterRegistry instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected io.micrometer.core.instrument.distribution.DistributionStatisticConfig
     
    protected TimeUnit
     
    io.prometheus.client.CollectorRegistry
     
    io.micrometer.core.instrument.Counter
    newCounter(io.micrometer.core.instrument.Meter.Id id)
     
    io.micrometer.core.instrument.DistributionSummary
    newDistributionSummary(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig, double scale)
     
    protected <T> io.micrometer.core.instrument.FunctionCounter
    newFunctionCounter(io.micrometer.core.instrument.Meter.Id id, T obj, ToDoubleFunction<T> countFunction)
     
    protected <T> io.micrometer.core.instrument.FunctionTimer
    newFunctionTimer(io.micrometer.core.instrument.Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit)
     
    protected <T> io.micrometer.core.instrument.Gauge
    newGauge(io.micrometer.core.instrument.Meter.Id id, T obj, ToDoubleFunction<T> valueFunction)
     
    protected io.micrometer.core.instrument.LongTaskTimer
    newLongTaskTimer(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig)
     
    protected io.micrometer.core.instrument.Meter
    newMeter(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.Meter.Type type, Iterable<io.micrometer.core.instrument.Measurement> measurements)
     
    protected io.micrometer.core.instrument.Timer
    newTimer(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig, io.micrometer.core.instrument.distribution.pause.PauseDetector pauseDetector)
     
     
    void
    scrape(Writer writer)
    Scrape to the specified writer in Prometheus text format.
    void
    scrape(Writer writer, String contentType)
    Write the metrics scrape body in a specific content type to the given writer.
    void
    scrape(Writer writer, String contentType, Set<String> includedNames)
    Scrape to the specified writer.
    scrape(String contentType)
    Get the metrics scrape body in a specific content type.
    scrape(String contentType, Set<String> includedNames)
    Return text for scraping.
    For use with MeterRegistry.Config#onMeterRegistrationFailed(BiConsumer) when you want meters with the same name but different tags to cause an unchecked exception.

    Methods inherited from class io.micrometer.core.instrument.MeterRegistry

    clear, close, config, counter, counter, find, forEachMeter, gauge, gauge, gauge, gauge, gaugeCollectionSize, gaugeMapSize, get, getConventionName, getConventionTags, getMeters, isClosed, meterRegistrationFailed, more, newLongTaskTimer, newTimeGauge, remove, remove, removeByPreFilterId, summary, summary, timer, timer

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PrometheusMeterRegistry

      public PrometheusMeterRegistry(PrometheusConfig config)
    • PrometheusMeterRegistry

      public PrometheusMeterRegistry(PrometheusConfig config, io.prometheus.client.CollectorRegistry registry, io.micrometer.core.instrument.Clock clock)
    • PrometheusMeterRegistry

      public PrometheusMeterRegistry(PrometheusConfig config, io.prometheus.client.CollectorRegistry registry, io.micrometer.core.instrument.Clock clock, @Nullable io.prometheus.client.exemplars.ExemplarSampler exemplarSampler)
      Create a PrometheusMeterRegistry instance.
      Parameters:
      config - configuration
      registry - collector registry
      clock - clock
      exemplarSampler - exemplar sampler
      Since:
      1.9.0
  • Method Details

    • scrape

      public String scrape()
      Returns:
      Content in Prometheus text format for the response body of an endpoint designated for Prometheus to scrape.
    • scrape

      public String scrape(String contentType)
      Get the metrics scrape body in a specific content type.
      Parameters:
      contentType - the scrape Content-Type
      Returns:
      the scrape body
      Since:
      1.7.0
      See Also:
      • TextFormat
    • scrape

      public void scrape(Writer writer) throws IOException
      Scrape to the specified writer in Prometheus text format.
      Parameters:
      writer - Target that serves the content to be scraped by Prometheus.
      Throws:
      IOException - if writing fails
      Since:
      1.2.0
    • scrape

      public void scrape(Writer writer, String contentType) throws IOException
      Write the metrics scrape body in a specific content type to the given writer.
      Parameters:
      writer - where to write the scrape body
      contentType - the Content-Type of the scrape
      Throws:
      IOException - if writing fails
      Since:
      1.7.0
      See Also:
      • TextFormat
    • scrape

      public String scrape(String contentType, @Nullable Set<String> includedNames)
      Return text for scraping.
      Parameters:
      contentType - the Content-Type of the scrape.
      includedNames - Sample names to be included. All samples will be included if null.
      Returns:
      Content that should be included in the response body for an endpoint designated for Prometheus to scrape from.
      Since:
      1.7.0
    • scrape

      public void scrape(Writer writer, String contentType, @Nullable Set<String> includedNames) throws IOException
      Scrape to the specified writer.
      Parameters:
      writer - Target that serves the content to be scraped by Prometheus.
      contentType - the Content-Type of the scrape.
      includedNames - Sample names to be included. All samples will be included if null.
      Throws:
      IOException - if writing fails
      Since:
      1.7.0
    • newCounter

      public io.micrometer.core.instrument.Counter newCounter(io.micrometer.core.instrument.Meter.Id id)
      Specified by:
      newCounter in class io.micrometer.core.instrument.MeterRegistry
    • newDistributionSummary

      public io.micrometer.core.instrument.DistributionSummary newDistributionSummary(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig, double scale)
      Specified by:
      newDistributionSummary in class io.micrometer.core.instrument.MeterRegistry
    • newTimer

      protected io.micrometer.core.instrument.Timer newTimer(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig, io.micrometer.core.instrument.distribution.pause.PauseDetector pauseDetector)
      Specified by:
      newTimer in class io.micrometer.core.instrument.MeterRegistry
    • newGauge

      protected <T> io.micrometer.core.instrument.Gauge newGauge(io.micrometer.core.instrument.Meter.Id id, @Nullable T obj, ToDoubleFunction<T> valueFunction)
      Specified by:
      newGauge in class io.micrometer.core.instrument.MeterRegistry
    • newLongTaskTimer

      protected io.micrometer.core.instrument.LongTaskTimer newLongTaskTimer(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.distribution.DistributionStatisticConfig distributionStatisticConfig)
      Overrides:
      newLongTaskTimer in class io.micrometer.core.instrument.MeterRegistry
    • newFunctionTimer

      protected <T> io.micrometer.core.instrument.FunctionTimer newFunctionTimer(io.micrometer.core.instrument.Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit)
      Specified by:
      newFunctionTimer in class io.micrometer.core.instrument.MeterRegistry
    • newFunctionCounter

      protected <T> io.micrometer.core.instrument.FunctionCounter newFunctionCounter(io.micrometer.core.instrument.Meter.Id id, T obj, ToDoubleFunction<T> countFunction)
      Specified by:
      newFunctionCounter in class io.micrometer.core.instrument.MeterRegistry
    • newMeter

      protected io.micrometer.core.instrument.Meter newMeter(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.Meter.Type type, Iterable<io.micrometer.core.instrument.Measurement> measurements)
      Specified by:
      newMeter in class io.micrometer.core.instrument.MeterRegistry
    • getBaseTimeUnit

      protected TimeUnit getBaseTimeUnit()
      Specified by:
      getBaseTimeUnit in class io.micrometer.core.instrument.MeterRegistry
    • getPrometheusRegistry

      public io.prometheus.client.CollectorRegistry getPrometheusRegistry()
      Returns:
      The underlying Prometheus CollectorRegistry.
    • defaultHistogramConfig

      protected io.micrometer.core.instrument.distribution.DistributionStatisticConfig defaultHistogramConfig()
      Specified by:
      defaultHistogramConfig in class io.micrometer.core.instrument.MeterRegistry
    • throwExceptionOnRegistrationFailure

      public PrometheusMeterRegistry throwExceptionOnRegistrationFailure()
      For use with MeterRegistry.Config#onMeterRegistrationFailed(BiConsumer) when you want meters with the same name but different tags to cause an unchecked exception.
      Returns:
      This registry
      Since:
      1.6.0