From bc3be6f87fdfb94460b56b0a1f2e578ba25f79c9 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 7 Sep 2023 08:12:00 +0200 Subject: [PATCH] gauges as float values --- codex/node.nim | 4 ++-- codex/rest/api.nim | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/codex/node.nim b/codex/node.nim index d7f799c2..70c9f11a 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -173,7 +173,7 @@ proc retrieve*( proc store*( self: CodexNodeRef, stream: LPStream, - blockSize = DefaultBlockSize): Future[?!Cid] {.async.} = + blockSize = DefaultBlockSize): Future[?!(Manifest, Cid)] {.async.} = ## Save stream contents as dataset with given blockSize ## to nodes's BlockStore, and return Cid of its manifest ## @@ -233,7 +233,7 @@ proc store*( # Announce manifest await self.discovery.provide(manifest.cid) - return manifest.cid.success + return success (blockManifest, manifest.cid) proc requestStorage*( self: CodexNodeRef, diff --git a/codex/rest/api.nim b/codex/rest/api.nim index 367a2bea..44433a96 100644 --- a/codex/rest/api.nim +++ b/codex/rest/api.nim @@ -46,9 +46,9 @@ logScope: 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") +declareGauge(codexApiUploadBytesPerMilliSecond, "codex API upload bytes per millisecond") +declareGauge(codexApiDownloadBytesPerMilliSecond, "codex API download bytes per millisecond") +declareGauge(codexApiFetchBytesPerMilliSecond, "codex API fetch bytes per millisecond") proc validate( pattern: string, @@ -194,10 +194,11 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = await resp.finish() let stop = getMonoTime().ticks - totalSeconds = (stop - start) div 1000000.int64 - downloadBytesPerSecond = bytes div totalSeconds + bytesFloat = bytes.float64 + totalMilliseconds = (stop - start) div 1000.int64 + downloadBytesPerMilliSecond = bytesFloat / (totalMilliseconds.float64) codexApiDownloads.inc() - codexApiDownloadBytesPerSecond.set(downloadBytesPerSecond.int64) + codexApiDownloadBytesPerMilliSecond.set(downloadBytesPerMilliSecond.float64) except CatchableError as exc: trace "Excepting streaming blocks", exc = exc.msg return RestApiResponse.error(Http500) @@ -270,17 +271,17 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = let start = getMonoTime().ticks wrapper = AsyncStreamWrapper.new(reader = AsyncStreamReader(reader)) - without cid =? ( + without (manifest, cid) =? ( await node.store(wrapper)), error: trace "Error uploading file", exc = error.msg return RestApiResponse.error(Http500, error.msg) let stop = getMonoTime().ticks - bytes = wrapper.reader.bytesCount.int64 - totalSeconds = (stop - start) div 1000000.int64 - uploadBytesPerSecond = bytes div totalSeconds - codexApiUploadBytesPerSecond.set(uploadBytesPerSecond.int64) + bytes = manifest.originalBytes.float64 + totalMilliseconds = (stop - start) div 1000.int64 + uploadBytesPerMilliSecond = bytes / (totalMilliseconds.float64) + codexApiUploadBytesPerMilliSecond.set(uploadBytesPerMilliSecond.float64) codexApiUploads.inc() trace "Uploaded file", cid return RestApiResponse.response($cid) @@ -379,10 +380,10 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter = let stop = getMonoTime().ticks - bytes = manifest.originalBytes.int64 - totalSeconds = (stop - start) div 1000000.int64 - fetchBytesPerSecond = bytes div totalSeconds - codexApiFetchBytesPerSecond.set(fetchBytesPerSecond.int64) + bytes = manifest.originalBytes.float64 + totalMilliseconds = (stop - start) div 1000.int64 + fetchBytesPerMilliSecond = bytes / (totalMilliseconds.float64) + codexApiFetchBytesPerMilliSecond.set(fetchBytesPerMilliSecond.float64) let json = formatManifest(manifest) trace "Blocks fetched. Debug/fetch returning manifest" return RestApiResponse.response($json)