vieter/src/server/api_metrics.v

20 lines
531 B
Coq
Raw Normal View History

2022-12-28 16:09:00 +01:00
module server
import metrics
import web
// v1_metrics serves a Prometheus-compatible metrics endpoint.
['/api/v1/metrics'; get; markused]
2022-12-28 16:09:00 +01:00
fn (mut app App) v1_metrics() web.Result {
if !app.conf.collect_metrics {
return app.status(.not_found)
}
2022-12-28 16:09:00 +01:00
mut exporter := metrics.new_prometheus_exporter([0.01, 0.05, 0.1, 0.5, 1, 100])
exporter.load(app.collector)
2022-12-28 16:09:00 +01:00
// TODO stream to connection instead
body := exporter.export_to_string() or { return app.status(.internal_server_error) }
2022-12-28 16:09:00 +01:00
return app.body(.ok, 'text/plain', body)
}