prometheus

package
v0.0.0-...-4b55cb2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0, MIT Imports: 7 Imported by: 0

README

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_metrics
  • run the server
package main

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

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_metrics.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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GinRequestTotalCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gin_request_total",
			Help: "Number of hello requests in total",
		},
		[]string{"method", "endpoint"},
	)

	GinRequestGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "gin_request_total2",
			Help: "Number of hello requests in total",
		},
		[]string{"method", "endpoint"},
	)

	GinRequestHistogram = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "gin_request_total3",
			Help:    "Number of hello requests in total",
			Buckets: []float64{},
		},
		[]string{"method", "endpoint"},
	)

	GinRequestSummary = prometheus.NewSummaryVec(
		prometheus.SummaryOpts{
			Name:       "gin_request_time_millisecond",
			Help:       "Number of hello requests in total",
			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
		},
		[]string{"method", "endpoint"},
	)
)

Functions

func AppMetrics

func AppMetrics(app *gin.Engine)

Types

type Context

type Context struct {
	Request *http.Request

	// Keys is a key/value pair exclusively for the context of each request.
	Keys map[string]interface{}

	// Accepted defines a list of manually accepted formats for content negotiation.
	Accepted []string
	// contains filtered or unexported fields
}

type GinRoutesInfo

type GinRoutesInfo struct {
	Method  string
	Path    string
	Handler string
}

Jump to

Keyboard shortcuts

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