list_metrics
Discover available Prometheus metrics to identify what data is being collected for monitoring and troubleshooting purposes.
Instructions
List all available metrics in Prometheus. Useful for discovering what metrics are being collected.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prefix | No | Optional prefix to filter metrics (e.g., 'http_', 'cpu_') |
Implementation Reference
- src/tools/prometheus_tools.py:100-140 (handler)The implementation of the `list_metrics` tool handler.
async def list_metrics( client: PrometheusClient, prefix: Optional[str] = None ) -> Dict[str, Any]: """ List all available metrics in Prometheus. Args: client: Prometheus client prefix: Optional prefix to filter metrics Returns: List of metric names """ try: # Query __name__ label to get all metrics result = await client.label_values("__name__") if result.get("status") == "success": metrics = result.get("data", []) # Filter by prefix if provided if prefix: metrics = [m for m in metrics if m.startswith(prefix)] return { "success": True, "count": len(metrics), "metrics": metrics[:1000] # Limit to prevent huge responses } else: return { "success": False, "error": "Failed to fetch metrics" } except Exception as e: logger.error(f"Error listing metrics: {e}") return { "success": False, "error": str(e) }