Class MetricsSnapshot

java.lang.Object
org.acemq.rabbitmq.admin.metrics.MetricsSnapshot

public final class MetricsSnapshot extends Object
Everything one scrape returned, queryable.

 MetricsSnapshot metrics = PrometheusMetrics.at("http://localhost:15692").scrapeDetailed();

 metrics.forQueue("orders.new")
        .metric("rabbitmq_detailed_queue_messages_ready")
        .map(MetricSample::asLong)
        .orElse(0L);
 

A snapshot is a moment, not a stream. Nothing here computes a rate, because a rate needs two scrapes and a clock and this holds one — takenAt() is provided so a caller comparing two snapshots can do the arithmetic honestly rather than have it guessed for them.

  • Method Details

    • samples

      public List<MetricSample> samples()
      Returns:
      every sample in the scrape
    • takenAt

      public Instant takenAt()
      Returns:
      when this scrape was taken, for a caller computing a rate across two of them
    • all

      public List<MetricSample> all(String name)
      Parameters:
      name - a metric name
      Returns:
      every sample of it — one per label combination, so one per queue on the detailed endpoint and exactly one on the aggregate endpoint
    • metric

      public Optional<MetricSample> metric(String name)
      Parameters:
      name - a metric name
      Returns:
      the single sample of it, or empty. Use all(String) where the metric is labelled: this returns the first and there is no meaningful first among queues
    • sum

      public double sum(String name)
      Parameters:
      name - a metric name
      Returns:
      the sum across every label combination. What "how many messages are waiting anywhere" means on the detailed endpoint
    • forQueue

      public MetricsSnapshot forQueue(String queue)
      Narrows to one queue.
      Parameters:
      queue - the queue's name
      Returns:
      a snapshot of only the samples labelled with it
    • withLabel

      public MetricsSnapshot withLabel(String label, String value)
      Parameters:
      label - a label name
      value - the value it must have
      Returns:
      a snapshot of only the samples carrying it
    • where

      public MetricsSnapshot where(Predicate<MetricSample> predicate)
      Parameters:
      predicate - what to keep
      Returns:
      a snapshot of the samples matching it, taken at the same moment as this one
    • queues

      public List<String> queues()
      Returns:
      the distinct queue names this snapshot has samples for
    • helpFor

      public Optional<String> helpFor(String name)
      Parameters:
      name - a metric name
      Returns:
      the broker's own description of it, from the # HELP line. Useful when generating a dashboard, where a panel wants a subtitle somebody did not have to write
    • isEmpty

      public boolean isEmpty()
      Returns:
      whether the scrape returned nothing at all
    • toString

      public String toString()
      Overrides:
      toString in class Object