ginprom: Index | Examples | Files

package ginprom

import ""

Package ginprom is a library to instrument a gin server and expose a /metrics endpoint for Prometheus to scrape, keeping a low cardinality by preserving the path parameters name in the prometheus label



Package Files

prom.go reqsize.go

func BucketSize Uses

func BucketSize(b []float64) func(*Prometheus)

func Engine Uses

func Engine(e *gin.Engine) func(*Prometheus)

Engine is an option allowing to set the gin engine when intializing with New. Example : r := gin.Default() p := ginprom.New(Engine(r))

func Ignore Uses

func Ignore(paths ...string) func(*Prometheus)

Ignore is used to disable instrumentation on some routes

func Namespace Uses

func Namespace(ns string) func(*Prometheus)

Namespace is an option allowing to set the namespace when intitializing with New

func Path Uses

func Path(path string) func(*Prometheus)

Path is an option allowing to set the metrics path when intializing with New

Set the path (endpoint) where the metrics will be served


r := gin.New()
p := New(Engine(r), Path("/metrics"))

func Registry Uses

func Registry(r *prometheus.Registry) func(*Prometheus)

Registry is an option allowing to set a *prometheus.Registry with New. Use this option if you want to use a custom Registry instead of a global one that prometheus client uses by default Example : r := gin.Default() p := ginprom.New(Registry(r))

func Subsystem Uses

func Subsystem(sub string) func(*Prometheus)

Subsystem is an option allowing to set the subsystem when intitializing with New

func Token Uses

func Token(token string) func(*Prometheus)

Token is an option allowing to set the bearer token in prometheus with New. Example : ginprom.New(ginprom.Token("your_custom_token"))

Set a secret token that is required to access the endpoint


r := gin.New()
p := New(Engine(r), Token("supersecrettoken"))

type Prometheus Uses

type Prometheus struct {
    MetricsPath string
    Namespace   string
    Subsystem   string
    Token       string
    Ignored     pmapb
    Engine      *gin.Engine
    PathMap     pmap
    BucketsSize []float64
    Registry    *prometheus.Registry
    // contains filtered or unexported fields

Prometheus contains the metrics gathered by the instance and its path

func New Uses

func New(options ...func(*Prometheus)) *Prometheus

New will initialize a new Prometheus instance with the given options. If no options are passed, sane defaults are used. If a router is passed using the Engine() option, this instance will automatically bind to it.

func (*Prometheus) AddCustomGauge Uses

func (p *Prometheus) AddCustomGauge(name, help string, labels []string)

AddCustomGauge adds a custom gauge and registers it

func (*Prometheus) DecrementGaugeValue Uses

func (p *Prometheus) DecrementGaugeValue(name string, labelValues []string) error

DecrementGaugeValue decrements a custom gauge

func (*Prometheus) IncrementGaugeValue Uses

func (p *Prometheus) IncrementGaugeValue(name string, labelValues []string) error

IncrementGaugeValue increments a custom gauge

func (*Prometheus) Instrument Uses

func (p *Prometheus) Instrument() gin.HandlerFunc

Instrument is a gin middleware that can be used to generate metrics for a single handler

func (*Prometheus) SetGaugeValue Uses

func (p *Prometheus) SetGaugeValue(name string, labelValues []string, value float64) error

SetGaugeValue set gauge to value

func (*Prometheus) Use Uses

func (p *Prometheus) Use(e *gin.Engine)

Use is a method that should be used if the engine is set after middleware initialization

Package ginprom imports 9 packages (graph) and is imported by 4 packages. Updated 2020-11-22. Refresh now. Tools for package owners.