| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This package is not in the latest version of its module.
Go to latest Published: Mar 1, 2026 License: MITThe Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
Package echoprometheus provides middleware to add Prometheus metrics.
This section is empty.
This section is empty.
func NewHandler() echo.HandlerFunc
NewHandler creates new instance of Handler using Prometheus default registry.
func NewHandlerWithConfig(config HandlerConfig) echo.HandlerFunc
NewHandlerWithConfig creates new instance of Handler using given configuration.
func NewMiddleware(subsystem string) echo.MiddlewareFunc
NewMiddleware creates new instance of middleware using Prometheus default registry.
func NewMiddlewareWithConfig(config MiddlewareConfig) echo.MiddlewareFunc
NewMiddlewareWithConfig creates new instance of middleware using given configuration.
func RunPushGatewayGatherer(ctx context.Context, config PushGatewayConfig) error
RunPushGatewayGatherer starts pushing collected metrics and waits for it context to complete or ErrorHandler to return error.
Example: ```
go func() {
config := echoprometheus.PushGatewayConfig{
PushGatewayURL: "https://host:9080",
PushInterval: 10 * time.Millisecond,
}
if err := echoprometheus.RunPushGatewayGatherer(context.Background(), config); !errors.Is(err, context.Canceled) {
log.Fatal(err)
}
}()
```
func WriteGatheredMetrics(writer io.Writer, gatherer prometheus.Gatherer) error
WriteGatheredMetrics gathers collected metrics and writes them to given writer
type HandlerConfig struct {
// Gatherer sets the prometheus.Gatherer instance the middleware will use when generating the metric endpoint handler.
// Defaults to: prometheus.DefaultGatherer
Gatherer prometheus.Gatherer
}
HandlerConfig contains the configuration for creating HTTP handler for metrics.
LabelValueFunc is a function that returns a label value for a given context and error.
type MiddlewareConfig struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// Namespace is components of the fully-qualified name of the Metric (created by joining Namespace,Subsystem and Name components with "_")
// Optional
Namespace string
// Subsystem is components of the fully-qualified name of the Metric (created by joining Namespace,Subsystem and Name components with "_")
// Defaults to: "echo"
Subsystem string
// LabelFuncs allows adding custom labels in addition to default labels. When key has same name with default label
// it replaces default one.
LabelFuncs map[string]LabelValueFunc
// HistogramOptsFunc allows to change options for metrics of type histogram before metric is registered to Registerer
HistogramOptsFunc func(opts prometheus.HistogramOpts) prometheus.HistogramOpts
// CounterOptsFunc allows to change options for metrics of type counter before metric is registered to Registerer
CounterOptsFunc func(opts prometheus.CounterOpts) prometheus.CounterOpts
// Registerer sets the prometheus.Registerer instance the middleware will register these metrics with.
// Defaults to: prometheus.DefaultRegisterer
Registerer prometheus.Registerer
// BeforeNext is callback that is executed before next middleware/handler is called. Useful for case when you have own
// metrics that need data to be stored for AfterNext.
BeforeNext func(c *echo.Context)
// AfterNext is callback that is executed after next middleware/handler returns. Useful for case when you have own
// metrics that need incremented/observed.
AfterNext func(c *echo.Context, err error)
// If DoNotUseRequestPathFor404 is true, all 404 responses (due to non-matching route) will have the same `url` label and
// thus won't generate new metrics.
DoNotUseRequestPathFor404 bool
// contains filtered or unexported fields
}
MiddlewareConfig contains the configuration for creating prometheus middleware collecting several default metrics.
func (conf MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error)
ToMiddleware converts configuration to middleware or returns an error.
type PushGatewayConfig struct {
// PushGatewayURL is push gateway URL in format http://domain:port
PushGatewayURL string
// PushInterval in ticker interval for pushing gathered metrics to the Gateway
// Defaults to: 1 minute
PushInterval time.Duration
// Gatherer sets the prometheus.Gatherer instance the middleware will use when generating the metric endpoint handler.
// Defaults to: prometheus.DefaultGatherer
Gatherer prometheus.Gatherer
// ErrorHandler is function that is called when errors occur. When callback returns error StartPushGateway also returns.
ErrorHandler func(err error) error
// ClientTransport specifies the mechanism by which individual HTTP POST requests are made.
// Defaults to: http.DefaultTransport
ClientTransport http.RoundTripper
}
PushGatewayConfig contains the configuration for pushing to a Prometheus push gateway.
| Back | FazBrowse Home | New Git URL |