muxprom

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: MIT Imports: 10 Imported by: 0

README

gorilla/mux Prometheus easy-to-use instrumentation

Install

go get -u github.com/rusart/muxprom

Example

package main

import (
	"github.com/gorilla/mux"
	"github.com/rusart/muxprom"
	"net/http"
)

const listen string = ":9000"

var prom *muxprom.MuxProm

func main() {
	router := mux.NewRouter().StrictSlash(true)
	prom = muxprom.New(
		muxprom.Router(router),
	)
	prom.Instrument()

	http.ListenAndServe(listen, router)
}

Options

Setting options example

prom = muxprom.New(
    muxprom.Router(router),
    muxprom.MetricsRouteName("prommetrics"),
    muxprom.MetricsPath("/health/metrics"),
)

Option Description
MetricsPath Path to the exported metrics. Default: /metrics
MetricsRouteName Route name for the exported metrics. Default: metrics. Need to override if default already in use
DurationBucket Bucket for request duration metric. Default: []float64{.0001, .0005, .001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
RespSizeBucket Bucket for response size metric. Default: []float64{0, 512, bytefmt.KILOBYTE, 100 * bytefmt.KILOBYTE, 512 * bytefmt.KILOBYTE, bytefmt.MEGABYTE, 5 * bytefmt.MEGABYTE, 10 * bytefmt.MEGABYTE, 25 * bytefmt.MEGABYTE, 50 * bytefmt.MEGABYTE, 100 * bytefmt.MEGABYTE, 500 * bytefmt.MEGABYTE}
Namespace Prometheus namespace. Default: muxprom

Grafana Dashboard

https://grafana.com/grafana/dashboards/11976

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationBucket

func DurationBucket(db []float64) func(*MuxProm)

func MetricsPath

func MetricsPath(p string) func(*MuxProm)

func MetricsRouteName

func MetricsRouteName(rn string) func(*MuxProm)

func Namespace

func Namespace(ns string) func(*MuxProm)

func RespSizeBucket

func RespSizeBucket(rsb []float64) func(*MuxProm)

func Router

func Router(r *mux.Router) func(*MuxProm)

func WrapMethodNotAllowedHandler

func WrapMethodNotAllowedHandler(h http.Handler, m mux.MiddlewareFunc) http.Handler

func WrapNotFoundHandler

func WrapNotFoundHandler(h http.Handler, m mux.MiddlewareFunc) http.Handler

Types

type MuxProm

type MuxProm struct {
	Router           *mux.Router
	Namespace        string
	MetricsPath      string
	MetricsRouteName string

	DurationBucket []float64
	RespSizeBucket []float64
	// contains filtered or unexported fields
}

func New

func New(options ...func(prom *MuxProm)) *MuxProm

func (*MuxProm) Instrument

func (prom *MuxProm) Instrument()

Jump to

Keyboard shortcuts

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