getCpuUsage
Monitor CPU utilization in real-time to identify performance bottlenecks and optimize system resources for the current operating environment.
Instructions
获取当前平台的 CPU 占用率
Input Schema
TableJSON 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) }] }; }