mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-11 04:32:29 +02:00
Add status_codes_total counter to Prometheus metrics
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Add
|
### 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 `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.
|
- (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) {
|
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, nrCancel, rw := newrelic.StartTransaction(ctx, rw, r)
|
||||||
ctx, ddCancel, rw := datadog.StartRootSpan(ctx, rw, r)
|
ctx, ddCancel, rw := datadog.StartRootSpan(ctx, rw, r)
|
||||||
ctx, otelCancel, rw := otel.StartRootSpan(ctx, rw, r)
|
ctx, otelCancel, rw := otel.StartRootSpan(ctx, rw, r)
|
||||||
|
@@ -4,8 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/felixge/httpsnoop"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -19,6 +21,7 @@ var (
|
|||||||
enabled = false
|
enabled = false
|
||||||
|
|
||||||
requestsTotal prometheus.Counter
|
requestsTotal prometheus.Counter
|
||||||
|
statusCodesTotal *prometheus.CounterVec
|
||||||
errorsTotal *prometheus.CounterVec
|
errorsTotal *prometheus.CounterVec
|
||||||
|
|
||||||
requestDuration prometheus.Histogram
|
requestDuration prometheus.Histogram
|
||||||
@@ -45,6 +48,12 @@ func Init() {
|
|||||||
Help: "A counter of the total number of HTTP requests imgproxy processed.",
|
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{
|
errorsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: config.PrometheusNamespace,
|
Namespace: config.PrometheusNamespace,
|
||||||
Name: "errors_total",
|
Name: "errors_total",
|
||||||
@@ -108,6 +117,7 @@ func Init() {
|
|||||||
|
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
requestsTotal,
|
requestsTotal,
|
||||||
|
statusCodesTotal,
|
||||||
errorsTotal,
|
errorsTotal,
|
||||||
requestDuration,
|
requestDuration,
|
||||||
requestSpanDuration,
|
requestSpanDuration,
|
||||||
@@ -150,13 +160,23 @@ func StartServer(cancel context.CancelFunc) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartRequest() context.CancelFunc {
|
func StartRequest(rw http.ResponseWriter) (context.CancelFunc, http.ResponseWriter) {
|
||||||
if !enabled {
|
if !enabled {
|
||||||
return func() {}
|
return func() {}, rw
|
||||||
}
|
}
|
||||||
|
|
||||||
requestsTotal.Inc()
|
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 {
|
func StartQueueSegment() context.CancelFunc {
|
||||||
|
Reference in New Issue
Block a user