Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CounterMetric ¶
type CounterMetric struct {
// Name is the Prometheus metric name. It must be unique within the
// module configuration.
Name string `json:"name,omitempty"`
// Help is the help/description string for the metric. A sensible default
// is generated if this is left empty.
Help string `json:"help,omitempty"`
// Labels is the list of labels for the metric.
Labels []*Label `json:"labels,omitempty"`
// MatcherSetsRaw holds the raw matcher configuration parsed from Caddyfile /
// JSON. It is exercise only during Provision; the concrete matcher sets are
// produced from it and stored in matcherSets.
MatcherSetsRaw caddyhttp.RawMatcherSets `json:"match,omitempty" caddy:"namespace=http.matchers"`
// contains filtered or unexported fields
}
type GaugeMetric ¶ added in v0.2.0
type GaugeMetric struct {
// Name is the Prometheus metric name. It must be unique within the
// module configuration.
Name string `json:"name,omitempty"`
// Help is the help/description string for the metric. A sensible default
// is generated if this is left empty.
Help string `json:"help,omitempty"`
// Value is the placeholder for the value to be set.
Value string `json:"value,omitempty"`
// Labels is the list of labels for the metric.
Labels []*Label `json:"labels,omitempty"`
// MatcherSetsRaw holds the raw matcher configuration parsed from Caddyfile /
// JSON. It is exercise only during Provision; the concrete matcher sets are
// produced from it and stored in matcherSets.
MatcherSetsRaw caddyhttp.RawMatcherSets `json:"match,omitempty" caddy:"namespace=http.matchers"`
// contains filtered or unexported fields
}
type Label ¶ added in v0.2.0
type Label struct {
// Name is the Prometheus label name.
Name string `json:"name,omitempty"`
// Value is the placeholder to be evaluated for the label's value.
Value string `json:"value,omitempty"`
// Default is the value to be used if the placeholder is empty.
Default string `json:"default,omitempty"`
}
type MetricInjector ¶
type MetricInjector struct {
// Counters is the list of counter metrics that should be tracked.
Counters []*CounterMetric `json:"counters,omitempty"`
// Gauges is the list of gauge metrics that should be tracked.
Gauges []*GaugeMetric `json:"gauges,omitempty"`
// contains filtered or unexported fields
}
MetricInjector is a Caddy HTTP middleware module that defines and increments custom Prometheus counters.
The module allows defining one or more counters, with optional labels, that are incremented when incoming requests match configured Caddy HTTP request matchers.
Each counter may define optional matcher conditions. If the matchers evaluate to true for a request, the corresponding counter is incremented. Counters without matchers act as match-all counters and increment for every request passing through the handler.
Counter evaluation occurs after the remaining handler chain has executed, ensuring that metric collection does not interfere with request processing.
All counters are registered in Caddy's metrics registry and become available through the standard Prometheus metrics endpoint when the global `metrics` option is enabled.
func (MetricInjector) CaddyModule ¶
func (MetricInjector) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*MetricInjector) Provision ¶
func (m *MetricInjector) Provision(ctx caddy.Context) error
Provision sets up the metrics and prepares any matchers.
It initializes the logger, verifies the configuration (unique names, etc.), creates or reuses Prometheus counters via Caddy’s registry, and converts the raw matcher configuration into matcherSets for runtime use.
func (MetricInjector) ServeHTTP ¶
func (m MetricInjector) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP evaluates each configured counter and increments those whose matchers (if any) are satisfied by the current request. The next handler in the chain is always invoked first, so metric failures do not block the request.
func (*MetricInjector) UnmarshalCaddyfile ¶
func (m *MetricInjector) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile parses the metric_injector block from the Caddyfile