From ac63198f74197173722b17f76a3e9680df4b3380 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sat, 12 Mar 2022 18:29:32 +0100 Subject: [PATCH] added wpm, acc and duration histograms --- backend/utils/prometheus.ts | 46 ++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/backend/utils/prometheus.ts b/backend/utils/prometheus.ts index 1312ea44d..fe8383980 100644 --- a/backend/utils/prometheus.ts +++ b/backend/utils/prometheus.ts @@ -1,5 +1,5 @@ import "dotenv/config"; -import { Counter } from "prom-client"; +import { Counter, Histogram } from "prom-client"; const auth = new Counter({ name: "api_request_auth_total", @@ -34,6 +34,32 @@ const resultFunbox = new Counter({ labelNames: ["funbox"], }); +const resultWpm = new Histogram({ + name: "result_wpm", + help: "Result wpm", + labelNames: ["mode", "mode2"], + buckets: [ + 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, + 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, + ], +}); + +const resultAcc = new Histogram({ + name: "result_acc", + help: "Result accuracy", + labelNames: ["mode", "mode2"], + buckets: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], +}); + +const resultDuration = new Histogram({ + name: "result_duration", + help: "Result duration", + buckets: [ + 5, 10, 15, 30, 45, 60, 90, 120, 250, 500, 750, 1000, 1250, 1500, 1750, 2000, + 2500, 3000, + ], +}); + export function incrementAuth(type: "Bearer" | "ApeKey" | "None"): void { auth.inc({ type }); } @@ -81,4 +107,22 @@ export function incrementResult( resultFunbox.inc({ funbox: funbox || "none", }); + + resultWpm.observe( + { + mode, + mode2: m2, + }, + res.wpm + ); + + resultAcc.observe( + { + mode, + mode2: m2, + }, + res.acc + ); + + resultDuration.observe(res.testDuration); }