Container stats
container_statsMonitor container resource usage statistics including CPU, memory, and network metrics to track performance and identify resource bottlenecks in Podman containers.
Instructions
Get resource usage statistics for containers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | No | Container name or ID (all containers if not specified) | |
| no_stream | No | Disable streaming stats and only pull the first result |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- main_b.py:582-591 (handler)The main handler function that implements the container_stats tool logic by running the 'podman stats' command with appropriate arguments and returning the JSON-formatted output or error message.
async def container_stats(self, args: Dict[str, Any]) -> Dict[str, Any]: container = args.get("container") no_stream = args.get("no_stream", True) cmd_args = ["stats", "--format", "json"] if no_stream: cmd_args.append("--no-stream") if container: cmd_args.append(container) result = run_podman(cmd_args) return {"output": result["stdout"] if result["success"] else f"Error: {result['stderr']}"} - main_b.py:373-386 (schema)The input schema for the container_stats tool, defining optional 'container' parameter (string) and 'no_stream' parameter (boolean, default true).
inputSchema={ "type": "object", "properties": { "container": { "type": "string", "description": "Container name or ID (all containers if not specified)" }, "no_stream": { "type": "boolean", "description": "Disable streaming stats and only pull the first result", "default": True } } } - main_b.py:370-387 (registration)Registration of the container_stats tool in the server's tools list, including name, description, and input schema.
Tool( name="container_stats", description="Get resource usage statistics for containers", inputSchema={ "type": "object", "properties": { "container": { "type": "string", "description": "Container name or ID (all containers if not specified)" }, "no_stream": { "type": "boolean", "description": "Disable streaming stats and only pull the first result", "default": True } } } ) - main_b.py:471-472 (registration)Mapping the 'container_stats' tool name to its handler method in the tool_handlers dictionary used in handle_tools_call.
"container_stats": self.container_stats, } - main.py:444-454 (handler)Alternative synchronous handler for container_stats using @mcp.tool decorator, which also implies schema from Field annotations and auto-registration.
def container_stats( container: str = Field(None, description="Container name or ID (all containers if not specified)"), no_stream: bool = Field(True, description="Disable streaming stats and only pull the first result") ) -> str: args = ["stats", "--format", "json"] if no_stream: args.append("--no-stream") if container: args.append(container) result = run_podman(args) return result["stdout"] if result["success"] else f"Error: {result['stderr']}"