All Implemented Interfaces:
DataPoint, DistributionDataPoint, TimerApi, io.prometheus.metrics.model.registry.Collector

public class Summary extends MetricWithFixedMetadata implements DistributionDataPoint
Summary metric. Example:

 Summary summary = Summary.builder()
         .name("http_request_duration_seconds_hi")
         .help("HTTP request service time in seconds")
         .unit(SECONDS)
         .labelNames("method", "path", "status_code")
         .quantile(0.5, 0.01)
         .quantile(0.95, 0.001)
         .quantile(0.99, 0.001)
         .register();

 long start = System.nanoTime();
 // process a request, duration will be observed
 summary.labelValues("GET", "/", "200").observe(Unit.nanosToSeconds(System.nanoTime() - start));
 
See Summary.Builder for configuration options.
  • Method Details

    • isExemplarsEnabled

      protected boolean isExemplarsEnabled()
    • observe

      public void observe(double amount)
      Description copied from interface: DistributionDataPoint
      Observe value.
      Specified by:
      observe in interface DistributionDataPoint
    • observeWithExemplar

      public void observeWithExemplar(double amount, io.prometheus.metrics.model.snapshots.Labels labels)
      Description copied from interface: DistributionDataPoint
      Observe value, and create a custom exemplar with the given labels.
      Specified by:
      observeWithExemplar in interface DistributionDataPoint
    • collect

      public io.prometheus.metrics.model.snapshots.SummarySnapshot collect()
      Specified by:
      collect in interface io.prometheus.metrics.model.registry.Collector
    • collect

      protected io.prometheus.metrics.model.snapshots.SummarySnapshot collect(List<io.prometheus.metrics.model.snapshots.Labels> labels, List<Summary.DataPoint> metricData)
      labels and metricData have the same size. labels.get(i) are the labels for metricData.get(i).
    • newDataPoint

      protected Summary.DataPoint newDataPoint()
    • builder

      public static Summary.Builder builder()
    • builder

      public static Summary.Builder builder(io.prometheus.metrics.config.PrometheusProperties config)
    • initLabelValues

      public void initLabelValues(String... labelValues)
      Initialize label values.

      Example: Imagine you have a counter for payments as follows

       payment_transactions_total{payment_type="credit card"} 7.0
       payment_transactions_total{payment_type="paypal"} 3.0
       
      Now, the data points for the payment_type label values get initialized when they are first used, i.e. the first time you call
      
       counter.labelValues("paypal").inc();
       
      the data point with label payment_type="paypal" will go from non-existent to having value 1.0.

      In some cases this is confusing, and you want to have data points initialized on application start with an initial value of 0.0:

       payment_transactions_total{payment_type="credit card"} 0.0
       payment_transactions_total{payment_type="paypal"} 0.0
       
      initLabelValues(...) can be used to initialize label value, so that the data points show up in the exposition format with an initial value of zero.
    • labelValues

      public DistributionDataPoint labelValues(String... labelValues)
    • remove

      public void remove(String... labelValues)
      Remove the data point with the given label values. See https://prometheus.io/docs/instrumenting/writing_clientlibs/#labels.
    • removeIf

      public void removeIf(Function<List<String>,Boolean> f)
      Remove the data points when the given function.
    • clear

      public void clear()
      Reset the metric (remove all data points).
    • getNoLabels

      protected Summary.DataPoint getNoLabels()
    • getMetricProperties

      protected io.prometheus.metrics.config.MetricsProperties[] getMetricProperties(io.prometheus.metrics.core.metrics.StatefulMetric.Builder<?,?> builder, io.prometheus.metrics.config.PrometheusProperties prometheusProperties)
    • getConfigProperty

      protected <P> P getConfigProperty(io.prometheus.metrics.config.MetricsProperties[] properties, Function<io.prometheus.metrics.config.MetricsProperties,P> getter)