prometheusmiddleware

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 7 Imported by: 5

README

prometheus-middleware Build Status Go Report Card

Prometheus middleware supports only gorilla/mux.

Installation

go get -u github.com/albertogviana/prometheus-middleware

What you will get

You will get:

  • the HTTP request duration in seconds (http_request_duration_seconds) histogram partitioned by status code, method and HTTP path.
...
# HELP http_request_duration_seconds How long it took to process the request, partitioned by status code, method and HTTP path.
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{code="200",method="get",path="/",le="0.3"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/",le="1"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/",le="2.5"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/",le="5"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/",le="+Inf"} 2
http_request_duration_seconds_sum{code="200",method="get",path="/"} 3.5256e-05
http_request_duration_seconds_count{code="200",method="get",path="/"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/metrics",le="0.3"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/metrics",le="1"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/metrics",le="2.5"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/metrics",le="5"} 2
http_request_duration_seconds_bucket{code="200",method="get",path="/metrics",le="+Inf"} 2
http_request_duration_seconds_sum{code="200",method="get",path="/metrics"} 0.001261767
http_request_duration_seconds_count{code="200",method="get",path="/metrics"} 2
...
  • HTTP request total (http_requests_total) partitioned by status code, method, and HTTP path.
...
# HELP http_requests_total How many HTTP requests processed, partitioned by status code, method and HTTP path.
# TYPE http_requests_total counter
http_requests_total{code="200",method="get",path="/"} 2
http_requests_total{code="200",method="get",path="/metrics"} 2
...

How to use it

  • Gorilla/Mux
middleware := NewPrometheusMiddleware(Opts{})

r := mux.NewRouter()
r.Handle("/metrics", promhttp.Handler())
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    fmt.Fprintln(w, "ok")
})

r.Use(middleware.InstrumentHandlerDuration)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {
	// Buckets specifies an custom buckets to be used in request histograpm.
	Buckets []float64
}

Opts specifies options how to create new PrometheusMiddleware.

type PrometheusMiddleware

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

PrometheusMiddleware specifies the metrics that is going to be generated

func NewPrometheusMiddleware

func NewPrometheusMiddleware(opts Opts) *PrometheusMiddleware

NewPrometheusMiddleware creates a new PrometheusMiddleware instance

func (*PrometheusMiddleware) InstrumentHandlerDuration

func (p *PrometheusMiddleware) InstrumentHandlerDuration(next http.Handler) http.Handler

InstrumentHandlerDuration is a middleware that wraps the http.Handler and it record how long the handler took to run, which path was called, and the status code. This method is going to be used with gorilla/mux.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL