feat(metrics): add prefix; use base unit for time

dev
Jef Roosens 2023-01-04 09:19:02 +01:00
parent 849bf54979
commit 60d5fb77e0
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 9 additions and 4 deletions

View File

@ -10,8 +10,9 @@ fn (mut app App) v1_metrics() web.Result {
return app.status(.not_found)
}
mut exporter := metrics.new_prometheus_exporter([0.01, 0.05, 0.1, 0.5, 1, 100])
exporter.load(app.collector)
mut exporter := metrics.new_prometheus_exporter([0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5,
10])
exporter.load('vieter_', app.collector)
// TODO stream to connection instead
body := exporter.export_to_string() or { return app.status(.internal_server_error) }

View File

@ -335,11 +335,15 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
labels := [
['method', app.req.method.str()]!,
['path', app.req.url]!,
// Not all methods properly set this value yet I think
['status', app.status.int().str()]!,
]
app.collector.counter_increment(name: 'http_requests_total', labels: labels)
app.collector.histogram_record(time.ticks() - app.page_gen_start,
name: 'http_requests_time_ms'
// Prometheus prefers metrics containing base units, as defined here
// https://prometheus.io/docs/practices/naming/
app.collector.histogram_record(f64(time.ticks() - app.page_gen_start) / 1000,
name: 'http_requests_duration_seconds'
labels: labels
)