系统管理工具类
| 14 | |
| 15 | |
| 16 | class SystemManagementTools: |
| 17 | """系统管理工具类""" |
| 18 | |
| 19 | def __init__(self, project_root: str = None): |
| 20 | """ |
| 21 | 初始化系统管理工具 |
| 22 | |
| 23 | Args: |
| 24 | project_root: 项目根目录 |
| 25 | """ |
| 26 | self.data_service = DataService(project_root) |
| 27 | if project_root: |
| 28 | self.project_root = Path(project_root) |
| 29 | else: |
| 30 | # 获取项目根目录 |
| 31 | current_file = Path(__file__) |
| 32 | self.project_root = current_file.parent.parent.parent |
| 33 | |
| 34 | def get_system_status(self) -> Dict: |
| 35 | """ |
| 36 | 获取系统运行状态和健康检查信息 |
| 37 | |
| 38 | Returns: |
| 39 | 系统状态字典 |
| 40 | |
| 41 | Example: |
| 42 | >>> tools = SystemManagementTools() |
| 43 | >>> result = tools.get_system_status() |
| 44 | >>> print(result['system']['version']) |
| 45 | """ |
| 46 | try: |
| 47 | # 获取系统状态 |
| 48 | status = self.data_service.get_system_status() |
| 49 | |
| 50 | return { |
| 51 | "success": True, |
| 52 | "summary": { |
| 53 | "description": "系统运行状态和健康检查信息" |
| 54 | }, |
| 55 | "data": status |
| 56 | } |
| 57 | |
| 58 | except MCPError as e: |
| 59 | return { |
| 60 | "success": False, |
| 61 | "error": e.to_dict() |
| 62 | } |
| 63 | except Exception as e: |
| 64 | return { |
| 65 | "success": False, |
| 66 | "error": { |
| 67 | "code": "INTERNAL_ERROR", |
| 68 | "message": str(e) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | def _load_crawl_config(self): |
| 73 | """加载爬取配置,返回 (config_data, target_platforms_config)""" |