getCpuUsage
Monitor CPU usage in the current operating environment to assess system performance and optimize resource allocation efficiently.
Instructions
获取当前平台的 CPU 占用率
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:355-367 (handler)The switch case handler that computes overall CPU usage by aggregating idle and total times from all CPU cores using os.cpus(), then returns the usage percentage as a formatted string in JSON.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) }] }; }
- src/index.ts:73-81 (registration)Tool registration entry in the listTools response handler, defining the tool name, description, and empty input schema (no parameters required).{ name: "getCpuUsage", description: "获取当前平台的 CPU 占用率", inputSchema: { type: "object", properties: {}, required: [] } },
- src/index.ts:76-80 (schema)Input schema for the getCpuUsage tool, which is an empty object (no input parameters).inputSchema: { type: "object", properties: {}, required: [] }