From df881e16b5b39cb8dee4d29a6517f48e7ccfa6d5 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Fri, 21 May 2021 19:09:02 +0200 Subject: [PATCH] add metrics --- internal/metrics/metrics.go | 10 ++++++++++ server/http/routes.go | 6 ++++++ store/http.go | 5 +++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index ca65021..b6d5a57 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -118,6 +118,11 @@ var ( Name: "http3_blob_download_total", Help: "Total number of blobs downloaded from reflector through QUIC protocol", }) + HttpDownloadCount = promauto.NewCounter(prometheus.CounterOpts{ + Namespace: ns, + Name: "http_blob_download_total", + Help: "Total number of blobs downloaded from reflector through HTTP protocol", + }) CacheHitCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: ns, @@ -204,6 +209,11 @@ var ( Name: "udp_out_bytes", Help: "Total number of bytes streamed out through UDP", }) + MtrOutBytesHttp = promauto.NewCounter(prometheus.CounterOpts{ + Namespace: ns, + Name: "http_out_bytes", + Help: "Total number of bytes streamed out through UDP", + }) MtrInBytesReflector = promauto.NewCounter(prometheus.CounterOpts{ Namespace: ns, Name: "reflector_in_bytes", diff --git a/server/http/routes.go b/server/http/routes.go index eee696f..e9124a9 100644 --- a/server/http/routes.go +++ b/server/http/routes.go @@ -5,7 +5,10 @@ import ( "github.com/gin-gonic/gin" "github.com/lbryio/lbry.go/v2/extras/errors" + + "github.com/lbryio/reflector.go/internal/metrics" "github.com/lbryio/reflector.go/store" + log "github.com/sirupsen/logrus" ) @@ -33,6 +36,9 @@ func (s *Server) getBlob(c *gin.Context) { _ = c.AbortWithError(http.StatusInternalServerError, err) return } + metrics.MtrOutBytesHttp.Add(float64(len(blob))) + metrics.BlobDownloadCount.Inc() + metrics.HttpDownloadCount.Inc() c.Header("Via", serialized) c.Header("Content-Disposition", "filename="+hash) c.Data(http.StatusOK, "application/octet-stream", blob) diff --git a/store/http.go b/store/http.go index 11f506d..f79612e 100644 --- a/store/http.go +++ b/store/http.go @@ -8,10 +8,11 @@ import ( "sync" "time" - "github.com/lbryio/lbry.go/v2/extras/errors" - "github.com/lbryio/lbry.go/v2/stream" "github.com/lbryio/reflector.go/internal/metrics" "github.com/lbryio/reflector.go/shared" + + "github.com/lbryio/lbry.go/v2/extras/errors" + "github.com/lbryio/lbry.go/v2/stream" ) // NoopStore is a store that does nothing