Skip to content

Commit

Permalink
feat(root-admin): use a size format who support up to Yottabyte
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed Jul 17, 2024
1 parent a3644d0 commit 050df18
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@bull-board/koa": "^5.9.1",
"@dnd-kit/core": "6.0.6",
"@dnd-kit/sortable": "7.0.1",
"@draconides/format": "1.0.3",
"@emotion/react": "11.7.1",
"@emotion/styled": "11.6.0",
"@ezs/analytics": "2.3.2",
Expand Down
4 changes: 2 additions & 2 deletions src/api/controller/rootAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const getTenants = async (ctx, filter) => {
for (const tenant of tenants) {
const db = await mongoClient(tenant.name);

tenant.totalSize = (await db.stats({ scale: 1024 })).totalSize;
tenant.totalSize = (await db.stats()).totalSize;

try {
tenant.dataset = await db.collection('dataset').find().count();
Expand Down Expand Up @@ -163,7 +163,7 @@ function getAverageUsage() {
}

const systemInfo = async (ctx) => {
const dbStats = await ctx.rootAdminDb.stats({ scale: 1024 });
const dbStats = await ctx.rootAdminDb.stats();
ctx.body = {
cpu: os.cpus().length,
load: getAverageUsage(),
Expand Down
4 changes: 2 additions & 2 deletions src/app/js/root-admin/SystemLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ const SystemLoad = () => {
);
setLoadAvg(data.load * 100);

const totalMem = data.totalmem / 1024;
const usedMem = (data.totalmem - data.freemem) / 1024;
const totalMem = data.totalmem;
const usedMem = data.totalmem - data.freemem;
const memPercent = (100 * usedMem) / totalMem;

setMemUsage(memPercent);
Expand Down
19 changes: 8 additions & 11 deletions src/app/js/root-admin/rootAdminUtils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { formatBytes } from '@draconides/format';

const numberFormatter = new Intl.NumberFormat('fr-FR');

export const sizeConverter = (value) => {
if (value == null) {
return '-';
}

const mbSize = (value / 1024).toFixed(2);

if (mbSize > 1024) {
return `${(mbSize / 1024).toFixed(2)} Gio`;
}

if (mbSize > 1) {
return `${mbSize} Mio`;
}

return `${value} Kio`;
return formatBytes(Number(value), {
style: 'octet',
formatter: numberFormatter.format,
});
};

0 comments on commit 050df18

Please sign in to comment.