Documentation ¶
Overview ¶
Package caddyprom implements a metrics module for Caddy v2 that exports in the Prometheus text format.
The simplest use could be in a Caddyfile like:
{ order prometheus first } localhost prometheus
package promhttp
package promhttp
Index ¶
- func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc
- func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
- func InstrumentHandlerInFlight(g prometheus.Gauge, next http.Handler) http.Handler
- func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
- func InstrumentHandlerResponseSize(obs prometheus.ObserverVec, next http.Handler) http.Handler
- func InstrumentHandlerTimeToWriteHeader(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
- type Metrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InstrumentHandlerCounter ¶
func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc
InstrumentHandlerCounter is a middleware that wraps the provided http.Handler to observe the request result with the provided CounterVec. The CounterVec must have zero, one, or two non-const non-curried labels. For those, the only allowed label names are "code" and "method". The function panics otherwise. Partitioning of the CounterVec happens by HTTP status code and/or HTTP method if the respective instance label names are present in the CounterVec. For unpartitioned counting, use a CounterVec with zero labels.
If the wrapped Handler does not set a status code, a status code of 200 is assumed.
If the wrapped Handler panics, the Counter is not incremented.
See the example for InstrumentHandlerDuration for example usage.
func InstrumentHandlerDuration ¶
func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
InstrumentHandlerDuration is a middleware that wraps the provided http.Handler to observe the request duration with the provided ObserverVec. The ObserverVec must have zero, one, or two non-const non-curried labels. For those, the only allowed label names are "code" and "method". The function panics otherwise. The Observe method of the Observer in the ObserverVec is called with the request duration in seconds. Partitioning happens by HTTP status code and/or HTTP method if the respective instance label names are present in the ObserverVec. For unpartitioned observations, use an ObserverVec with zero labels. Note that partitioning of Histograms is expensive and should be used judiciously.
If the wrapped Handler does not set a status code, a status code of 200 is assumed.
If the wrapped Handler panics, no values are reported.
Note that this method is only guaranteed to never observe negative durations if used with Go1.9+.
func InstrumentHandlerInFlight ¶
InstrumentHandlerInFlight is a middleware that wraps the provided http.Handler. It sets the provided prometheus.Gauge to the number of requests currently handled by the wrapped http.Handler.
See the example for InstrumentHandlerDuration for example usage.
func InstrumentHandlerRequestSize ¶
func InstrumentHandlerRequestSize(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
InstrumentHandlerRequestSize is a middleware that wraps the provided http.Handler to observe the request size with the provided ObserverVec. The ObserverVec must have zero, one, or two non-const non-curried labels. For those, the only allowed label names are "code" and "method". The function panics otherwise. The Observe method of the Observer in the ObserverVec is called with the request size in bytes. Partitioning happens by HTTP status code and/or HTTP method if the respective instance label names are present in the ObserverVec. For unpartitioned observations, use an ObserverVec with zero labels. Note that partitioning of Histograms is expensive and should be used judiciously.
If the wrapped Handler does not set a status code, a status code of 200 is assumed.
If the wrapped Handler panics, no values are reported.
See the example for InstrumentHandlerDuration for example usage.
func InstrumentHandlerResponseSize ¶
func InstrumentHandlerResponseSize(obs prometheus.ObserverVec, next http.Handler) http.Handler
InstrumentHandlerResponseSize is a middleware that wraps the provided http.Handler to observe the response size with the provided ObserverVec. The ObserverVec must have zero, one, or two non-const non-curried labels. For those, the only allowed label names are "code" and "method". The function panics otherwise. The Observe method of the Observer in the ObserverVec is called with the response size in bytes. Partitioning happens by HTTP status code and/or HTTP method if the respective instance label names are present in the ObserverVec. For unpartitioned observations, use an ObserverVec with zero labels. Note that partitioning of Histograms is expensive and should be used judiciously.
If the wrapped Handler does not set a status code, a status code of 200 is assumed.
If the wrapped Handler panics, no values are reported.
See the example for InstrumentHandlerDuration for example usage.
func InstrumentHandlerTimeToWriteHeader ¶
func InstrumentHandlerTimeToWriteHeader(obs prometheus.ObserverVec, next http.Handler) http.HandlerFunc
InstrumentHandlerTimeToWriteHeader is a middleware that wraps the provided http.Handler to observe with the provided ObserverVec the request duration until the response headers are written. The ObserverVec must have zero, one, or two non-const non-curried labels. For those, the only allowed label names are "code" and "method". The function panics otherwise. The Observe method of the Observer in the ObserverVec is called with the request duration in seconds. Partitioning happens by HTTP status code and/or HTTP method if the respective instance label names are present in the ObserverVec. For unpartitioned observations, use an ObserverVec with zero labels. Note that partitioning of Histograms is expensive and should be used judiciously.
If the wrapped Handler panics before calling WriteHeader, no value is reported.
Note that this method is only guaranteed to never observe negative durations if used with Go1.9+.
See the example for InstrumentHandlerDuration for example usage.
Types ¶
type Metrics ¶
type Metrics struct { Addr string `json:"address,omitempty"` Path string `json:"path,omitempty"` // contains filtered or unexported fields }
Metrics -
func (Metrics) CaddyModule ¶
func (Metrics) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.