From 60d5fb77e04a697f07cfc8c5e42b17b4b3e641d4 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 4 Jan 2023 09:19:02 +0100 Subject: [PATCH] feat(metrics): add prefix; use base unit for time --- src/server/api_metrics.v | 5 +++-- src/web/web.v | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/server/api_metrics.v b/src/server/api_metrics.v index 8d6f654..cde4437 100644 --- a/src/server/api_metrics.v +++ b/src/server/api_metrics.v @@ -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) } diff --git a/src/web/web.v b/src/web/web.v index c44057e..f0f3523 100644 --- a/src/web/web.v +++ b/src/web/web.v @@ -335,11 +335,15 @@ fn handle_conn(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 )