adds bytes per second gauge for fetch endpoint

This commit is contained in:
benbierens 2023-09-06 08:46:21 +02:00
parent 44ed0b6b37
commit 9ea75f033b
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 8 additions and 0 deletions

View File

@ -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)