getCpuUsage
Monitor CPU utilization in real-time to identify performance bottlenecks and optimize system resources for the current operating environment.
Instructions
获取当前平台的 CPU 占用率
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "getCpuUsage"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:74-81 (schema)Schema definition for the getCpuUsage tool, including name, description, and empty input schema.
name: "getCpuUsage", description: "获取当前平台的 CPU 占用率", inputSchema: { type: "object", properties: {}, required: [] } }, - src/index.ts:355-367 (handler)Handler implementation for getCpuUsage tool. Calculates overall CPU usage percentage by aggregating idle and total tick times from os.cpus().
case "getCpuUsage": { const cpus = os.cpus(); const totalIdle = cpus.reduce((acc, cpu) => acc + cpu.times.idle, 0); const totalTick = cpus.reduce((acc, cpu) => acc + Object.values(cpu.times).reduce((a, b) => a + b, 0), 0); const cpuUsage = 1 - totalIdle / totalTick; return { content: [{ type: "text", text: JSON.stringify({ cpuUsage: (cpuUsage * 100).toFixed(2) + '%' }, null, 2) }] }; }