All Projects → Depado → ginprom

Depado / ginprom

Licence: MIT license
Gin Prometheus metrics exporter inspired by https://github.com/zsais/go-gin-prometheus

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to ginprom

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 (+31.96%)
Mutual labels:  prometheus, instrumentation, gin
Go Project Sample
Introduce the best practice experience of Go project with a complete project example.通过一个完整的项目示例介绍Go语言项目的最佳实践经验.
Stars: ✭ 344 (+254.64%)
Mutual labels:  prometheus, gin
Prometheus.ex
Prometheus.io Elixir client
Stars: ✭ 343 (+253.61%)
Mutual labels:  prometheus, instrumentation
Microservice learning
从零开始微服务框架使用
Stars: ✭ 31 (-68.04%)
Mutual labels:  prometheus, gin
ginprom
📡 Prometheus metrics exporter for Gin.
Stars: ✭ 110 (+13.4%)
Mutual labels:  prometheus, gin
Prometheus.erl
Prometheus.io client in Erlang
Stars: ✭ 276 (+184.54%)
Mutual labels:  prometheus, instrumentation
Go Gin Api
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用 等等。
Stars: ✭ 730 (+652.58%)
Mutual labels:  prometheus, gin
druid-prometheus-exporter
Service to collect Apache Druid metrics and export them to Prometheus
Stars: ✭ 14 (-85.57%)
Mutual labels:  prometheus, gin
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+1947.42%)
Mutual labels:  prometheus, instrumentation
Client java
Prometheus instrumentation library for JVM applications
Stars: ✭ 1,644 (+1594.85%)
Mutual labels:  prometheus, instrumentation
prometheus-httpd
Expose Prometheus metrics using inets httpd.
Stars: ✭ 21 (-78.35%)
Mutual labels:  prometheus, instrumentation
Prometheus rabbitmq exporter
Prometheus.io exporter as a RabbitMQ Managment Plugin plugin
Stars: ✭ 248 (+155.67%)
Mutual labels:  prometheus, instrumentation
Learning tools
Go 学习、Go 进阶、Go 实用工具类、Go-kit ,Go-Micro 微服务实践、Go 推送
Stars: ✭ 605 (+523.71%)
Mutual labels:  prometheus, gin
Prometheus.cl
Prometheus.io Common Lisp client
Stars: ✭ 67 (-30.93%)
Mutual labels:  prometheus, instrumentation
Client python
Prometheus instrumentation library for Python applications
Stars: ✭ 2,500 (+2477.32%)
Mutual labels:  prometheus, instrumentation
Mtail
extract internal monitoring data from application logs for collection in a timeseries database
Stars: ✭ 3,028 (+3021.65%)
Mutual labels:  prometheus, instrumentation
website
Official website and document for Gin
Stars: ✭ 88 (-9.28%)
Mutual labels:  gin
ghostwriter
Solutions for instrumenting application flow tracking API calls into an existing code base in a non-invasive way
Stars: ✭ 17 (-82.47%)
Mutual labels:  instrumentation
asprom
Aerospike prometheus exporter
Stars: ✭ 38 (-60.82%)
Mutual labels:  instrumentation
gryllidae
Opinionated CNCF-based, Docker Compose setup for everything needed to develop a 12factor app
Stars: ✭ 18 (-81.44%)
Mutual labels:  instrumentation

ginprom

Gin Prometheus metrics exporter inspired by github.com/zsais/go-gin-prometheus

Sourcegraph Go Report Card Build Status codecov License godoc

Install

Simply run: go get -u github.com/Depado/ginprom

Differences with go-gin-prometheus

  • No support for Prometheus' Push Gateway
  • Options on constructor
  • Adds a path label to get the matched route
  • Ability to ignore routes

Usage

package main

import (
	"github.com/Depado/ginprom"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	p := ginprom.New(
		ginprom.Engine(r),
		ginprom.Subsystem("gin"),
		ginprom.Path("/metrics"),
	)
	r.Use(p.Instrument())

	r.GET("/hello/:id", func(c *gin.Context) {})
	r.GET("/world/:id", func(c *gin.Context) {})
	r.Run("127.0.0.1:8080")
}

Options

Custom gauges

Add custom gauges to add own values to the metrics

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
)
p.AddCustomGauge("custom", "Some help text to provide", []string{"label"})
r.Use(p.Instrument())

Save p and use the following functions:

  • IncrementGaugeValue
  • DecrementGaugeValue
  • SetGaugeValue

Path

Override the default path (/metrics) on which the metrics can be accessed:

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.Path("/custom/metrics"),
)
r.Use(p.Instrument())

Namespace

Override the default namespace (gin):

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.Namespace("custom_ns"),
)
r.Use(p.Instrument())

Subsystem

Override the default (gonic) subsystem:

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.Subsystem("your_subsystem"),
)
r.Use(p.Instrument())

Engine

The preferred way to pass the router to ginprom:

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
)
r.Use(p.Instrument())

The alternative being to call the Use method after initialization:

p := ginprom.New()
// ...
r := gin.New()
p.Use(r)
r.Use(p.Instrument())

Prometheus Registry

Use a custom prometheus.Registry instead of prometheus client's global registry. This option allows to use ginprom in multiple gin engines in the same process, or if you would like to integrate ginprom with your own prometheus Registry.

registry := prometheus.NewRegistry() // creates new prometheus metric registry
r := gin.New()
p := ginprom.New(
    ginprom.Registry(registry),
)
r.Use(p.Instrument())

Ignore

Ignore allows to completely ignore some routes. Even though you can apply the middleware to the only groups you're interested in, it is sometimes useful to have routes not instrumented.

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.Ignore("/api/no/no/no", "/api/super/secret/route")
)
r.Use(p.Instrument())

Note that most of the time this can be solved by gin groups:

r := gin.New()
p := ginprom.New(ginprom.Engine(r))

// Add the routes that do not need instrumentation
g := r.Group("/api/")
g.Use(p.Instrument())
{
	// Instrumented routes
}

Token

Specify a secret token which Prometheus will use to access the endpoint. If the token is invalid, the endpoint will return an error.

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.Token("supersecrettoken")
)
r.Use(p.Instrument())

Bucket size

Specify the bucket size for the request duration histogram according to your expected durations.

r := gin.New()
p := ginprom.New(
	ginprom.Engine(r),
	ginprom.BucketSize([]float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}),
)
r.Use(p.Instrument())

Troubleshooting

The instrumentation doesn't seem to work

Make sure you have set the gin.Engine in the ginprom middleware, either when initializing it using ginprom.New(ginprom.Engine(r)) or using the Use function after the initialization like this :

p := ginprom.New(
	ginprom.Namespace("gin"),
	ginprom.Subsystem("gonic"),
	ginprom.Path("/metrics"),
)
p.Use(r)
r.Use(p.Instrument())

By design, if the middleware was to panic, it would do so when a route is called. That's why it just silently fails when no engine has been set.

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