disk total mem

This commit is contained in:
2026-04-03 19:02:44 +03:00
parent f8f295f476
commit c5bef1e949
2 changed files with 27 additions and 15 deletions

View File

@ -1,4 +1,4 @@
HOST=i2c@10.0.0.11 HOST=i2c@192.168.1.200
build: dist/index.mjs build: dist/index.mjs

View File

@ -4,35 +4,47 @@ import si from 'systeminformation'
const lcd = new LCD(1, 0x27) const lcd = new LCD(1, 0x27)
await lcd.open() await lcd.open()
function BtoGB(bytes) {
return (bytes / 1024 ** 3).toFixed(1)
}
async function showSystemStats() { async function showSystemStats() {
const [cpu, mem, temp] = await Promise.all([ const [cpu, mem, disks] = await Promise.all([
si.currentLoad(), si.currentLoad(),
si.mem(), si.mem(),
si.cpuTemperature(), si.fsSize(),
]); ]);
const cpuLoad = cpu.currentLoad.toFixed(1); const cpuLoad = cpu.currentLoad.toFixed(1).padStart(4, ' ')
const totalMem = (mem.total / 1024 ** 2).toFixed(0); const totalMem = BtoGB(mem.total)
const usedMem = ((mem.total - mem.available) / 1024 ** 2).toFixed(0); const usedMem = BtoGB(mem.total - mem.available)
const tempC = temp.main?.toFixed(1) ?? 'N/A';
let diskTotalMem = 0
let diskUsedMem = 0
for (const disk of disks) {
diskTotalMem += disk.size
diskUsedMem += disk.used
}
diskTotalMem = BtoGB(diskTotalMem)
diskUsedMem = BtoGB(diskUsedMem)
await lcd.send(LCD.ClearDisplay()) await lcd.send(LCD.ClearDisplay())
const hours = new Date().getHours() const hours = new Date().getHours()
if (hours >= 23 || hours <= 7) { if (hours >= 23 || hours < 7) {
lcd.backlight = false lcd.backlight = false
} else { } else {
lcd.backlight = true lcd.backlight = true
} }
await lcd.jump(0, 0)
await lcd.sendString(`${diskUsedMem}/${diskTotalMem}GB`)
await lcd.jump(0, 0); await lcd.jump(0, 1)
await lcd.sendString(`${cpuLoad}%`); await lcd.sendString(`${usedMem}/${totalMem}GB`)
await lcd.jump(8, 0); await lcd.jump(11, 1)
await lcd.sendString(`${tempC}C`) await lcd.sendString(`${cpuLoad}%`)
await lcd.jump(0, 1);
await lcd.sendString(`${usedMem}/${totalMem} MB`);
} }
await showSystemStats() await showSystemStats()