Skip to content
Snippets Groups Projects
Commit 3c9dc46a1c49 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

prometheus: build metric names from the project name

parent 90fb58063fed
No related branches found
No related tags found
No related merge requests found
Pipeline #8879 passed
......@@ -4,6 +4,7 @@
{{ $package := .Package }}
import (
"github.com/prometheus/client_golang/prometheus"
{{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }}
{{ end }}
)
......@@ -15,3 +16,18 @@
{{.ReceiverName}}.handlers[{{ printf "%q" (upper .Method) }}][{{ if eq .Path "/" }}""{{ else }}{{ printf "%q" (cleanPath .Path) }}{{ end }}])
{{end}}
}
func init() {
reg := prometheus.WrapRegistererWith(prometheus.Labels{
"api_name": "{{ .Name }}",
"api_title": "{{ .Info.Title }}",
"api_version": "{{ .Info.Version }}",
}, prometheus.DefaultRegisterer)
{{range .Operations}}
reg.MustRegister(
{{if ne .Package $package}}{{.Package}}.{{end}}{{ camelize .Name }}HandlerDuration,
{{if ne .Package $package}}{{.Package}}.{{end}}{{ camelize .Name }}HandlerInFlight,
)
{{end}}
}
// Code generated by go-swagger with a alpe-api template; DO NOT EDIT.
// Code generated by go-swagger with a go-orusapi template; DO NOT EDIT.
// Copyright Orus.io team
......@@ -12,5 +12,5 @@
var (
{{ camelize .Name }}HandlerDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "alpe_api_handler",
Name: "orus_api_handler",
Help: "The handlers duration and count.",
......@@ -16,4 +16,4 @@
Help: "The handlers duration and count.",
Objectives: map[float64]float64{0.9: 0.01, 0.95: 0.01, 0.99: 0.001},
Objectives: map[float64]float64{0.9: 0.01, 0.95: 0.01, 0.99: 0.001},
ConstLabels: map[string]string{
"service": "{{.Name}}",
......@@ -18,5 +18,8 @@
ConstLabels: map[string]string{
"service": "{{.Name}}",
{{- if .Tags }}
"tag": "{{ .Tags }}",
{{- end }}
},
},
[]string{"code"},
......@@ -24,7 +27,7 @@
{{ camelize .Name }}HandlerInFlight = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "alpe_api_handler_in_flights",
Name: "orus_api_handler_in_flignts",
Help: "The number of handlers currently running.",
ConstLabels: map[string]string{
"service": "{{.Name}}",
......@@ -28,6 +31,9 @@
Help: "The number of handlers currently running.",
ConstLabels: map[string]string{
"service": "{{.Name}}",
{{- if .Tags }}
"tag": "{{ .Tags }}",
{{- end }}
},
},
)
......@@ -40,10 +46,3 @@
),
)
}
func init() {
prometheus.MustRegister(
{{ camelize .Name }}HandlerDuration,
{{ camelize .Name }}HandlerInFlight,
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment