Skip to content

Latest commit

 

History

History
78 lines (58 loc) · 2.04 KB

README.md

File metadata and controls

78 lines (58 loc) · 2.04 KB

The Gin Framework Metrics Middleware

Build Status

Preface

Many small companies don't have such a large architecture for micro-services when they do websites. A simple solution for viewing application traffic is very important. This repository is a middleware that integrates seamlessly with Gin.

gin_metrics_v1

How to use

  • install the metrics lib
go get github.com/kylesliu/gin_exporter
  • run the server
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/kylesliu/gin_exporter"
)

func main() {
	app := gin.Default()
	gin.SetMode(gin.DebugMode)

	app.GET("demo1", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "demo1",
		})
	})

	gin_exporter.Default(app)

	if err := app.Run("127.0.0.1:9000"); err != nil {
		panic(err.Error())
	}
}
  • Config the Prometheus
  - job_name: 'gin_metrics'
    static_configs:
    - targets: ['localhost:9000']
  • Config the Grafana

Grafana Dashboard

Last

If you have any good suggestions to mention issue or PR, I will check it out in detail.