update
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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',
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const VERSION = "0.4.14";
|
||||
export const VERSION = "0.6.3";
|
||||
|
||||
Reference in New Issue
Block a user