Skip to main content
Glama

cpu_memory_health

Monitors CPU, memory, and swap usage, kernel OOM-kill count over 24 hours, and load averages. Detects OOM-imminent or triggered conditions to assess health.

Instructions

CPU% + memory% + swap% snapshot, kernel OOM-kill count over 24h, load averages. Each component gets a HealthLevel; CRITICAL when OOM-imminent or already triggered.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool 'cpu_memory_health' is registered in the list_tools() function with its name, description, and inputSchema.
    Tool(
        name="cpu_memory_health",
        description=(
            "CPU% + memory% + swap% snapshot, kernel OOM-kill count over 24h, "
            "load averages. Each component gets a HealthLevel; CRITICAL when "
            "OOM-imminent or already triggered."
        ),
        inputSchema={"type": "object", "properties": {}, "required": []},
    ),
  • The call_tool() handler for 'cpu_memory_health' delegates to backend.get_resource_metrics() and serializes the result.
    if name == "cpu_memory_health":
        return _serialize(await backend.get_resource_metrics())
  • ResourceMetrics Pydantic model — the schema/return type for the cpu_memory_health tool (CPU%, memory%, swap%, OOM count, load averages, health levels).
    class ResourceMetrics(BaseModel):
        """CPU + memory + swap snapshot."""
    
        model_config = ConfigDict(frozen=True)
    
        cpu_percent: float | None = None
        memory_percent: float | None = None
        memory_used_mb: float | None = None
        memory_total_mb: float | None = None
        swap_percent: float | None = None
        swap_used_mb: float | None = None
        oom_events_24h: int = 0
        """Kernel OOM-killer invocations in the last 24h (read from journalctl/dmesg)."""
        load_average_1m: float | None = None
        load_average_5m: float | None = None
        load_average_15m: float | None = None
        cpu_health: HealthLevel = HealthLevel.UNKNOWN
        memory_health: HealthLevel = HealthLevel.UNKNOWN
        overall_health: HealthLevel = HealthLevel.UNKNOWN
        notes: list[str] = Field(default_factory=list)
  • LinuxProcBackend.get_resource_metrics() — real implementation using psutil for CPU/memory/swap/load and _count_oom_events_24h() for OOM detection, with health classification thresholds.
    async def get_resource_metrics(self) -> ResourceMetrics:
        if psutil is None:  # pragma: no cover  # type: ignore[unreachable]
            return ResourceMetrics(  # type: ignore[unreachable]
                overall_health=HealthLevel.UNKNOWN,
                notes=["psutil not installed."],
            )
    
        try:
            cpu = psutil.cpu_percent(interval=0.1)
            mem = psutil.virtual_memory()
            swap = psutil.swap_memory()
        except Exception:  # noqa: BLE001 - psutil errors are platform-specific; degrade gracefully
            return ResourceMetrics(
                overall_health=HealthLevel.UNKNOWN,
                notes=["psutil call failed; backend cannot read metrics."],
            )
    
        load_1m = load_5m = load_15m = None
        if hasattr(psutil, "getloadavg"):
            with contextlib.suppress(OSError, AttributeError):
                load_1m, load_5m, load_15m = psutil.getloadavg()
    
        oom = _count_oom_events_24h()
    
        cpu_h = _classify_pct(cpu, degraded=_CPU_DEGRADED_PCT, critical=_CPU_CRITICAL_PCT)
        mem_h = _classify_pct(mem.percent, degraded=_MEM_DEGRADED_PCT, critical=_MEM_CRITICAL_PCT)
        swap_h = _classify_pct(swap.percent, degraded=_SWAP_DEGRADED_PCT, critical=_SWAP_CRITICAL_PCT)
        oom_h = HealthLevel.CRITICAL if oom > 0 else HealthLevel.HEALTHY
        overall = _max_level(cpu_h, mem_h, swap_h, oom_h)
    
        notes: list[str] = []
        if mem.percent >= _MEM_DEGRADED_PCT:
            notes.append(f"Memory at {mem.percent:.1f}% — watch for OOM under spike load.")
        if swap.percent >= _SWAP_DEGRADED_PCT:
            notes.append(f"Swap at {swap.percent:.1f}% — system may be paging heavily.")
        if oom > 0:
            notes.append(
                f"{oom} OOM kill event(s) detected in last 24h via journalctl/dmesg."
            )
    
        return ResourceMetrics(
            cpu_percent=cpu,
            memory_percent=mem.percent,
            memory_used_mb=mem.used / (1024 * 1024),
            memory_total_mb=mem.total / (1024 * 1024),
            swap_percent=swap.percent,
            swap_used_mb=swap.used / (1024 * 1024),
            oom_events_24h=oom,
            load_average_1m=load_1m,
            load_average_5m=load_5m,
            load_average_15m=load_15m,
            cpu_health=cpu_h,
            memory_health=mem_h,
            overall_health=overall,
            notes=notes,
        )
  • MockBackend.get_resource_metrics() — mock implementation providing sample data for development/ testing.
    async def get_resource_metrics(self) -> ResourceMetrics:
        return ResourceMetrics(
            cpu_percent=42.7,
            memory_percent=78.3,
            memory_used_mb=1602.0,
            memory_total_mb=2048.0,
            swap_percent=12.5,
            swap_used_mb=128.0,
            oom_events_24h=0,
            load_average_1m=1.42,
            load_average_5m=1.28,
            load_average_15m=1.12,
            cpu_health=HealthLevel.HEALTHY,
            memory_health=HealthLevel.DEGRADED,
            overall_health=HealthLevel.DEGRADED,
            notes=[
                "Memory at 78% — elevated for a 2GB VPS. Watch for OOM if a cron-heavy hour spikes load.",
            ],
        )
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It describes the tool as taking a 'snapshot' (non-destructive), and indicates CRITICAL levels for OOM-imminent conditions. This provides good behavioral insight, though it does not explicitly state read-only or side-effect-free 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 with three sentences, each adding distinct value. It front-loads the core purpose ('CPU% + memory% + swap% snapshot') and then elaborates with additional components and HealthLevel semantics. No redundancy or wasted words.

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

Completeness4/5

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

Given no annotations, no output schema, and zero parameters, the description adequately covers the tool's functionality and behavioral traits. However, it lacks details about the exact response structure or the HealthLevel range, which could be helpful for an agent. Still, it is sufficiently complete for a simple health snapshot tool.

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

Parameters4/5

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

The input schema has zero parameters and 100% description coverage. According to the guidelines, 0 parameters gives a baseline of 4. The description does not add parameter info (none needed), so this score is appropriate.

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

Purpose5/5

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

The description clearly defines the tool as a health snapshot of CPU, memory, swap, OOM-kill count, and load averages with HealthLevel classifications. It distinguishes itself from sibling health tools by focusing specifically on CPU/memory/swap health, while 'health_overview' suggests a broader summary.

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 does not provide any guidance on when to use this tool versus siblings like 'health_overview' or 'disk_usage'. It only describes what it does, leaving the agent to infer usage context without explicit when-to-use or when-not-to-use instructions.

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/temurkhan13/openclaw-health-mcp'

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