All Projects → penglongli → gin-metrics

penglongli / gin-metrics

Licence: MIT License
gin-gonic/gin metrics for prometheus.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gin-metrics

Prometheus To Cloudwatch
Utility for scraping Prometheus metrics from a Prometheus client endpoint and publishing them to CloudWatch
Stars: ✭ 127 (+45.98%)
Mutual labels:  metrics, prometheus-exporter
Bull exporter
Prometheus exporter for Bull metrics
Stars: ✭ 149 (+71.26%)
Mutual labels:  metrics, prometheus-exporter
Go Http Metrics
Go modular http middleware to measure HTTP requests independent of metrics backend (with Prometheus and OpenCensus as backend implementations) and http framework/library
Stars: ✭ 128 (+47.13%)
Mutual labels:  metrics, gin
Tomcat exporter
A Prometheus exporter for Apache Tomcat
Stars: ✭ 99 (+13.79%)
Mutual labels:  metrics, prometheus-exporter
Aliyun Exporter
Prometheus exporter for Alibaba Cloud Monitor
Stars: ✭ 210 (+141.38%)
Mutual labels:  metrics, prometheus-exporter
Memcached exporter
Exports metrics from memcached servers for consumption by Prometheus.
Stars: ✭ 109 (+25.29%)
Mutual labels:  metrics, prometheus-exporter
Redis exporter
Prometheus Exporter for Redis Metrics. Supports Redis 2.x, 3.x, 4.x, 5.x and 6.x
Stars: ✭ 2,092 (+2304.6%)
Mutual labels:  metrics, prometheus-exporter
Gin Gomonitor
Gin middleware for monitoring
Stars: ✭ 59 (-32.18%)
Mutual labels:  metrics, gin
Query Exporter
Export Prometheus metrics from SQL queries
Stars: ✭ 166 (+90.8%)
Mutual labels:  metrics, prometheus-exporter
Minecraft Prometheus Exporter
A Bukkit plugin which exports minecraft server stats to Prometheus
Stars: ✭ 150 (+72.41%)
Mutual labels:  metrics, prometheus-exporter
Systemd exporter
Exporter for systemd unit metrics
Stars: ✭ 82 (-5.75%)
Mutual labels:  metrics, prometheus-exporter
Github Exporter
Prometheus exporter for github metrics
Stars: ✭ 231 (+165.52%)
Mutual labels:  metrics, prometheus-exporter
Citrix Adc Metrics Exporter
Export metrics from Citrix ADC (NetScaler) to Prometheus
Stars: ✭ 67 (-22.99%)
Mutual labels:  metrics, prometheus-exporter
Bigbluebutton Exporter
Prometheus exporter for BigBlueButton
Stars: ✭ 117 (+34.48%)
Mutual labels:  metrics, prometheus-exporter
Prom Confluence Exporter
Prometheus Exporter For Confluence
Stars: ✭ 62 (-28.74%)
Mutual labels:  metrics, prometheus-exporter
Sidekiq Prometheus Exporter
All the basic metrics of Sidekiq with pluggable contribs prepared for Prometheus
Stars: ✭ 129 (+48.28%)
Mutual labels:  metrics, prometheus-exporter
Kafka exporter
Kafka exporter for Prometheus
Stars: ✭ 996 (+1044.83%)
Mutual labels:  metrics, prometheus-exporter
Promcord
📊 Analyze your entire discord guild in grafana using prometheus. Message, User, Game and Voice statistics...
Stars: ✭ 39 (-55.17%)
Mutual labels:  metrics, prometheus-exporter
Pagespeed exporter
Prometheus pagespeed exporter
Stars: ✭ 149 (+71.26%)
Mutual labels:  metrics, prometheus-exporter
Ssl exporter
Exports Prometheus metrics for SSL certificates
Stars: ✭ 211 (+142.53%)
Mutual labels:  metrics, prometheus-exporter

gin-metrics

gin-gonic/gin metrics exporter for Prometheus.

中文

Introduction

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.

Grafana

Set the grafana directory for details.

grafana

Installation

$ go get github.com/penglongli/gin-metrics

Usage

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

package main

import (
	"github.com/gin-gonic/gin"

	"github.com/penglongli/gin-metrics/ginmetrics"
)

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

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

	// +optional set metric path, default /debug/metrics
	m.SetMetricPath("/metrics")
	// +optional set slow time, default 5s
	m.SetSlowTime(10)
	// +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
	m.Use(r)

	r.GET("/product/:id", func(ctx *gin.Context) {
		ctx.JSON(200, map[string]string{
			"productId": ctx.Param("id"),
		})
	})

	_ = r.Run()
}

Custom Metric

gin-metric provides ways to custom your own metric.

Gauge

With Gauge type metric, you can use three functions to change it's value.

And you should define a Gauge Metric first,

gaugeMetric := &ginmetrics.Metric{
    Type:        ginmetrics.Gauge,
    Name:        "example_gauge_metric",
    Description: "an example of gauge type metric",
    Labels:      []string{"label1"},
}

// Add metric to global monitor object
_ = ginmetrics.GetMonitor().AddMetric(gaugeMetric)

SetGaugeValue

SetGaugeValue will setting metric value directly。

_ = ginmetrics.GetMonitor().GetMetric("example_gauge_metric").SetGaugeValue([]string{"label_value1"}, 0.1)

Inc

Inc will increase 1 to metric value

_ = ginmetrics.GetMonitor().GetMetric("example_gauge_metric").Inc([]string{"label_value1"})

Add

Add will add float64 num to metric value

_ = ginmetrics.GetMonitor().GetMetric("example_gauge_metric").Add([]string{"label_value1"}, 0.2)

Counter

With Counter type metric, you can use Inc and Add function, don't use SetGaugeValue.

Histogram and Summary

For Histogram and Summary type metric, should use Observe function.

Metric with separate port

For some users, they don't want to merge the port of the metric with the port of the application.

So we provide a way to separate the metric port. Here is the example.

func main() {
	appRouter := gin.Default()
	metricRouter := gin.Default()

	m := ginmetrics.GetMonitor()
	// use metric middleware without expose metric path
	m.UseWithoutExposingEndpoint(appRouter)
	// set metric path expose to metric router
	m.Expose(metricRouter)

	appRouter.GET("/product/:id", func(ctx *gin.Context) {
		ctx.JSON(200, map[string]string{
			"productId": ctx.Param("id"),
		})
	})
	go func() {
		_ = metricRouter.Run(":8081")
	}()
	_ = appRouter.Run(":8080")
}

Contributing

If someone has a problem or suggestions, you can submit new issues or new pull requests.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].