promplus

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 6 Imported by: 0

README

promplus

Out-of-box HTTP middlewares to collect common prometheus metrics

go get -u github.com/absurdlab/pkg/promplus

Metrics

  • ⌚ handler duration
  • 📒 handler visit count
  • 🆗 handler response status count

Usage

target := &promplus.Target{
    Namespace: "my_company",
    Service: "my_app",
}

var h = myHandler()
h = target.Duration()(h)
h = target.VisitCount()(h)
h = target.StatusCount()(h)

Documentation

Index

Constants

View Source
const (
	LabelService = "service"
	LabelPath    = "path"
	LabelMethod  = "method"
	LabelStatus  = "status"
)

Common labels used.

Variables

This section is empty.

Functions

This section is empty.

Types

type Target

type Target struct {
	Namespace string
	Service   string
	// contains filtered or unexported fields
}

Target describes the service that is exposing the metrics.

func (*Target) Duration

func (t *Target) Duration() func(handler http.Handler) http.Handler

Duration returns an HTTP middleware that records the request duration per HTTP method and path. Multiple calls of Duration on the same Target will only register the metric once.

func (*Target) DurationMetric

func (t *Target) DurationMetric() prometheus.Collector

DurationMetric exposes the internal duration metric. It may or may not have been initialized.

func (*Target) StatusCount

func (t *Target) StatusCount() func(handler http.Handler) http.Handler

StatusCount returns an HTTP handler that counts the occurrence of status code per path, method and status. Multiple calls to StatusCount will only initialize the metric once.

func (*Target) StatusCountMetric

func (t *Target) StatusCountMetric() prometheus.Collector

StatusCountMetric exposes the status count metric. It may or may not have been initialized.

func (*Target) VisitCount

func (t *Target) VisitCount() func(handler http.Handler) http.Handler

VisitCount returns an HTTP middleware that keeps track of the number of times the endpoint is visited per path and method. Multiple calls to VisitCount will only initialize the metric once.

func (*Target) VisitCountMetric

func (t *Target) VisitCountMetric() prometheus.Collector

VisitCountMetric exposes the visit count metric. It may or may not have been initialized.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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