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.
- 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
If you have any good suggestions to mention issue or PR, I will check it out in detail.