2022-12-28 16:09:00 +01:00
|
|
|
module server
|
|
|
|
|
|
|
|
import metrics
|
|
|
|
import web
|
|
|
|
|
2022-12-28 17:39:45 +01:00
|
|
|
// 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 {
|
2022-12-28 17:39:45 +01:00
|
|
|
if !app.conf.collect_metrics {
|
|
|
|
return app.status(.not_found)
|
|
|
|
}
|
|
|
|
|
2023-01-28 17:35:01 +01:00
|
|
|
mut exporter := metrics.new_prometheus_exporter()
|
2023-01-04 09:19:02 +01:00
|
|
|
exporter.load('vieter_', app.collector)
|
2022-12-28 17:39:45 +01:00
|
|
|
|
2022-12-28 16:09:00 +01:00
|
|
|
// TODO stream to connection instead
|
2022-12-28 17:39:45 +01:00
|
|
|
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)
|
|
|
|
}
|