Class StatsFormatter

java.lang.Object
org.microproxy.stats.StatsFormatter

public final class StatsFormatter extends Object
Renders a registry's metrics as Envoy's admin endpoint does: Prometheus's text exposition format, the plain /stats dump and its JSON form.

Prometheus names are the registry's prefix, _, and the tag-extracted name with its dots made _; the tags are labels: envoy_cluster_upstream_rq_xx{envoy_response_code_class="2", envoy_cluster_name="direct"} 7. The other forms use the flat names.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    json(StatsRegistry registry)
    The metrics as Envoy's /stats?format=json: {"stats": [...]} with an object {"name": ..., "value": ...} per counter and gauge, sorted by flat name, and last an object {"histograms": {"supported_quantiles": [...], "computed_quantiles": [...]}} whose entries give each histogram's estimated quantiles as {"interval": null, "cumulative": ...} (null when nothing was recorded).
    static String
    json(StatsRegistry registry, Predicate<? super Metric> include)
    The metrics include accepts, as Envoy's /stats?format=json (see json(StatsRegistry)).
    static String
    name as a Prometheus metric name: every character other than a letter, digit, _ or : becomes _, and a leading digit gets a _ before it.
    static String
    The metrics in Prometheus's text exposition format, version 0.0.4: per family (metrics with the same tag-extracted name), a # HELP line when the metric has a description, a # TYPE line, and a sample per tag set; a histogram has a cumulative _bucket sample per bound (le, the last +Inf), then _sum and _count.
    static String
    prometheus(StatsRegistry registry, Predicate<? super Metric> include)
    The metrics include accepts, in Prometheus's text exposition format (see prometheus(StatsRegistry)).
    static String
    text(StatsRegistry registry)
    The metrics as Envoy's /stats text: a line name: value per counter and gauge, sorted by flat name, then a line per histogram with its estimated quantiles, name: P0(nan,0.5) P25(nan,1.2) ... (Envoy's interval values are not kept: nan), or name: No recorded values.
    static String
    text(StatsRegistry registry, Predicate<? super Metric> include)
    The metrics include accepts, as Envoy's /stats text (see text(StatsRegistry)).
    static boolean
    used(Metric metric)
    Whether metric has been used, as Envoy's usedonly asks: a counter or gauge that is not zero, a histogram with values.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • prometheus

      public static String prometheus(StatsRegistry registry)
      The metrics in Prometheus's text exposition format, version 0.0.4: per family (metrics with the same tag-extracted name), a # HELP line when the metric has a description, a # TYPE line, and a sample per tag set; a histogram has a cumulative _bucket sample per bound (le, the last +Inf), then _sum and _count. Families are sorted by name, samples by labels.
      Parameters:
      registry - the metrics
      Returns:
      the exposition
    • prometheus

      public static String prometheus(StatsRegistry registry, Predicate<? super Metric> include)
      The metrics include accepts, in Prometheus's text exposition format (see prometheus(StatsRegistry)).
      Parameters:
      registry - the metrics
      include - which metrics to show; it sees each metric as read once, the value shown
      Returns:
      the exposition
    • metricName

      public static String metricName(String name)
      name as a Prometheus metric name: every character other than a letter, digit, _ or : becomes _, and a leading digit gets a _ before it.
      Parameters:
      name - a tag-extracted stat name
      Returns:
      the Prometheus name, without the prefix
    • text

      public static String text(StatsRegistry registry)
      The metrics as Envoy's /stats text: a line name: value per counter and gauge, sorted by flat name, then a line per histogram with its estimated quantiles, name: P0(nan,0.5) P25(nan,1.2) ... (Envoy's interval values are not kept: nan), or name: No recorded values.
      Parameters:
      registry - the metrics
      Returns:
      the dump, a line per metric
    • text

      public static String text(StatsRegistry registry, Predicate<? super Metric> include)
      The metrics include accepts, as Envoy's /stats text (see text(StatsRegistry)).
      Parameters:
      registry - the metrics
      include - which metrics to show; it sees each metric as read once, the value shown
      Returns:
      the dump, a line per metric
    • json

      public static String json(StatsRegistry registry)
      The metrics as Envoy's /stats?format=json: {"stats": [...]} with an object {"name": ..., "value": ...} per counter and gauge, sorted by flat name, and last an object {"histograms": {"supported_quantiles": [...], "computed_quantiles": [...]}} whose entries give each histogram's estimated quantiles as {"interval": null, "cumulative": ...} (null when nothing was recorded).
      Parameters:
      registry - the metrics
      Returns:
      the JSON document
    • json

      public static String json(StatsRegistry registry, Predicate<? super Metric> include)
      The metrics include accepts, as Envoy's /stats?format=json (see json(StatsRegistry)).
      Parameters:
      registry - the metrics
      include - which metrics to show; it sees each metric as read once, the value shown
      Returns:
      the JSON document
    • used

      public static boolean used(Metric metric)
      Whether metric has been used, as Envoy's usedonly asks: a counter or gauge that is not zero, a histogram with values. (Envoy remembers whether a stat was ever written, so it also shows a gauge set back to zero; this registry keeps no such mark.)
      Parameters:
      metric - the metric
      Returns:
      whether it has a value worth showing