This commit is contained in:
2026-01-12 14:34:56 +00:00
parent 2b87d63121
commit 2d4846cfed
12 changed files with 1173 additions and 566 deletions

File diff suppressed because one or more lines are too long

View File

@@ -78,6 +78,8 @@ export interface SystemInfoData {
}
export class SystemInfo {
private lastCpuStats: { total: number; idle: number } | null = null;
async getInfo(): Promise<SystemInfoData> {
const [hostname, cpu, memory, disks, network, gpu, uptime, inputDevices, speakers, microphones] =
await Promise.all([
@@ -112,13 +114,23 @@ export class SystemInfo {
const modelMatch = cpuinfo.match(/model name\s*:\s*(.+)/);
const coreMatches = cpuinfo.match(/processor\s*:/g);
// Get CPU usage from /proc/stat
// Get CPU usage from /proc/stat (delta between readings)
const stat = await Deno.readTextFile('/proc/stat');
const cpuLine = stat.split('\n')[0];
const values = cpuLine.split(/\s+/).slice(1).map(Number);
const total = values.reduce((a, b) => a + b, 0);
const idle = values[3];
const usage = ((total - idle) / total) * 100;
const idle = values[3] + values[4]; // idle + iowait
let usage = 0;
if (this.lastCpuStats) {
const totalDelta = total - this.lastCpuStats.total;
const idleDelta = idle - this.lastCpuStats.idle;
if (totalDelta > 0) {
usage = ((totalDelta - idleDelta) / totalDelta) * 100;
}
}
this.lastCpuStats = { total, idle };
return {
model: modelMatch ? modelMatch[1] : 'Unknown',

View File

@@ -1 +1 @@
export const VERSION = "0.4.14";
export const VERSION = "0.6.3";