Original post

Hello everyone, i just want to share my personal project, that add metrics for Prometheus when run a gin http-server

Repo address: https://github.com/penglongli/gin-metrics


gin-metrics defines some metrics for gin http-server. There have easy way to use it.

Below is the detailed description for every metric.

Metric Type Description
gin_request_total Counter all the server received request num.
gin_request_uv Counter all the server received ip num.
gin_uri_request_total Counter all the server received request num with every uri.
gin_request_body_total Counter the server received request body size, unit byte.
gin_response_body_total Counter the server send response body size, unit byte.
gin_request_duration Histogram the time server took to handle the request.
gin_slow_request_total Counter the server handled slow requests counter, t=%d.


Your can see some metrics across http://localhost:8080/metrics

package main

import (

func main() {
        r := gin.Default()

        // get global Monitor object
        m := ginmetrics.GetMonitor()

        // +optional set metric path, default /debug/metrics
        // +optional set slow time, default 5s
        // +optional set request duration, default {0.1, 0.3, 1.2, 5, 10}
        // used to p95, p99
        m.SetDuration([]float64{0.1, 0.3, 1.2, 5, 10})

        // set middleware for gin

        r.GET("/product/:id", func(ctx *gin.Context) {
                        "productId": ctx.Param("id"),
        _ = r.Run()

Custom Metric

You can use it to custom your own metric, contain Gauge/Counter/Histogram/Summary type.

If you met some problems, you can new an ISSUE for me.