system_processes
Monitor and analyze top system processes by CPU or memory usage to identify resource consumption patterns and performance bottlenecks.
Instructions
List top processes sorted by CPU or memory usage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sort_by | No | 'cpu' or 'memory' (default: 'memory') | |
| limit | No | Number of processes to show (default: 20) |
Implementation Reference
- src/tools/system/processes.ts:6-27 (handler)The main handler function for the `system_processes` tool which executes the `ps` command to list processes.
export async function listProcesses(args: Record<string, unknown>): Promise<string> { const sortBy = (args.sort_by as string) || "memory"; const limit = (args.limit as number) || 20; const sortFlag = sortBy === "cpu" ? "-%cpu" : "-%mem"; try { const { stdout } = await execFileAsync( "ps", ["aux", `--sort=${sortFlag}`], { timeout: 10000 } ); const lines = stdout.trim().split("\n"); const header = lines[0]; const processes = lines.slice(1, limit + 1); return `Top ${processes.length} processes by ${sortBy}:\n\n${header}\n${processes.join("\n")}`; } catch (error: any) { throw new Error(`Failed to list processes: ${error.message}`); } } - src/tools/system/index.ts:18-28 (registration)The registration definition for the `system_processes` tool.
{ name: "system_processes", description: "List top processes sorted by CPU or memory usage", inputSchema: { type: "object" as const, properties: { sort_by: { type: "string", description: "'cpu' or 'memory' (default: 'memory')" }, limit: { type: "number", description: "Number of processes to show (default: 20)" }, }, }, }, - src/tools/system/index.ts:61-61 (handler)The routing logic in `handleSystemTool` that maps the `system_processes` name to the `listProcesses` implementation.
case "system_processes": return listProcesses(a);