Package org.microproxy.stats
Class StatsFormatter
java.lang.Object
org.microproxy.stats.StatsFormatter
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
FieldsModifier and TypeFieldDescriptionstatic final StringThe content type ofprometheus(org.microproxy.stats.StatsRegistry)'s output. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringjson(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": ...}(nullwhen nothing was recorded).static Stringjson(StatsRegistry registry, Predicate<? super Metric> include) static StringmetricName(String name) nameas a Prometheus metric name: every character other than a letter, digit,_or:becomes_, and a leading digit gets a_before it.static Stringprometheus(StatsRegistry registry) The metrics in Prometheus's text exposition format, version 0.0.4: per family (metrics with the same tag-extracted name), a# HELPline when the metric has a description, a# TYPEline, and a sample per tag set; a histogram has a cumulative_bucketsample per bound (le, the last+Inf), then_sumand_count.static Stringprometheus(StatsRegistry registry, Predicate<? super Metric> include) The metricsincludeaccepts, in Prometheus's text exposition format (seeprometheus(StatsRegistry)).static Stringtext(StatsRegistry registry) The metrics as Envoy's/statstext: a linename: valueper 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), orname: No recorded values.static Stringtext(StatsRegistry registry, Predicate<? super Metric> include) static booleanWhethermetrichas been used, as Envoy'susedonlyasks: a counter or gauge that is not zero, a histogram with values.
-
Field Details
-
PROMETHEUS_CONTENT_TYPE
The content type ofprometheus(org.microproxy.stats.StatsRegistry)'s output.- See Also:
-
-
Method Details
-
prometheus
The metrics in Prometheus's text exposition format, version 0.0.4: per family (metrics with the same tag-extracted name), a# HELPline when the metric has a description, a# TYPEline, and a sample per tag set; a histogram has a cumulative_bucketsample per bound (le, the last+Inf), then_sumand_count. Families are sorted by name, samples by labels.- Parameters:
registry- the metrics- Returns:
- the exposition
-
prometheus
The metricsincludeaccepts, in Prometheus's text exposition format (seeprometheus(StatsRegistry)).- Parameters:
registry- the metricsinclude- which metrics to show; it sees each metric as read once, the value shown- Returns:
- the exposition
-
metricName
nameas 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
The metrics as Envoy's/statstext: a linename: valueper 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), orname: No recorded values.- Parameters:
registry- the metrics- Returns:
- the dump, a line per metric
-
text
- Parameters:
registry- the metricsinclude- which metrics to show; it sees each metric as read once, the value shown- Returns:
- the dump, a line per metric
-
json
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": ...}(nullwhen nothing was recorded).- Parameters:
registry- the metrics- Returns:
- the JSON document
-
json
- Parameters:
registry- the metricsinclude- which metrics to show; it sees each metric as read once, the value shown- Returns:
- the JSON document
-
used
Whethermetrichas been used, as Envoy'susedonlyasks: 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
-