prometheus

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 12 Imported by: 222 modules, 195 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prometheus provides middleware to add Prometheus metrics.

Example: ``` package main import (

"github.com/labstack/echo/v4"
"github.com/labstack/echo-contrib/prometheus"

)

func main() {
    e := echo.New()
    // Enable metrics middleware
    p := prometheus.NewPrometheus("echo", nil)
    p.Use(e)

    e.Logger.Fatal(e.Start(":1323"))
}

```

Index

Constants

View Source
const (
	KB float64 = 1 << (10 * iota)
	MB
	GB
	TB
)

Variables

This section is empty.

Functions

func NewMetric

func NewMetric(m *Metric, subsystem string) prometheus.Collector

NewMetric associates prometheus.Collector based on Metric.Type Deprecated: use echoprometheus package instead

Types

type Metric

type Metric struct {
	MetricCollector prometheus.Collector
	ID              string
	Name            string
	Description     string
	Type            string
	Args            []string
	Buckets         []float64
}

Metric is a definition for the name, description, type, ID, and prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric

type Prometheus

type Prometheus struct {
	Ppg PushGateway

	MetricsList []*Metric
	MetricsPath string
	Subsystem   string
	Skipper     middleware.Skipper

	RequestCounterURLLabelMappingFunc  RequestCounterLabelMappingFunc
	RequestCounterHostLabelMappingFunc RequestCounterLabelMappingFunc

	// Context string to use as a prometheus URL label
	URLLabelFromContext string
	// contains filtered or unexported fields
}

Prometheus contains the metrics gathered by the instance and its path Deprecated: use echoprometheus package instead

func NewPrometheus

func NewPrometheus(subsystem string, skipper middleware.Skipper, customMetricsList ...[]*Metric) *Prometheus

NewPrometheus generates a new set of metrics with a certain subsystem name Deprecated: use echoprometheus package instead

func (*Prometheus) HandlerFunc

func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc

HandlerFunc defines handler function for middleware

func (*Prometheus) SetMetricsPath

func (p *Prometheus) SetMetricsPath(e *echo.Echo)

SetMetricsPath set metrics paths

func (*Prometheus) SetPushGateway

func (p *Prometheus) SetPushGateway(pushGatewayURL string, pushInterval time.Duration)

SetPushGateway sends metrics to a remote pushgateway exposed on pushGatewayURL every pushInterval. Metrics are fetched from

func (*Prometheus) SetPushGatewayJob

func (p *Prometheus) SetPushGatewayJob(j string)

SetPushGatewayJob job name, defaults to "echo"

func (*Prometheus) Use

func (p *Prometheus) Use(e *echo.Echo)

Use adds the middleware to the Echo engine.

type PushGateway

type PushGateway struct {
	// Push interval in seconds
	//lint:ignore ST1011 renaming would be breaking change
	PushIntervalSeconds time.Duration

	// Push Gateway URL in format http://domain:port
	// where JOBNAME can be any string of your choice
	PushGatewayURL string

	// pushgateway job name, defaults to "echo"
	Job string
}

PushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)

type RequestCounterLabelMappingFunc added in v0.11.0

type RequestCounterLabelMappingFunc func(c echo.Context) string

RequestCounterLabelMappingFunc is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:

func(c echo.Context) string {
	url := c.Request.URL.Path
	for _, p := range c.Params {
		if p.Key == "name" {
			url = strings.Replace(url, p.Value, ":name", 1)
			break
		}
	}
	return url
}

which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name". It can also be applied for the "Host" label

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL