Go API Documentation

github.com/caddyserver/caddy/v2/modules/metrics

No package summary is available.

Package

Files: 2. Third party imports: 3. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Vars

var (
	_	caddy.Provisioner	= (*AdminMetrics)(nil)
	_	caddy.AdminRouter	= (*AdminMetrics)(nil)
)

Types

AdminMetrics

AdminMetrics is a module that serves a metrics endpoint so that any gathered metrics can be exposed for scraping. This module is not configurable, and is permanently mounted to the admin API endpoint at "/metrics". See the Metrics module for a configurable endpoint that is usable if the Admin API is disabled.

type AdminMetrics struct {
	registry	*prometheus.Registry

	metricsHandler	http.Handler
}

Metrics

Metrics is a module that serves a /metrics endpoint so that any gathered metrics can be exposed for scraping. This module is configurable by end-users unlike AdminMetrics.

type Metrics struct {
	metricsHandler	http.Handler

	// Disable OpenMetrics negotiation, enabled by default. May be necessary if
	// the produced metrics cannot be parsed by the service scraping metrics.
	DisableOpenMetrics	bool	`json:"disable_openmetrics,omitempty"`
}

zapLogger

This type doesn't have documentation.

type zapLogger struct {
	zl *zap.Logger
}

Functions

func (*AdminMetrics) Provision

Provision -

func (m *AdminMetrics) Provision(ctx caddy.Context) error {
	m.registry = ctx.GetMetricsRegistry()
	if m.registry == nil {
		return errors.New("no metrics registry found")
	}
	m.metricsHandler = createMetricsHandler(nil, false, m.registry)
	return nil
}

Cognitive complexity: 2, Cyclomatic complexity: 2

Uses: errors.New.

func (*AdminMetrics) Routes

Routes returns a route for the /metrics endpoint.

func (m *AdminMetrics) Routes() []caddy.AdminRoute {
	return []caddy.AdminRoute{{Pattern: "/metrics", Handler: caddy.AdminHandlerFunc(m.serveHTTP)}}
}

Cognitive complexity: 2, Cyclomatic complexity: 1

func (*Metrics) UnmarshalCaddyfile

UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:

metrics [<matcher>] {
    disable_openmetrics
}

func (m *Metrics) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
	d.Next()	// consume directive name
	args := d.RemainingArgs()
	if len(args) > 0 {
		return d.ArgErr()
	}

	for d.NextBlock(0) {
		switch d.Val() {
		case "disable_openmetrics":
			m.DisableOpenMetrics = true
		default:
			return d.Errf("unrecognized subdirective %q", d.Val())
		}
	}
	return nil
}

Cognitive complexity: 7, Cyclomatic complexity: 5

func (*zapLogger) Println

func (l *zapLogger) Println(v ...any) {
	l.zl.Sugar().Error(v...)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (AdminMetrics) CaddyModule

CaddyModule returns the Caddy module information.

func (AdminMetrics) CaddyModule() caddy.ModuleInfo {
	return caddy.ModuleInfo{
		ID:	"admin.api.metrics",
		New:	func() caddy.Module { return new(AdminMetrics) },
	}
}

Cognitive complexity: 2, Cyclomatic complexity: 1

func (Metrics) ServeHTTP

func (m Metrics) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
	m.metricsHandler.ServeHTTP(w, r)
	return nil
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func createMetricsHandler

createMetricsHandler (logger promhttp.Logger, enableOpenMetrics bool, registry *prometheus.Registry) http.Handler
References: promhttp.HandlerFor, promhttp.HandlerOpts, promhttp.InstrumentMetricHandler.

func init

init ()

func parseCaddyfile

parseCaddyfile (h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)

func serveHTTP

serveHTTP (w http.ResponseWriter, r *http.Request) error


Tests

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 1. Benchmarks: 0.

Test functions

TestMetricsUnmarshalCaddyfile

References: caddyfile.NewTestDispenser.