Files
yenai-plugin/model/State/CPU.js
2024-04-22 18:07:30 +08:00

25 lines
694 B
JavaScript

import { si, Circle } from "./utils.js"
/** 获取CPU占用 */
export default async function getCpuInfo() {
let { currentLoad: { currentLoad }, cpu, fullLoad } = await si.get({
currentLoad: "currentLoad",
cpu: "manufacturer,speed,cores",
fullLoad: "*"
})
let { manufacturer, speed, cores } = cpu
if (currentLoad == null || currentLoad == undefined) return false
fullLoad = Math.round(fullLoad)
manufacturer = manufacturer?.split(" ")?.[0] ?? "unknown"
return {
...Circle(currentLoad / 100),
inner: Math.round(currentLoad) + "%",
title: "CPU",
info: [
`${manufacturer} ${cores}${speed}GHz`,
`CPU满载率 ${fullLoad}%`
]
}
}