Skip to main content
Glama

docker_container_stats

Monitor real-time CPU, memory, and network statistics for Docker containers to track performance and resource usage.

Instructions

Get real-time CPU, memory, and network stats for a container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesContainer ID or name

Implementation Reference

  • Implementation of the containerStats function which fetches and formats Docker container metrics.
    export async function containerStats(args: Record<string, unknown>): Promise<string> {
      const docker = getDockerClient();
      const id = args.id as string || args.name as string;
      if (!id) throw new Error("Container ID or name is required");
    
      const container = docker.getContainer(id);
      const stats = await container.stats({ stream: false });
    
      const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - stats.precpu_stats.cpu_usage.total_usage;
      const systemDelta = stats.cpu_stats.system_cpu_usage - stats.precpu_stats.system_cpu_usage;
      const cpuPercent = systemDelta > 0 ? (cpuDelta / systemDelta) * 100 : 0;
    
      const memUsage = stats.memory_stats.usage || 0;
      const memLimit = stats.memory_stats.limit || 1;
      const memPercent = (memUsage / memLimit) * 100;
    
      const lines = [
        `Stats for container '${id}':`,
        "",
        `  CPU:     ${cpuPercent.toFixed(2)}%`,
        `  Memory:  ${Math.round(memUsage / 1024 / 1024)}Mi / ${Math.round(memLimit / 1024 / 1024)}Mi (${memPercent.toFixed(1)}%)`,
      ];
    
      const networks = stats.networks || {};
      for (const [iface, net] of Object.entries(networks)) {
        const n = net as { rx_bytes: number; tx_bytes: number };
        lines.push(`  Net ${iface}: RX ${Math.round(n.rx_bytes / 1024)}Ki / TX ${Math.round(n.tx_bytes / 1024)}Ki`);
      }
    
      return lines.join("\n");
    }
  • Registration of the 'docker_container_stats' tool in the Docker tools list.
      name: "docker_container_stats",
      description: "Get real-time CPU, memory, and network stats for a container",
      inputSchema: {
        type: "object" as const,
        properties: {
          id: { type: "string", description: "Container ID or name" },
        },
        required: ["id"],
      },
    },
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 states the tool retrieves 'real-time' stats, implying dynamic data, but doesn't cover critical aspects like whether this is a one-time snapshot or continuous stream, permissions required, rate limits, or error conditions (e.g., if container isn't running).

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 a single, efficient sentence that front-loads the core purpose ('Get real-time CPU, memory, and network stats for a container'). There's no wasted verbiage or redundancy, making it highly scannable and direct.

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?

For a tool with no annotations and no output schema, the description is insufficient. It lacks details on return format (e.g., JSON structure, units for metrics), behavioral traits (e.g., streaming vs. snapshot), and error handling. Given the complexity of system metrics, more context is needed for effective use.

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

Parameters3/5

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

The input schema has 100% description coverage, with the 'id' parameter clearly documented as 'Container ID or name'. The description doesn't add any parameter details beyond this, so it meets the baseline for high schema coverage without compensating value.

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 with a specific verb ('Get') and resource ('real-time CPU, memory, and network stats for a container'), making it immediately understandable. It distinguishes from siblings like docker_inspect_container (detailed configuration) or docker_list_containers (listing containers), though it doesn't explicitly name these alternatives.

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., container must be running), compare to similar tools (e.g., docker_inspect_container for static info), or specify use cases (e.g., monitoring vs. debugging).

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/batu-sonmez/infraclaude'

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