negroniprometheus

package module
v0.0.0-...-b9891e8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

negroni-prometheus GoDoc Go Report Card

Prometheus middleware for negroni.

Why

Logging v. instrumentation

Instead of logging request times, it is considered best practice to provide an endpoint for instrumentation tools (like prometheus).

Installation

$ go get github.com/zbindenren/negroni-prometheus

Usage

Use this middleware like the negroni.Logger middleware (after negroni.Recovery, before every other middleware).

Take a look at the example. It implements instrumentation by partitioning by status code, path, and method.

In other instances, instrumentation partitioned by paths can become extreme if your application has many custom endpoints. Data from instrumentation may become too much to deliver. Look at this other example.

What do you get

An endpoint with the following information (stripped output):

...
# HELP negroni_request_duration_milliseconds How long it took to process the request, partitioned by status code, method and HTTP path.
# TYPE negroni_request_duration_milliseconds histogram
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/metrics",service="serviceName",le="300"} 1
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/metrics",service="serviceName",le="1200"} 1
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/metrics",service="serviceName",le="5000"} 1
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/metrics",service="serviceName",le="+Inf"} 1
negroni_request_duration_milliseconds_sum{code="OK",method="GET",path="/metrics",service="serviceName"} 2.003123
negroni_request_duration_milliseconds_count{code="OK",method="GET",path="/metrics",service="serviceName"} 1
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/ok",service="serviceName",le="300"} 0
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/ok",service="serviceName",le="1200"} 0
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/ok",service="serviceName",le="5000"} 2
negroni_request_duration_milliseconds_bucket{code="OK",method="GET",path="/ok",service="serviceName",le="+Inf"} 2
negroni_request_duration_milliseconds_sum{code="OK",method="GET",path="/ok",service="serviceName"} 4747.529026
negroni_request_duration_milliseconds_count{code="OK",method="GET",path="/ok",service="serviceName"} 2
# HELP negroni_requests_total How many HTTP requests processed, partitioned by status code, method and HTTP path.
# TYPE negroni_requests_total counter
negroni_requests_total{code="OK",method="GET",path="/metrics",service="serviceName"} 1
negroni_requests_total{code="OK",method="GET",path="/ok",service="serviceName"} 2
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMiddleware

func NewMiddleware(name string, buckets ...float64) negroni.Handler

NewMiddleware returns a new prometheus Middleware handler.

func NewMiddlewareWithoutPath

func NewMiddlewareWithoutPath(name string, buckets ...float64) negroni.Handler

NewMiddlewareWithoutPath returns a new prometheus MiddlewareWithoutPath handler

Types

type Middleware

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

Middleware is a handler that exposes prometheus metrics for the number of requests, the latency and the response size, partitioned by status code, method and HTTP path.

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type MiddlewareWithoutPath

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

MiddlewareWithoutPath is like Middleware but will only partition latency and response size by status code and method. This is useful for applications with such a wide variety of paths that metrics would become extremely large to deliver

func (*MiddlewareWithoutPath) ServeHTTP

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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