Skip to content

Commit

Permalink
Adding ssd to stats summary endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
maayarosama committed Dec 5, 2024
1 parent f5ee485 commit b1f0bee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/playground/src/stores/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand Down
20 changes: 19 additions & 1 deletion packages/stats/nginx/njs/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 };

0 comments on commit b1f0bee

Please sign in to comment.