Skip to content

Prometheus Implementation #1892

Answered by aldas
nicholasanthonys asked this question in Q&A
Discussion options

You must be logged in to vote

https://github.com/labstack/echo-contrib/blob/master/prometheus/prometheus.go registers middleware for http server and exposes prometheus metrics through /metrics route.

You can use it with your own custom metrics.

For example:

import (
	promMW "github.com/labstack/echo-contrib/prometheus"
	"github.com/labstack/echo/v4"
	"github.com/labstack/gommon/log"
	"github.com/prometheus/client_golang/prometheus"
	"net/http"
)

func main() {
	e := echo.New()
	p := promMW.NewPrometheus("echo", nil)

	myCounter := prometheus.NewGauge(prometheus.GaugeOpts{
		Name:        "my_handler_executions",
		Help:        "Counts executions of my handler function.",
		ConstLabels: prometheus.Labels{"version": "1234"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nicholasanthonys
Comment options

Answer selected by nicholasanthonys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants