From 1c2760c2a6fd6e21647f7c131938e7823158da39 Mon Sep 17 00:00:00 2001 From: maayarosama Date: Thu, 5 Dec 2024 12:52:37 +0200 Subject: [PATCH 1/4] Removing hdd storage repoting from stats --- packages/playground/src/views/stats.vue | 1 - packages/stats/src/components/stats_table.vue | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/playground/src/views/stats.vue b/packages/playground/src/views/stats.vue index bfe43b3f7a..da0767e272 100644 --- a/packages/playground/src/views/stats.vue +++ b/packages/playground/src/views/stats.vue @@ -141,7 +141,6 @@ const fetchData = async () => { { data: stats!.countries, title: "Countries", icon: "mdi-earth" }, { data: stats!.totalCru, title: "CPUs", icon: "mdi-cpu-64-bit" }, { data: formatResourceSize(stats!.totalSru), title: "SSD Storage", icon: "mdi-nas" }, - { data: formatResourceSize(stats!.totalHru), title: "HDD Storage", icon: "mdi-harddisk" }, { data: formatResourceSize(stats!.totalMru), title: "RAM", icon: "mdi-memory" }, { data: stats!.gpus, title: "GPUs", icon: "mdi-memory" }, { data: stats!.accessNodes, title: "Access Nodes", icon: "mdi-gate" }, diff --git a/packages/stats/src/components/stats_table.vue b/packages/stats/src/components/stats_table.vue index 2d1c80aa37..2a8ebc737a 100644 --- a/packages/stats/src/components/stats_table.vue +++ b/packages/stats/src/components/stats_table.vue @@ -84,11 +84,6 @@ const Istats = computed((): IStatistics[] => { { data: formattedStats.value.totalCru, title: "CPUs", icon: "mdi-cpu-64-bit" }, { data: formattedStats.value.gpus, title: "GPUs", icon: "mdi-memory" }, { data: toTeraOrGigaOrPeta(formattedStats.value.totalSru.toString()), title: "SSD Storage", icon: "mdi-nas" }, - { - data: toTeraOrGigaOrPeta(formattedStats.value.totalHru.toString()), - title: "HDD Storage", - icon: "mdi-harddisk", - }, { data: toTeraOrGigaOrPeta(formattedStats.value.totalMru.toString()), title: "RAM", icon: "mdi-memory" }, { data: formattedStats.value.accessNodes, title: "Access Nodes", icon: "mdi-gate" }, { data: formattedStats.value.gateways, title: "Gateways", icon: "mdi-boom-gate-outline" }, From f5ee485e57973bdbc48d83666a8e21e821fac9be Mon Sep 17 00:00:00 2001 From: maayarosama Date: Thu, 5 Dec 2024 13:03:40 +0200 Subject: [PATCH 2/4] Fixing cols and md --- packages/playground/src/views/stats.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/playground/src/views/stats.vue b/packages/playground/src/views/stats.vue index da0767e272..be3a506463 100644 --- a/packages/playground/src/views/stats.vue +++ b/packages/playground/src/views/stats.vue @@ -29,13 +29,7 @@ - + From b1f0bee2ca8c1829836f05f8c41f305bf38ba4cd Mon Sep 17 00:00:00 2001 From: maayarosama Date: Thu, 5 Dec 2024 14:30:22 +0200 Subject: [PATCH 3/4] 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 }; From bb9bb36479e4c23be42f6d7f8538742cdfa5f50b Mon Sep 17 00:00:00 2001 From: maayarosama Date: Thu, 5 Dec 2024 14:53:48 +0200 Subject: [PATCH 4/4] Changing capacity label and changing ssd capacity to tb or gb in stats --- packages/playground/src/stores/stats.ts | 2 +- .../src/utils/format_resource_size.ts | 18 ++++++++++++++++++ packages/playground/src/views/stats.vue | 4 ++-- packages/stats/nginx/njs/stats.js | 2 +- packages/stats/src/components/stats_table.vue | 4 ++-- packages/stats/src/utils/toTeraOrGegaOrPeta.ts | 18 ++++++++++++++++++ 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/packages/playground/src/stores/stats.ts b/packages/playground/src/stores/stats.ts index ac45479b93..c752de7162 100644 --- a/packages/playground/src/stores/stats.ts +++ b/packages/playground/src/stores/stats.ts @@ -11,7 +11,7 @@ export const useStatsStore = defineStore("stats-store", () => { const data = computed(() => res.value.data); const stats = computed(() => [ { - label: "Capacity", + label: "SSD Capacity", value: data.value?.ssd, image: "capacity.png", }, diff --git a/packages/playground/src/utils/format_resource_size.ts b/packages/playground/src/utils/format_resource_size.ts index afd8862bcf..ba249a5679 100644 --- a/packages/playground/src/utils/format_resource_size.ts +++ b/packages/playground/src/utils/format_resource_size.ts @@ -49,3 +49,21 @@ function toFixedTwo(val: number) { function formatSpeed(val: number) { return Math.round(val); } + +export function toTeraOrGigaStats(sizeInBytes: number) { + const giga = 1024 ** 3; + + if (!sizeInBytes) return "0 GB"; + + const val = +sizeInBytes; + 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"; +} diff --git a/packages/playground/src/views/stats.vue b/packages/playground/src/views/stats.vue index be3a506463..204419751c 100644 --- a/packages/playground/src/views/stats.vue +++ b/packages/playground/src/views/stats.vue @@ -44,7 +44,7 @@ import { NodeStatus, type Stats as GridProxyStats } from "@threefold/gridproxy_client"; import { onMounted, ref } from "vue"; -import formatResourceSize from "@/utils/format_resource_size"; +import formatResourceSize, { toTeraOrGigaStats } from "@/utils/format_resource_size"; import { gridProxyClient } from "../clients"; import StatisticsCard from "../components/statistics_card.vue"; @@ -134,7 +134,7 @@ const fetchData = async () => { { data: stats!.farms, title: "Farms", icon: "mdi-tractor" }, { data: stats!.countries, title: "Countries", icon: "mdi-earth" }, { data: stats!.totalCru, title: "CPUs", icon: "mdi-cpu-64-bit" }, - { data: formatResourceSize(stats!.totalSru), title: "SSD Storage", icon: "mdi-nas" }, + { data: toTeraOrGigaStats(stats!.totalSru), title: "SSD Storage", icon: "mdi-nas" }, { data: formatResourceSize(stats!.totalMru), title: "RAM", icon: "mdi-memory" }, { data: stats!.gpus, title: "GPUs", icon: "mdi-memory" }, { data: stats!.accessNodes, title: "Access Nodes", icon: "mdi-gate" }, diff --git a/packages/stats/nginx/njs/stats.js b/packages/stats/nginx/njs/stats.js index 5eaf0e8246..e7f8336e65 100644 --- a/packages/stats/nginx/njs/stats.js +++ b/packages/stats/nginx/njs/stats.js @@ -131,7 +131,7 @@ function toTeraOrGiga(value) { return gb.toFixed(2) + " PB"; } -function toTeraOrGigaStats(value) { +export function toTeraOrGigaStats(value) { const giga = 1024 ** 3; if (!value) return "0 GB"; diff --git a/packages/stats/src/components/stats_table.vue b/packages/stats/src/components/stats_table.vue index 2a8ebc737a..6e5acf54d2 100644 --- a/packages/stats/src/components/stats_table.vue +++ b/packages/stats/src/components/stats_table.vue @@ -51,7 +51,7 @@ import { computed, type PropType, type Ref, ref, watch } from "vue"; import type { IStatistics, NetworkStats } from "../types/index"; import { formatData, getStats } from "../utils/stats"; -import toTeraOrGigaOrPeta from "../utils/toTeraOrGegaOrPeta"; +import toTeraOrGigaOrPeta, { toTeraOrGigaStats } from "../utils/toTeraOrGegaOrPeta"; import StatisticsCard from "./statistics_card.vue"; const props = defineProps({ @@ -83,7 +83,7 @@ const Istats = computed((): IStatistics[] => { { data: formattedStats.value.countries, title: "Countries", icon: "mdi-earth" }, { data: formattedStats.value.totalCru, title: "CPUs", icon: "mdi-cpu-64-bit" }, { data: formattedStats.value.gpus, title: "GPUs", icon: "mdi-memory" }, - { data: toTeraOrGigaOrPeta(formattedStats.value.totalSru.toString()), title: "SSD Storage", icon: "mdi-nas" }, + { data: toTeraOrGigaStats(formattedStats.value.totalSru.toString()), title: "SSD Storage", icon: "mdi-nas" }, { data: toTeraOrGigaOrPeta(formattedStats.value.totalMru.toString()), title: "RAM", icon: "mdi-memory" }, { data: formattedStats.value.accessNodes, title: "Access Nodes", icon: "mdi-gate" }, { data: formattedStats.value.gateways, title: "Gateways", icon: "mdi-boom-gate-outline" }, diff --git a/packages/stats/src/utils/toTeraOrGegaOrPeta.ts b/packages/stats/src/utils/toTeraOrGegaOrPeta.ts index a03d29f835..b7afdc58f9 100644 --- a/packages/stats/src/utils/toTeraOrGegaOrPeta.ts +++ b/packages/stats/src/utils/toTeraOrGegaOrPeta.ts @@ -19,3 +19,21 @@ export default function toTeraOrGiga(value?: string) { gb = gb / 1024; return `${gb.toFixed(2)} PB`; } + +export function toTeraOrGigaStats(value?: string) { + 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"; +}