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") p.Embed(e) e.Logger.Fatal(e.Start(":1323")) }
```
Index ¶
- func NewMetric(m *Metric, subsystem string) prometheus.Collector
- type Config
- type Metric
- type Prometheus
- func (p *Prometheus) Embed(e *echo.Echo)
- func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc
- func (p *Prometheus) Mount(e *echo.Echo)
- func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushIntervalSeconds time.Duration)
- func (p *Prometheus) SetPushGatewayJob(j string)
- func (p *Prometheus) SetRoute(e *echo.Echo)
- func (p *Prometheus) Start(e *echo.Echo, listenAddress string)
- type PushGateway
- type RequestCounterURLLabelMappingFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { MetricsPath string Subsystem string Skipper middleware.Skipper AdditionMetrics []*Metric }
Config let you configure how Prometheus works
type Metric ¶
type Metric struct { MetricCollector prometheus.Collector ID string Name string Description string Type string Args []string }
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 // contains filtered or unexported fields }
Prometheus contains the metrics gathered by the instance and its path
func NewPrometheus ¶
func NewPrometheus(subsystem string) *Prometheus
NewPrometheus creates a new Prometheus instance with default configuration
func NewPrometheusWithConfig ¶
func NewPrometheusWithConfig(config Config) *Prometheus
NewPrometheusWithConfig creates a new Prometheus instance with your configuration
func (*Prometheus) Embed ¶
func (p *Prometheus) Embed(e *echo.Echo)
Embed adds the middleware to the Echo instance and setup the route for exporting
func (*Prometheus) HandlerFunc ¶
func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc
HandlerFunc defines handler function for middleware
func (*Prometheus) Mount ¶
func (p *Prometheus) Mount(e *echo.Echo)
func (*Prometheus) SetPushGateway ¶
func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushIntervalSeconds time.Duration)
SetPushGateway sends metrics to a remote pushgateway exposed on pushGatewayURL every pushIntervalSeconds. Metrics are fetched from metricsURL
func (*Prometheus) SetPushGatewayJob ¶
func (p *Prometheus) SetPushGatewayJob(j string)
SetPushGatewayJob job name, defaults to "echo"
func (*Prometheus) SetRoute ¶
func (p *Prometheus) SetRoute(e *echo.Echo)
func (*Prometheus) Start ¶
func (p *Prometheus) Start(e *echo.Echo, listenAddress string)
Start start Prometheus in a separate Echo instance, which can be shutdowned with the Context parameter
type PushGateway ¶
type PushGateway struct { // Push interval in seconds PushIntervalSeconds time.Duration // Push Gateway URL in format http://domain:port // where JOBNAME can be any string of your choice PushGatewayURL string // Local metrics URL where metrics are fetched from, this could be ommited in the future // if implemented using prometheus common/expfmt instead MetricsURL string // pushgateway job name, defaults to "echo" Job string }
PushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)
type RequestCounterURLLabelMappingFunc ¶
type RequestCounterURLLabelMappingFunc func(c echo.Context) string
RequestCounterURLLabelMappingFunc 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".