Skip to content

feat(metrics): add Prometheus-compatible headers to metrics API #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(metrics): add Prometheus-compatible headers to metrics API
  • Loading branch information
pinylin committed May 29, 2025
commit 2aedc7a8d45d66ea21796c69cdb03dfb5c91f022
13 changes: 10 additions & 3 deletions pgdog/src/stats/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ async fn metrics(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Byte
.map(|m| m.to_string())
.collect();
let query_cache = query_cache.join("\n");
Ok(Response::new(Full::new(Bytes::from(
clients.to_string() + "\n" + &pools.to_string() + "\n" + &query_cache,
))))
let metrics_data = clients.to_string() + "\n" + &pools.to_string() + "\n" + &query_cache;
let response = Response::builder()
.header(
hyper::header::CONTENT_TYPE,
"text/plain; version=0.0.4; charset=utf-8",
)
.body(Full::new(Bytes::from(metrics_data)))
.expect("build metrics response");

Ok(response)
}

pub async fn server(port: u16) -> std::io::Result<()> {
Expand Down