query_prometheus
Execute PromQL instant queries to retrieve metric values at specific times from Prometheus for monitoring and troubleshooting.
Instructions
Execute raw PromQL instant query against Prometheus. Returns metric values at a specific point in time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | PromQL query string (e.g., 'up{job="api-server"}' or 'rate(http_requests_total[5m])') | |
| time | No | Optional evaluation timestamp. Can be: 'now', relative like '5m', RFC3339, or Unix timestamp |
Implementation Reference
- src/tools/prometheus_tools.py:15-52 (handler)The handler function `query_prometheus` implementation which takes a client, a PromQL query, and an optional time argument to execute an instant query against Prometheus.
async def query_prometheus( client: PrometheusClient, query: str, time: Optional[str] = None ) -> Dict[str, Any]: """ Execute raw PromQL instant query. Args: client: Prometheus client query: PromQL query string time: Optional evaluation timestamp Returns: Query results """ try: # Parse time if provided time_value = None if time: parsed_time = parse_time(time) if parsed_time: time_value = to_prometheus_time(parsed_time) result = await client.query(query, time_value) return { "success": True, "query": query, "result": result } except Exception as e: logger.error(f"Error executing Prometheus query: {e}") return { "success": False, "error": str(e), "query": query }