Skip to content

Commit d43925d

Browse files
committed
plugins(stats_over_http): Add Prometheus v2 output with metric labels
The current Prometheus output in stats_over_http dumps flattened metric names (e.g., proxy.process.http.200_responses), which makes it difficult to aggregate data in Grafana or Prometheus. This adds a new "v2" output format that parses these names into proper labels like status="200" or method="GET". The new format can be accessed via /_stats/prometheus_v2 or by passing an Accept header with version=2.0.0. To keep this efficient, the parsing uses swoc::TextView for a zero- allocation approach. It recognizes common ATS patterns such as status codes, HTTP methods, cache results, and thread/volume indices. I've also added deduplication for the HELP and TYPE metadata lines, so that metrics sharing the same base name (but different labels) are grouped correctly in the output. Includes compile-time unit tests (static_assert) to verify the parsing logic and updated AuTests for the new endpoint.
1 parent dea3657 commit d43925d

File tree

5 files changed

+487
-28
lines changed

5 files changed

+487
-28
lines changed

doc/admin-guide/plugins/stats_over_http.en.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,29 @@ if you wish to have it in CSV format you can do so by passing an ``Accept`` head
105105

106106
.. option:: Accept: text/csv
107107

108-
Prometheus formatted output is also supported via the ``Accept`` header:
108+
Prometheus formatted output is also supported via the ``Accept`` header. Version 0.0.4
109+
(flat metric names) and version 2.0.0 (labeled metrics for better aggregation)
110+
are supported:
109111

110112
.. option:: Accept: text/plain; version=0.0.4
113+
.. option:: Accept: text/plain; version=2.0.0
111114

112115
Alternatively, the output format can be specified as a suffix to the configured
113116
path in the HTTP request target. The supported suffixes are ``/json``,
114-
``/csv``, and ``/prometheus``. For example, if the path is set to ``/_stats``
115-
(the default), you can access the stats in CSV format by using the URL::
117+
``/csv``, ``/prometheus``, and ``/prometheus_v2``. For example, if the path
118+
is set to ``/_stats`` (the default), you can access the stats in CSV format by
119+
using the URL::
116120

117121
http://host:port/_stats/csv
118122

119-
The Prometheus format can be requested by using the URL::
123+
The Prometheus version 0.0.4 format (flat) can be requested by using the URL::
120124

121125
http://host:port/_stats/prometheus
122126

127+
The Prometheus v2 labeled format can be requested by using the URL::
128+
129+
http://host:port/_stats/prometheus_v2
130+
123131
The JSON format is the default, but you can also access it explicitly by using the URL::
124132

125133
http://host:port/_stats/json
@@ -129,9 +137,11 @@ specify a path suffix, the plugin will return the data in that format regardless
129137
the ``Accept`` header.
130138

131139
In either case the ``Content-Type`` header returned by ``stats_over_http.so`` will
132-
reflect the content that has been returned: ``text/json``, ``text/csv``, or
133-
``text/plain; version=0.0.4; charset=utf-8`` for JSON, CSV, and Prometheus
134-
formats respectively.
140+
reflect the content that has been returned: ``text/json``, ``text/csv``,
141+
``text/plain; version=0.0.4; charset=utf-8``, or
142+
``text/plain; version=2.0.0; charset=utf-8`` for JSON, CSV, Prometheus v1, and
143+
Prometheus v2 formats respectively.
144+
135145

136146
Stats over http also accepts returning data in gzip or br compressed format per the
137147
``Accept-encoding`` header. If the header is present, the plugin will return the

0 commit comments

Comments
 (0)