From 9ea75f033b3f4d4402130ada5682f01435f20b25 Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 6 Sep 2023 08:46:21 +0200 Subject: [PATCH] adds bytes per second gauge for fetch endpoint --- codex/rest/api.nim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 4d8c2cd8..367a2bea 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -48,6 +48,7 @@ declareCounter(codexApiUploads, "codex API uploads") declareCounter(codexApiDownloads, "codex API downloads") declareGauge(codexApiUploadBytesPerSecond, "codex API upload bytes per second") declareGauge(codexApiDownloadBytesPerSecond, "codex API download bytes per second") +declareGauge(codexApiFetchBytesPerSecond, "codex API fetch bytes per second") proc validate( pattern: string, @@ -367,6 +368,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = $id.error()) try: + let start = getMonoTime().ticks trace "Fetching manifest" without manifest =? (await node.fetchManifest(id.get())), error: return RestApiResponse.error(Http404, error.msg) @@ -375,6 +377,12 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = if isErr(await node.fetchBatched(manifest)): return RestApiResponse.error(Http404, "fetchBatched failed.") + let + stop = getMonoTime().ticks + bytes = manifest.originalBytes.int64 + totalSeconds = (stop - start) div 1000000.int64 + fetchBytesPerSecond = bytes div totalSeconds + codexApiFetchBytesPerSecond.set(fetchBytesPerSecond.int64) let json = formatManifest(manifest) trace "Blocks fetched. Debug/fetch returning manifest" return RestApiResponse.response($json)