Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 783 Bytes

README.md

File metadata and controls

43 lines (32 loc) · 783 Bytes

ginprometheus

GoDoc

Send gin request metrics to prometheus

installation

go get github.com/fortnoxab/ginprometheus

usage example

package main

import (
	"flag"
	"log"
	"net/http"

	gin "gopkg.in/gin-gonic/gin.v1"
	"github.com/fortnoxab/ginprometheus"
)

var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")

func main() {
	flag.Parse()
	g := gin.Default()

	m := ginprometheus.New("http")
	m.Use(g)

	g.GET("/one/:id/", func(c *gin.Context) {
		c.String(200, "one")
	})
	g.GET("/two/:id/", func(c *gin.Context) {
		c.String(200, "two")
	})
	log.Fatal(http.ListenAndServe(*addr, g))
}