query_container_stats
Retrieve time-series statistics for container CPU, memory, and network usage by specifying container ID and optional time range parameters.
Instructions
Query statistics for a specific container.
Args: container_id: The container ID to query statistics for start_time: Start time in ISO 8601 format (e.g., '2024-01-01T00:00:00Z') end_time: End time in ISO 8601 format page: Page number (default: 1) per_page: Number of results per page (default: 100)
Returns: Dictionary containing time-series data for container CPU, memory, and network usage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container_id | Yes | ||
| start_time | No | ||
| end_time | No | ||
| page | No | ||
| per_page | No |
Implementation Reference
- src/beszel_mcp/server.py:198-234 (handler)The @mcp.tool()-decorated handler function implementing the query_container_stats tool. It processes input parameters for container ID and optional time range/pagination, authenticates the PocketBase client, builds PocketBase filters, and queries the 'container_stats' collection for time-series data on CPU, memory, and network usage.@mcp.tool() async def query_container_stats( container_id: str, start_time: Optional[str] = None, end_time: Optional[str] = None, page: int = 1, per_page: int = 100, ) -> dict: """Query statistics for a specific container. Args: container_id: The container ID to query statistics for start_time: Start time in ISO 8601 format (e.g., '2024-01-01T00:00:00Z') end_time: End time in ISO 8601 format page: Page number (default: 1) per_page: Number of results per page (default: 100) Returns: Dictionary containing time-series data for container CPU, memory, and network usage """ client = get_client() await ensure_authenticated(client) # Build filter for container and time range filters = [f"container = '{container_id}'"] time_filter = client.build_time_filter("created", start_time, end_time) if time_filter: filters.append(time_filter) return await client.query_stats( collection="container_stats", filter=" && ".join(filters), page=page, per_page=per_page, sort="-created", )