From a87b633ca3f057ca3402b9531d61ce9da223518f Mon Sep 17 00:00:00 2001 From: Jacob Gunther Date: Thu, 24 Mar 2022 04:40:55 -0500 Subject: [PATCH] Add more metrics --- src/routes/body.go | 30 ++++++++++++++++++++++++++++++ src/routes/face.go | 6 ++++++ src/routes/head.go | 6 ++++++ src/util/util.go | 18 +++++++++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/routes/body.go b/src/routes/body.go index defa950..78db397 100644 --- a/src/routes/body.go +++ b/src/routes/body.go @@ -13,22 +13,42 @@ import ( ) var ( + requestFullBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "full_body_request_count", + Help: "The amount of full body requests", + }) renderFullBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "full_body_render_count", Help: "The amount of full body renders", }) + requestFrontBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "front_body_request_count", + Help: "The amount of front body requests", + }) renderFrontBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "front_body_render_count", Help: "The amount of front body renders", }) + requestBackBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "back_body_request_count", + Help: "The amount of back body requests", + }) renderBackBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "back_body_render_count", Help: "The amount of back body renders", }) + requestLeftBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "left_body_request_count", + Help: "The amount of left body requests", + }) renderLeftBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "left_body_render_count", Help: "The amount of left body renders", }) + requestRightBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "right_body_request_count", + Help: "The amount of right body requests", + }) renderRightBodyMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "right_body_render_count", Help: "The amount of right body renders", @@ -36,6 +56,8 @@ var ( ) func FullBodyHandler(ctx *fasthttp.RequestCtx) { + requestFullBodyMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.FullBody) @@ -142,6 +164,8 @@ func FullBodyHandler(ctx *fasthttp.RequestCtx) { } func FrontBodyHandler(ctx *fasthttp.RequestCtx) { + requestFrontBodyMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.FrontBody) @@ -248,6 +272,8 @@ func FrontBodyHandler(ctx *fasthttp.RequestCtx) { } func BackBodyHandler(ctx *fasthttp.RequestCtx) { + requestBackBodyMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.BackBody) @@ -354,6 +380,8 @@ func BackBodyHandler(ctx *fasthttp.RequestCtx) { } func LeftBodyHandler(ctx *fasthttp.RequestCtx) { + requestLeftBodyMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.LeftBody) @@ -460,6 +488,8 @@ func LeftBodyHandler(ctx *fasthttp.RequestCtx) { } func RightBodyHandler(ctx *fasthttp.RequestCtx) { + requestRightBodyMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.RightBody) diff --git a/src/routes/face.go b/src/routes/face.go index be97cef..b7aff44 100644 --- a/src/routes/face.go +++ b/src/routes/face.go @@ -13,6 +13,10 @@ import ( ) var ( + requestFaceMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "face_request_count", + Help: "The amount of face requests", + }) renderFaceMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "face_render_count", Help: "The amount of face renders", @@ -20,6 +24,8 @@ var ( ) func FaceHandler(ctx *fasthttp.RequestCtx) { + requestFaceMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.Face) diff --git a/src/routes/head.go b/src/routes/head.go index 44e1b24..e375a6f 100644 --- a/src/routes/head.go +++ b/src/routes/head.go @@ -13,6 +13,10 @@ import ( ) var ( + requestHeadMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "head_request_count", + Help: "The amount of head requests", + }) renderHeadMetric = promauto.NewCounter(prometheus.CounterOpts{ Name: "head_render_count", Help: "The amount of head renders", @@ -20,6 +24,8 @@ var ( ) func HeadHandler(ctx *fasthttp.RequestCtx) { + requestHeadMetric.Inc() + user := ctx.UserValue("user").(string) opts := util.ParseQueryParams(ctx, config.Routes.Head) diff --git a/src/util/util.go b/src/util/util.go index 8ff0ac2..e349742 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -15,10 +15,22 @@ import ( "github.com/mineatar-io/api-server/src/conf" "github.com/mineatar-io/skin-render" "github.com/mineatar-io/yggdrasil" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/valyala/fasthttp" ) -var Debug bool = os.Getenv("DEBUG") == "true" +var ( + Debug bool = os.Getenv("DEBUG") == "true" + yggdrasilUUIDLookupMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "yggdrasil_uuid_lookup_count", + Help: "The amount of Yggdrasil UUID lookup requests", + }) + yggdrasilTextureLookupMetric = promauto.NewCounter(prometheus.CounterOpts{ + Name: "yggdrasil_texture_lookup_count", + Help: "The amount of Yggdrasil texture lookup requests", + }) +) type QueryParams struct { Scale int @@ -60,6 +72,8 @@ func LookupUUID(value string) (string, bool, error) { return "", false, err } + yggdrasilUUIDLookupMetric.Inc() + if profile == nil { if Debug { log.Printf("Fetched UUID from Mojang for '%s', did not exist\n", value) @@ -142,6 +156,8 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) { return nil, false, err } + yggdrasilTextureLookupMetric.Inc() + if textures == nil { if Debug { log.Printf("Fetched textures for '%s' from Mojang, none exists, using default skin\n", uuid)