promhttpmux

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 2

README

promhttpmux

Opinionated prometheus metric exporter for Go http mux/routers, e.g.:

http_requests_total{code="200",method="GET",route="foo/bar"} 123

It exports the following metrics:

  • http_requests_total
  • http_request_duration_seconds
  • http_request_header_duration_seconds
  • http_request_size_bytes
  • http_response_size_bytes

You can find more docs at http://godoc.org/github.com/bitnami-labs/promhttpmux

Documentation

Overview

Package promhttpmux offers an opinionated metric exporter for http mux/routers.

The intended usage for this package is to just wrap your whole ServeMux with the promhttpmux.Interceptor and have it report a bunch of metrics partitioned by status code, http method and mux's pattern (aka route).

E.g.: http_requests_total{code="200",method="GET",route="/api/v1/auth/status"} 123

Usage:

http.HandleFunc("/api/v1/auth/status", statusHandler)
http.ListenAndServe(":8080", promhttpmux.Instrument(nil))

It exports the following metrics

- http_requests_total - http_request_duration_seconds - http_request_header_duration_seconds - http_request_size_bytes - http_response_size_bytes

All durations are histograms because summaries are not aggregatable (see excellent explaination why in http://latencytipoftheday.blogspot.it/2014/06/latencytipoftheday-you-cant-average.html)

Aggregation are important when you have replicas of your service.

Request and response sizes are summaries because we have no idea about reasonable bucket sizes for them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Instrument

func Instrument(m Mux) http.Handler

Instrument is a middleware that records metrics about http calls. It uses knowledge of the mux to add a route pattern label to each event.

Types

type Mux

type Mux interface {
	MuxPatternResolver
	http.Handler
}

Mux is a HTTP mux that knows how to resolve a pattern for a given request.

type MuxPatternResolver

type MuxPatternResolver interface {
	Handler(r *http.Request) (http.Handler, string)
}

MuxPatternResolver abstracts the fetching of the route pattern that matches a given request.

Jump to

Keyboard shortcuts

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