Documentation
¶
Overview ¶
Package ginprom collects metrics in the Gin web framework and exports it to the Prometheus.
Usage:
r := gin.Default()
p := ginprom.New()
// Attach the middleware to collect common metrics
r.Use(p.Middleware)
// Set the handler to export collected metrics
r.GET("/metrics", p.Handler)
// Register a custom metric
pings := prometheus.NewCounter(prometheus.CounterOpts{
Name: "pings_received",
})
p.MustRegister(pings)
r.GET("/ping", func(c *gin.Context) {
pings.Inc()
c.JSON(200, gin.H{"message": "pong"})
})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Prometheus ¶
type Prometheus struct {
// contains filtered or unexported fields
}
Prometheus provides methods to collect common and custom metrics.
func (*Prometheus) Handler ¶
func (p *Prometheus) Handler(c *gin.Context)
Handler exports collected metrics to the caller.
func (*Prometheus) Middleware ¶
func (p *Prometheus) Middleware(c *gin.Context)
Middleware used to collect common HTTP metrics. Should be attached to the Gin router through Use().
func (*Prometheus) MustRegister ¶
func (p *Prometheus) MustRegister(c prometheus.Collector)
MustRegister registers the custom collector and panics if any error occurs.
Click to show internal directories.
Click to hide internal directories.