mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-19 01:51:10 +00:00
Add comment explaining prometheus metrics endpoint body
This commit is contained in:
@@ -487,6 +487,13 @@ where
|
|||||||
async fn return_prometheus_metrics(aggregator: AggregatorSet) -> Response<hyper::Body> {
|
async fn return_prometheus_metrics(aggregator: AggregatorSet) -> Response<hyper::Body> {
|
||||||
let metrics = aggregator.latest_metrics();
|
let metrics = aggregator.latest_metrics();
|
||||||
|
|
||||||
|
// Instead of using the rust prometheus library, we just split out the text format that prometheus expects
|
||||||
|
// ourselves, using whatever the latest metrics that we've captured so far are. See:
|
||||||
|
//
|
||||||
|
// https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#text-format-details
|
||||||
|
//
|
||||||
|
// For an example and explanation of this text based format. The minimal output we produce here seems to
|
||||||
|
// be handled correctly when pointing a current version of prometheus at it.
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
for (idx, m) in metrics.iter().enumerate() {
|
for (idx, m) in metrics.iter().enumerate() {
|
||||||
s.push_str(&format!("telemetry_connected_feeds{{aggregator=\"{}\"}} {} {}\n", idx, m.connected_feeds, m.timestamp_unix_ms));
|
s.push_str(&format!("telemetry_connected_feeds{{aggregator=\"{}\"}} {} {}\n", idx, m.connected_feeds, m.timestamp_unix_ms));
|
||||||
@@ -500,6 +507,7 @@ async fn return_prometheus_metrics(aggregator: AggregatorSet) -> Response<hyper:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Response::builder()
|
Response::builder()
|
||||||
|
// The version number here tells prometheus which version of the text format we're using:
|
||||||
.header(http::header::CONTENT_TYPE, "text/plain; version=0.0.4")
|
.header(http::header::CONTENT_TYPE, "text/plain; version=0.0.4")
|
||||||
.body(s.into())
|
.body(s.into())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|||||||
Reference in New Issue
Block a user