From b1f0bee2ca8c1829836f05f8c41f305bf38ba4cd Mon Sep 17 00:00:00 2001 From: maayarosama Date: Thu, 5 Dec 2024 14:30:22 +0200 Subject: [PATCH] Adding ssd to stats summary endpoint --- packages/playground/src/stores/stats.ts | 2 +- packages/stats/nginx/njs/stats.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/playground/src/stores/stats.ts b/packages/playground/src/stores/stats.ts index 60625ed3b6..ac45479b93 100644 --- a/packages/playground/src/stores/stats.ts +++ b/packages/playground/src/stores/stats.ts @@ -12,7 +12,7 @@ export const useStatsStore = defineStore("stats-store", () => { const stats = computed(() => [ { label: "Capacity", - value: data.value?.capacity, + value: data.value?.ssd, image: "capacity.png", }, { diff --git a/packages/stats/nginx/njs/stats.js b/packages/stats/nginx/njs/stats.js index 73d848ffc5..5eaf0e8246 100644 --- a/packages/stats/nginx/njs/stats.js +++ b/packages/stats/nginx/njs/stats.js @@ -78,10 +78,10 @@ function mergeStatsData(stats) { const result = {}; result.capacity = toTeraOrGiga(res.totalHru + res.totalSru); + result.ssd = toTeraOrGigaStats(res.totalSru); result.nodes = res.nodes; result.countries = res.countries; result.cores = res.totalCru; - return result; } @@ -131,5 +131,23 @@ function toTeraOrGiga(value) { return gb.toFixed(2) + " PB"; } +function toTeraOrGigaStats(value) { + const giga = 1024 ** 3; + + if (!value) return "0 GB"; + + const val = +value; + if (val === 0 || isNaN(val)) return "0 GB"; + + const gb = val / giga; + + if (gb < 100) { + return gb.toFixed(2) + " GB"; + } + + const tb = gb / 1024; + return tb.toFixed(2) + " TB"; +} + // Exporting the main function for Nginx export default { getStats, updateStats };