Skip to main content
Glama

Current operating environment

getCpuUsage

Monitor CPU usage in the current operating environment to assess system performance and optimize resource allocation efficiently.

Instructions

获取当前平台的 CPU 占用率

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "required": [], "type": "object" }

Implementation Reference

  • 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: [] } },
  • Input schema for the getCpuUsage tool, which is an empty object (no input parameters).
    inputSchema: { type: "object", properties: {}, required: [] }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JackXuyi/env-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server