get_server_metrics
Retrieve detailed server performance metrics, including request counts, success rates, method usage, error categories, and cache statistics, to monitor and optimize Scrapy MCP Server operations.
Instructions
Get server performance metrics and statistics.
Returns information about:
Request counts and success rates
Performance metrics
Method usage statistics
Error categories
Cache statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- extractor/server.py:1092-1139 (handler)The core handler function for the 'get_server_metrics' MCP tool. Decorated with @app.tool() for automatic registration. Fetches metrics from global collectors (metrics_collector.get_stats() and cache_manager.stats()), constructs a MetricsResponse Pydantic model, and returns server performance statistics including request counts, success rates, response times, uptime, cache stats, method usage, and error categories. Includes exception handling for robustness.async def get_server_metrics() -> MetricsResponse: """ Get server performance metrics and statistics. Args: 无需参数,返回服务器性能指标和统计信息 Returns information about: - Request counts and success rates - Performance metrics - Method usage statistics - Error categories - Cache statistics - Server configuration details Returns: MetricsResponse object containing detailed server metrics including scraping performance, cache statistics, server configuration, and real-time statistics. """ try: metrics = metrics_collector.get_stats() cache_stats = cache_manager.stats() return MetricsResponse( success=True, total_requests=metrics.get("total_requests", 0), successful_requests=metrics.get("successful_requests", 0), failed_requests=metrics.get("failed_requests", 0), success_rate=metrics.get("success_rate", 0.0), average_response_time=metrics.get("average_response_time", 0.0), uptime_seconds=metrics.get("uptime_seconds", 0.0), cache_stats=cache_stats, method_usage=metrics.get("method_usage", {}), error_categories=metrics.get("error_categories", {}), ) except Exception: return MetricsResponse( success=False, total_requests=0, successful_requests=0, failed_requests=0, success_rate=0.0, average_response_time=0.0, uptime_seconds=0.0, cache_stats={}, method_usage={}, error_categories={}, )
- extractor/server.py:201-214 (schema)Pydantic BaseModel defining the response schema for get_server_metrics tool. Specifies fields for success status, request statistics (total/successful/failed counts and rates), performance metrics (avg response time, uptime), and breakdowns (cache stats, method usage, error categories). Used for input/output validation in the FastMCP framework.class MetricsResponse(BaseModel): """Response model for server metrics.""" success: bool = Field(..., description="操作是否成功") total_requests: int = Field(..., description="总请求数") successful_requests: int = Field(..., description="成功请求数") failed_requests: int = Field(..., description="失败请求数") success_rate: float = Field(..., description="成功率") average_response_time: float = Field(..., description="平均响应时间(秒)") uptime_seconds: float = Field(..., description="运行时间(秒)") cache_stats: Dict[str, Any] = Field(..., description="缓存统计") method_usage: Dict[str, int] = Field(..., description="方法使用统计") error_categories: Dict[str, int] = Field(..., description="错误分类统计")