gpmiddleware

package module
Version: v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 5 Imported by: 0

README

gin-prometheus-middleware

Go Gin middleware for Prometheus

Export metrics for request duration request_duration and request count request_count

Example

import (
    gpmiddleware "github.com/701search/gin-prometheus-middleware"
    "github.com/gin-gonic/gin"
)

func main(){
    r := gin.New()
    
    p := gpmiddleware.NewPrometheus("gin")
    p.Use(r)
    
    r.GET("/", func(c *gin.Context) {
        c.JSON(200, "Hello world! visit /metrics for metrics")
})

    r.Run(":37321")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Prometheus

type Prometheus struct {
	MetricsPath string
	// contains filtered or unexported fields
}

Prometheus contains the metrics gathered by the instance and its path

func NewPrometheus

func NewPrometheus(subsystem string) *Prometheus

NewPrometheus generates a new set of metrics with a certain subsystem name

func (*Prometheus) HandlerFunc

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

HandlerFunc defines handler function for middleware

func (*Prometheus) SetListenAddress

func (p *Prometheus) SetListenAddress(address string)

SetListenAddress for exposing metrics on address. If not set, it will be exposed at the same address of the gin engine that is being used

func (*Prometheus) SetListenAddressWithRouter

func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)

SetListenAddressWithRouter for using a separate router to expose metrics. (this keeps things like GET /metrics out of your content's access log).

func (*Prometheus) SetMetricsPath

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

SetMetricsPath set metrics paths

func (*Prometheus) Use

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

Use adds the middleware to a gin engine with /metrics route path.

func (*Prometheus) UseCustom added in v1.5.1

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

UseCustom adds the middleware to a gin engine with a custom route path.

type RequestCounterURLLabelMappingFn

type RequestCounterURLLabelMappingFn func(c *gin.Context) string

RequestCounterURLLabelMappingFn url label

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL