luci-mod-status: convert bytes into KB / MB / GB on progress bar
Currently on the system status page the the memory usage is shown in kB only. If you have a system with 1 GB of Ram its hard to read the large numbers. This automatically formats the byte numbers more human readable into KB / MB / GB. Submitted-by: Claudio Marelli <camarelli@gmx.net> [squash commits, rewrap commit message] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
faa5f0eacd
commit
97da884240
1 changed files with 23 additions and 16 deletions
|
@ -1,13 +1,15 @@
|
||||||
function progressbar(q, v, m)
|
function progressbar(query, value, max, byte)
|
||||||
{
|
{
|
||||||
var pg = document.querySelector(q),
|
var pg = document.querySelector(query),
|
||||||
vn = parseInt(v) || 0,
|
vn = parseInt(value) || 0,
|
||||||
mn = parseInt(m) || 100,
|
mn = parseInt(max) || 100,
|
||||||
|
fv = byte ? String.format('%1024.2mB', value) : value,
|
||||||
|
fm = byte ? String.format('%1024.2mB', max) : max,
|
||||||
pc = Math.floor((100 / mn) * vn);
|
pc = Math.floor((100 / mn) * vn);
|
||||||
|
|
||||||
if (pg) {
|
if (pg) {
|
||||||
pg.firstElementChild.style.width = pc + '%';
|
pg.firstElementChild.style.width = pc + '%';
|
||||||
pg.setAttribute('title', '%s / %s (%d%%)'.format(v, m, pc));
|
pg.setAttribute('title', '%s / %s (%d%%)'.format(fv, fm, pc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,27 +191,32 @@ L.poll(5, L.location(), { status: 1 },
|
||||||
);
|
);
|
||||||
|
|
||||||
progressbar('#memtotal',
|
progressbar('#memtotal',
|
||||||
((info.memory.free + info.memory.buffered) / 1024) + ' ' + _('kB'),
|
info.memory.free + info.memory.buffered,
|
||||||
(info.memory.total / 1024) + ' ' + _('kB'));
|
info.memory.total,
|
||||||
|
true);
|
||||||
|
|
||||||
progressbar('#memfree',
|
progressbar('#memfree',
|
||||||
(info.memory.free / 1024) + ' ' + _('kB'),
|
info.memory.free,
|
||||||
(info.memory.total / 1024) + ' ' + _('kB'));
|
info.memory.total,
|
||||||
|
true);
|
||||||
|
|
||||||
progressbar('#membuff',
|
progressbar('#membuff',
|
||||||
(info.memory.buffered / 1024) + ' ' + _('kB'),
|
info.memory.buffered,
|
||||||
(info.memory.total / 1024) + ' ' + _('kB'));
|
info.memory.total,
|
||||||
|
true);
|
||||||
|
|
||||||
progressbar('#swaptotal',
|
progressbar('#swaptotal',
|
||||||
(info.swap.free / 1024) + ' ' + _('kB'),
|
info.swap.free,
|
||||||
(info.swap.total / 1024) + ' ' + _('kB'));
|
info.swap.total,
|
||||||
|
true);
|
||||||
|
|
||||||
progressbar('#swapfree',
|
progressbar('#swapfree',
|
||||||
(info.swap.free / 1024) + ' ' + _('kB'),
|
info.swap.free,
|
||||||
(info.swap.total / 1024) + ' ' + _('kB'));
|
info.swap.total,
|
||||||
|
true);
|
||||||
|
|
||||||
progressbar('#conns',
|
progressbar('#conns',
|
||||||
info.conncount, info.connmax);
|
info.conncount, info.connmax, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue