Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
3c9dc46a1c49
Commit
3c9dc46a1c49
authored
4 years ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
prometheus: build metric names from the project name
parent
90fb58063fed
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#8879
passed
4 years ago
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
templates/server/initPrometheus.gotmpl
+16
-0
16 additions, 0 deletions
templates/server/initPrometheus.gotmpl
templates/server/prometheus.gotmpl
+10
-11
10 additions, 11 deletions
templates/server/prometheus.gotmpl
with
26 additions
and
11 deletions
templates/server/initPrometheus.gotmpl
+
16
−
0
View file @
3c9dc46a
...
...
@@ -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}}
}
This diff is collapsed.
Click to expand it.
templates/server/prometheus.gotmpl
+
10
−
11
View file @
3c9dc46a
// Code generated by go-swagger with a
alpe-
api template; DO NOT EDIT.
// Code generated by go-swagger with a
go-orus
api 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_flig
h
ts",
Name: "
orus
_api_handler_in_flig
n
ts",
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,
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment