Skip to main content
Glama
Heht571
by Heht571

monitor_processes

Monitor remote server processes to identify resource-intensive applications by analyzing CPU and memory usage for system optimization.

Instructions

监控远程服务器进程,返回占用资源最多的进程

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
usernameYes
passwordNo
portNo
top_nNo
sort_byNocpu
timeoutNo

Implementation Reference

  • Core handler function for the monitor_processes MCP tool. Establishes SSH connection to remote server, runs sorted 'ps aux' command to get top processes by CPU/memory/time, parses output using ServerInspector.parse_processes, and returns status and process list.
    def monitor_processes(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        top_n: int = 10,
        sort_by: str = "cpu",
        timeout: int = 30
    ) -> dict:
        """监控远程服务器进程,返回占用资源最多的进程"""
        result = {"status": "unknown", "processes": [], "error": ""}
    
        sort_options = {
            "cpu": "-pcpu",
            "memory": "-pmem",
            "time": "-time"
        }
    
        sort_param = sort_options.get(sort_by, "-pcpu")
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                # 使用ps命令获取进程信息,并按指定条件排序
                command = f"ps aux --sort={sort_param} | head -n {top_n + 1}"  # +1 是为了包含标题行
                stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout)
                raw_output = stdout.read().decode().strip()
    
                # 解析进程信息
                result["processes"] = ServerInspector.parse_processes(raw_output)
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • Identical core handler function for the monitor_processes tool in the SSE variant of the server monitor.
    def monitor_processes(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        top_n: int = 10,
        sort_by: str = "cpu",
        timeout: int = 30
    ) -> dict:
        """监控远程服务器进程,返回占用资源最多的进程"""
        result = {"status": "unknown", "processes": [], "error": ""}
    
        sort_options = {
            "cpu": "-pcpu",
            "memory": "-pmem",
            "time": "-time"
        }
    
        sort_param = sort_options.get(sort_by, "-pcpu")
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                # 使用ps命令获取进程信息,并按指定条件排序
                command = f"ps aux --sort={sort_param} | head -n {top_n + 1}"  # +1 是为了包含标题行
                stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout)
                raw_output = stdout.read().decode().strip()
    
                # 解析进程信息
                result["processes"] = ServerInspector.parse_processes(raw_output)
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • MCP tool registration in FastMCP server. The monitor_processes function is included in tools_dict (line 46) and dynamically registered using mcp.tool().
    tools_dict = {
        'get_memory_info': get_memory_info,
        'remote_server_inspection': remote_server_inspection,
        'get_system_load': get_system_load,
        'monitor_processes': monitor_processes,
        'check_service_status': check_service_status,
        'get_os_details': get_os_details,
        'check_ssh_risk_logins': check_ssh_risk_logins,
        'check_firewall_config': check_firewall_config,
        'security_vulnerability_scan': security_vulnerability_scan,
        'backup_critical_files': backup_critical_files,
        'inspect_network': inspect_network,
        'analyze_logs': analyze_logs,
        'list_docker_containers': list_docker_containers,
        'list_docker_images': list_docker_images,
        'list_docker_volumes': list_docker_volumes,
        'get_container_logs': get_container_logs,
        'monitor_container_stats': monitor_container_stats,
        'check_docker_health': check_docker_health
    }
    
    # 使用装饰器动态注册所有工具
    for name, func in tools_dict.items():
        mcp.tool()(func)
  • Manual dispatch and registration of monitor_processes tool call within the @app.call_tool() handler in the SSE MCP server.
    elif name == "monitor_processes":
        required_args = ["hostname", "username"]
        for arg in required_args:
            if arg not in arguments:
                raise ValueError(f"Missing required argument '{arg}'")
    
        result = monitor_processes(
            hostname=arguments["hostname"],
            username=arguments["username"],
            password=arguments.get("password", ""),
            port=arguments.get("port", 22),
            top_n=arguments.get("top_n", 10),
            sort_by=arguments.get("sort_by", "cpu"),
            timeout=arguments.get("timeout", 30)
        )
  • JSON schema definition for the monitor_processes tool, including parameters, types, and defaults, used in list_available_tools.
    {"name": "monitor_processes", "description": "监控远程服务器进程,返回占用资源最多的进程", "parameters": [
        {"name": "hostname", "type": "str", "default": None},
        {"name": "username", "type": "str", "default": None},
        {"name": "password", "type": "str", "default": ""},
        {"name": "port", "type": "int", "default": 22},
        {"name": "top_n", "type": "int", "default": 10},
        {"name": "sort_by", "type": "str", "default": "cpu"},
        {"name": "timeout", "type": "int", "default": 30}
    ]},
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions monitoring and returning data, implying a read-only operation, but doesn't specify authentication requirements (e.g., SSH credentials), potential side effects (e.g., network connections, process queries), rate limits, or error handling. For a tool with 7 parameters and remote server interaction, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded: a single sentence that directly states the tool's core function. There is no wasted language or redundancy, making it efficient and easy to parse. Every word contributes to understanding the purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (7 parameters, remote server interaction, no annotations, no output schema), the description is incomplete. It lacks details on authentication, network behavior, output format, error conditions, and how it differs from sibling tools. For a monitoring tool with multiple inputs and no structured output, more context is needed to ensure safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate by explaining parameters. It only implicitly references 'hostname' (via '远程服务器' - remote server) and 'top_n'/'sort_by' (via '占用资源最多的进程' - most resource-consuming processes), but doesn't clarify the purpose of 'username', 'password', 'port', 'timeout', or the meaning of 'sort_by' values. With 7 parameters, this minimal coverage is inadequate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '监控远程服务器进程,返回占用资源最多的进程' (monitor remote server processes, return the processes consuming the most resources). It specifies the verb (monitor), resource (remote server processes), and outcome (return top resource-consuming processes). However, it doesn't explicitly differentiate from sibling tools like 'get_system_load' or 'monitor_container_stats', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., SSH access), compare to siblings like 'get_system_load' (which might provide overall system metrics) or 'monitor_container_stats' (which focuses on containers), or specify scenarios where this tool is preferred. Usage is implied but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Heht571/ops-mcp-server'

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