Skip to content
Snippets Groups Projects
prometheus.gotmpl 1.37 KiB
Newer Older
// Code generated by go-swagger with a go-orusapi template; DO NOT EDIT.

// Copyright Orus.io team

package {{ .Package }}

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
    {{ camelize .Name }}HandlerDuration = prometheus.NewSummaryVec(
        prometheus.SummaryOpts{
            Help: "The handlers duration and count.",
            Objectives: map[float64]float64{0.9: 0.01, 0.95: 0.01, 0.99: 0.001},
            ConstLabels: map[string]string{
                "service": "{{.Name}}",
{{- if .Tags }}
                "tag": "{{ .Tags }}",
{{- end }}
            },
        },
        []string{"code"},
    )

    {{ camelize .Name }}HandlerInFlight = prometheus.NewGauge(
        prometheus.GaugeOpts{
            Name: "orus_api_handler_in_flight",
            Help: "The number of handlers currently running.",
            ConstLabels: map[string]string{
                "service": "{{.Name}}",
{{- if .Tags }}
                "tag": "{{ .Tags }}",
{{- end }}
            },
        },
    )
)

func {{ pascalize .Name }}InstrumentHandler(handler http.Handler) http.Handler {
    return promhttp.InstrumentHandlerInFlight({{ camelize .Name }}HandlerInFlight,
        promhttp.InstrumentHandlerDuration({{ camelize .Name }}HandlerDuration,
            handler,
        ),
    )
}