ginprom

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2018 License: MIT Imports: 7 Imported by: 80

README

ginprom

Gin Prometheus metrics exporter inspired by github.com/zsais/go-gin-prometheus

Go Version Go Version Go Report Card Build Status codecov License

Install

Simply run : go get -u github.com/Depado/ginprom

Differences with go-gin-prometheus

  • No support for Prometheus' Push Gateway
  • Options on constructor
  • Adds a path label to get the matched route

Usage

package main

import (
	"github.com/Depado/ginprom"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	p := ginprom.New(ginprom.Subsystem("gin"), ginprom.Path("/metrics"), ginprom.Engine(r))
	r.Use(p.Instrument())

	r.GET("/hello/:id", func(c *gin.Context) {})
	r.GET("/world/:id", func(c *gin.Context) {})
	r.Run("127.0.0.1:8080")
}

Options

Path(path string)
Specify the path on which the metrics are accessed
Default : "/metrics"

Subsystem(sub string)
Specify the subsystem
Default : "gin"

Engine(e *gin.Engine)
Specify the Gin engine directly when intializing. Saves a call to Use(e *gin.Engine)
Default : nil

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Engine

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

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

Ignore is used to disable instrumentation on some routes

func Path

func Path(path string) func(*Prometheus)

Path is an option allowing to set the metrics path when intializing with New. Example : ginprom.New(ginprom.Path("/mymetrics"))

func Subsystem

func Subsystem(sub string) func(*Prometheus)

Subsystem is an option allowing to set the subsystem when intitializing with New. Example : ginprom.New(ginprom.Subsystem("my_system"))

Types

type Prometheus

type Prometheus struct {
	MetricsPath string
	Subsystem   string
	Ignored     pmapb
	Engine      *gin.Engine
	PathMap     pmap
	// contains filtered or unexported fields
}

Prometheus contains the metrics gathered by the instance and its path

func New

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) Instrument

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

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

func (*Prometheus) Use

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

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

Jump to

Keyboard shortcuts

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