diff options
author | Dave Henderson <[email protected]> | 2020-09-17 14:01:20 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-17 12:01:20 -0600 |
commit | 8ec51bbede59e1fa6ac24de3607f6e7bb3e3a654 (patch) | |
tree | f598667a352f4606979965e200eedecc9aa4e4e8 /metrics.go | |
parent | bc453fa6ae36287c90d2bf6941cb686490090df2 (diff) | |
download | caddy-8ec51bbede59e1fa6ac24de3607f6e7bb3e3a654.tar.gz caddy-8ec51bbede59e1fa6ac24de3607f6e7bb3e3a654.zip |
metrics: Initial integration of Prometheus metrics (#3709)
Signed-off-by: Dave Henderson <[email protected]>
Diffstat (limited to 'metrics.go')
-rw-r--r-- | metrics.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/metrics.go b/metrics.go new file mode 100644 index 000000000..a7ff3b71d --- /dev/null +++ b/metrics.go @@ -0,0 +1,32 @@ +package caddy + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +// define and register the metrics used in this package. +func init() { + prometheus.MustRegister(prometheus.NewBuildInfoCollector()) + + const ns, sub = "caddy", "admin" + + adminMetrics.requestCount = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: ns, + Subsystem: sub, + Name: "http_requests_total", + Help: "Counter of requests made to the Admin API's HTTP endpoints.", + }, []string{"handler", "path", "code", "method"}) + adminMetrics.requestErrors = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: ns, + Subsystem: sub, + Name: "http_request_errors_total", + Help: "Number of requests resulting in middleware errors.", + }, []string{"handler", "path", "method"}) +} + +// adminMetrics is a collection of metrics that can be tracked for the admin API. +var adminMetrics = struct { + requestCount *prometheus.CounterVec + requestErrors *prometheus.CounterVec +}{} |