hydra: github.com/ory/hydra/metrics/prometheus Index | Files

package prometheus

import "github.com/ory/hydra/metrics/prometheus"

Index

Package Files

doc.go metrics.go middleware.go

type Metrics Uses

type Metrics struct{}

Metrics prototypes Example:

Counter      *prometheus.CounterVec
ResponseTime *prometheus.HistogramVec

func NewMetrics Uses

func NewMetrics(version, hash, date string) *Metrics

Method for creation new custom Prometheus metrics Example:

	pm := &Metrics{
		Counter: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Name:        "servicename_requests_total",
				Help:        "Description",
				ConstLabels: map[string]string{
					"version":   version,
					"hash":      hash,
					"buildTime": buildTime,
				},
			},
			[]string{"endpoint"},
		),
		ResponseTime: prometheus.NewHistogramVec(
			prometheus.HistogramOpts{
				Name:        "servicename_response_time_seconds",
				Help:        "Description",
				ConstLabels: map[string]string{
					"version":   version,
					"hash":      hash,
					"buildTime": buildTime,
				},
			},
			[]string{"endpoint"},
		),
	}
	prometheus.Register(pm.Counter)
 prometheus.Register(pm.ResponseTime)

type MetricsManager Uses

type MetricsManager struct {
    // contains filtered or unexported fields
}

func NewMetricsManager Uses

func NewMetricsManager(version, hash, buildTime string) *MetricsManager

func (*MetricsManager) ServeHTTP Uses

func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Main middleware method to collect metrics for Prometheus. Example:

start := time.Now()
next(rw, r)
Request counter metric
pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc()
Response time metric
pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds())

Package prometheus imports 1 packages (graph) and is imported by 11 packages. Updated 2019-08-25. Refresh now. Tools for package owners.