forked from vieter-v/vieter
feat(metrics): add prefix; use base unit for time
parent
849bf54979
commit
60d5fb77e0
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue