feat(server): add metric collection

This commit is contained in:
Jef Roosens 2022-12-28 16:09:00 +01:00
parent 8a0214babe
commit c0f58ddc77
4 changed files with 42 additions and 1 deletions

16
src/server/api_metrics.v Normal file
View file

@ -0,0 +1,16 @@
module server
import metrics
import web
['/api/v1/metrics'; get]
fn (mut app App) v1_metrics() web.Result {
mut exporter := metrics.new_prometheus_exporter([0.01, 0.05, 0.1, 0.5, 1, 100])
exporter.load(app.collector)
// TODO stream to connection instead
body := exporter.export_to_string() or {
return app.status(.internal_server_error)
}
return app.body(.ok, 'text/plain', body)
}

View file

@ -8,6 +8,7 @@ import util
import db
import build { BuildJobQueue }
import cron.expression
import metrics
const (
log_file_name = 'vieter.log'
@ -107,6 +108,7 @@ pub fn server(conf Config) ! {
repo: repo
db: db
job_queue: build.new_job_queue(global_ce, conf.base_image)
collector: metrics.new_default_collector()
}
app.init_job_queue() or {
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')