mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-27 12:07:59 +02:00
Add status_codes_total counter to Prometheus metrics
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
### Add
|
||||
- Add `status_codes_total` counter to Prometheus metrics.
|
||||
- (pro) Add the `IMGPROXY_VIDEO_THUMBNAIL_KEYFRAMES` config and the [video_thumbnail_keyframes](https://docs.imgproxy.net/latest/generating_the_url?id=video-thumbnail-keyframes) processing option.
|
||||
- (pro) Add the [video_thumbnail_tile](https://docs.imgproxy.net/latest/generating_the_url?id=video-thumbnail-tile) processing option.
|
||||
|
||||
|
@@ -47,7 +47,7 @@ func Enabled() bool {
|
||||
}
|
||||
|
||||
func StartRequest(ctx context.Context, rw http.ResponseWriter, r *http.Request) (context.Context, context.CancelFunc, http.ResponseWriter) {
|
||||
promCancel := prometheus.StartRequest()
|
||||
promCancel, rw := prometheus.StartRequest(rw)
|
||||
ctx, nrCancel, rw := newrelic.StartTransaction(ctx, rw, r)
|
||||
ctx, ddCancel, rw := datadog.StartRootSpan(ctx, rw, r)
|
||||
ctx, otelCancel, rw := otel.StartRootSpan(ctx, rw, r)
|
||||
|
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/felixge/httpsnoop"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -18,8 +20,9 @@ import (
|
||||
var (
|
||||
enabled = false
|
||||
|
||||
requestsTotal prometheus.Counter
|
||||
errorsTotal *prometheus.CounterVec
|
||||
requestsTotal prometheus.Counter
|
||||
statusCodesTotal *prometheus.CounterVec
|
||||
errorsTotal *prometheus.CounterVec
|
||||
|
||||
requestDuration prometheus.Histogram
|
||||
requestSpanDuration *prometheus.HistogramVec
|
||||
@@ -45,6 +48,12 @@ func Init() {
|
||||
Help: "A counter of the total number of HTTP requests imgproxy processed.",
|
||||
})
|
||||
|
||||
statusCodesTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: config.PrometheusNamespace,
|
||||
Name: "status_codes_total",
|
||||
Help: "A counter of the response status codes.",
|
||||
}, []string{"status"})
|
||||
|
||||
errorsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: config.PrometheusNamespace,
|
||||
Name: "errors_total",
|
||||
@@ -108,6 +117,7 @@ func Init() {
|
||||
|
||||
prometheus.MustRegister(
|
||||
requestsTotal,
|
||||
statusCodesTotal,
|
||||
errorsTotal,
|
||||
requestDuration,
|
||||
requestSpanDuration,
|
||||
@@ -150,13 +160,23 @@ func StartServer(cancel context.CancelFunc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func StartRequest() context.CancelFunc {
|
||||
func StartRequest(rw http.ResponseWriter) (context.CancelFunc, http.ResponseWriter) {
|
||||
if !enabled {
|
||||
return func() {}
|
||||
return func() {}, rw
|
||||
}
|
||||
|
||||
requestsTotal.Inc()
|
||||
return startDuration(requestDuration)
|
||||
|
||||
newRw := httpsnoop.Wrap(rw, httpsnoop.Hooks{
|
||||
WriteHeader: func(next httpsnoop.WriteHeaderFunc) httpsnoop.WriteHeaderFunc {
|
||||
return func(statusCode int) {
|
||||
statusCodesTotal.With(prometheus.Labels{"status": strconv.Itoa(statusCode)}).Inc()
|
||||
next(statusCode)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
return startDuration(requestDuration), newRw
|
||||
}
|
||||
|
||||
func StartQueueSegment() context.CancelFunc {
|
||||
|
Reference in New Issue
Block a user