Files
yenai-plugin/model/State/CPU.js
2024-04-21 21:06:45 +08:00

25 lines
664 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: "vendor,speed,cores",
fullLoad: "*"
})
let { vendor, speed, cores } = cpu
if (currentLoad == null || currentLoad == undefined) return false
fullLoad = Math.round(fullLoad)
vendor = vendor?.split(" ")?.[0] ?? "unknown"
return {
...Circle(currentLoad / 100),
inner: Math.round(currentLoad) + "%",
title: "CPU",
info: [
`${vendor} ${cores}${speed}GHz`,
`CPU满载率 ${fullLoad}%`
]
}
}