diff --git a/templates/server/initPrometheus.gotmpl b/templates/server/initPrometheus.gotmpl index 90fb58063fed3800fe3efe3aa102100547c2be1d_dGVtcGxhdGVzL3NlcnZlci9pbml0UHJvbWV0aGV1cy5nb3RtcGw=..3c9dc46a1c49abeec6f72591aa522a8656c6803c_dGVtcGxhdGVzL3NlcnZlci9pbml0UHJvbWV0aGV1cy5nb3RtcGw= 100644 --- a/templates/server/initPrometheus.gotmpl +++ b/templates/server/initPrometheus.gotmpl @@ -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}} +} diff --git a/templates/server/prometheus.gotmpl b/templates/server/prometheus.gotmpl index 90fb58063fed3800fe3efe3aa102100547c2be1d_dGVtcGxhdGVzL3NlcnZlci9wcm9tZXRoZXVzLmdvdG1wbA==..3c9dc46a1c49abeec6f72591aa522a8656c6803c_dGVtcGxhdGVzL3NlcnZlci9wcm9tZXRoZXVzLmdvdG1wbA== 100644 --- a/templates/server/prometheus.gotmpl +++ b/templates/server/prometheus.gotmpl @@ -1,4 +1,4 @@ -// 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, - ) -}