self diagnostic

解决联想一体机selfdiagnostic问题的方法
本文提供了解决联想一体机selfdiagnostic问题的步骤:检查定影是否粘在一起,关闭电源并进行特定操作以解决问题。若方法无效,则建议送至维修站。
部署运行你感兴趣的模型镜像
怎么处理
碰到这种self diagnostic问题的解决方法就是

1,检查定影是否粘在一起了


2,关闭联想一体机电源
[color=blue]按住功能键不松手同时打开联想一体机电源
开机后松掉功能键并按上下键直到屏幕上显示99
按确认键并等待联想一体机完成预热 [/color]OK,现在 self diagnostic的问题就已经解决了,如果这个方法无法解决的话那么请直接送维修站吧,这个时候不是专业人员是没办法解决的了。

定影的热敏电阻坏了也是这种想象,,总之是定影当面的问题。。

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

storcli64 /c0 show CLI Version = 007.1410.0000.0000 May 19, 2020 Operating system = Linux 4.18.0-372.9.1.el8.x86_64 Controller = 0 Status = Success Description = None Product Name = SAS9311-8i Serial Number = 500605b00915f745 SAS Address = 500605b00915f745 PCI Address = 00:41:00:00 System Time = 10/09/2025 04:02:20 FW Package Build = 00.00.00.00 FW Version = 16.00.16.00 BIOS Version = 08.37.00.00_18.00.00.00 NVDATA Version = 14.01.00.12 Driver Name = mpt3sas Driver Version = 39.100.00.00 Bus Number = 65 Device Number = 0 Function Number = 0 Domain ID = 0 Vendor Id = 0x1000 Device Id = 0x97 SubVendor Id = 0x1000 SubDevice Id = 0x3090 Board Name = SAS9311-8i Board Assembly = H3-25573-00G Board Tracer Number = XW641268BD Security Protocol = None Physical Drives = 3 PD LIST : ======= ----------------------------------------------------------------------------------- EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp ----------------------------------------------------------------------------------- :0 1 UGood - 893.137 GB SATA SSD N N 512B SAMSUNG MZ7LH960HAJR-00005 U :1 2 - - 3.637 TB SATA HDD N N 512B ST4000NM000A-2HZ100 U :2 0 - - 3.637 TB SATA HDD N N 512B ST4000NM000A-2HZ100 U ----------------------------------------------------------------------------------- EID-Enclosure Device ID|Slt-Slot No.|DID-Device ID|DG-DriveGroup UGood-Unconfigured Good|UBad-Unconfigured Bad|Intf-Interface Med-Media Type|SED-Self Encryptive Drive|PI-Protection Info SeSz-Sector Size|Sp-Spun|U-Up|D-Down|T-Transition Requested Boot Drive = Not Set [root@localhost storcli]# storcli64 /c0 show all CLI Version = 007.1410.0000.0000 May 19, 2020 Operating system = Linux 4.18.0-372.9.1.el8.x86_64 Controller = 0 Status = Success Description = None Basics : ====== Controller = 0 Adapter Type = SAS3008(C0) Model = SAS9311-8i Serial Number = 500605b00915f745 Current System Date/time = 10/09/2025 04:02:32 Concurrent commands supported = 4096 SAS Address = 500605b00915f745 PCI Address = 00:41:00:00 Mfg Date = 00/00/00 Rework Date = 00/00/00 Revision No = N/A Version : ======= Firmware Package Build = 00.00.00.00 Firmware Version = 16.00.16.00 Bios Version = 08.37.00.00_18.00.00.00 NVDATA Version = 14.01.00.12 Driver Name = mpt3sas Driver Version = 39.100.00.00 PCI Version : =========== Vendor Id = 0x1000 Device Id = 0x97 SubVendor Id = 0x1000 SubDevice Id = 0x3090 Host Interface = PCIE Device Interface = SAS-12G Bus Number = 65 Device Number = 0 Function Number = 0 Domain ID = 0 Pending Images in Flash : ======================= Image name = No pending images Status : ====== Controller Status = OK Memory Correctable Errors = 0 Memory Uncorrectable Errors = 0 Bios was not detected during boot = No Controller has booted into safe mode = No Controller has booted into certificate provision mode = No Supported Adapter Operations : ============================ Alarm Control = No Cluster Support = No Self Diagnostic = No Deny SCSI Passthrough = No Deny SMP Passthrough = No Deny STP Passthrough = No Support more than 8 Phys = No FW and Event Time in GMT = No Support Enclosure Enumeration = Yes Support Allowed Operations = Yes Support Multipath = Yes Support Security = No Support Config Page Model = No Support the OCE without adding drives = Yes support EKM = No Snapshot Enabled = No Support PFK = No Support PI = No Support Shield State = No Support Set Link Speed = No Support JBOD = No Disable Online PFK Change = No Real Time Scheduler = No Support Reset Now = No Support Emulated Drives = No Support Secure Boot = No Support Platform Security = No HwCfg : ===== ChipRevision = C0 BatteryFRU = N/A Front End Port Count = 1 Backend Port Count = 8 Serial Debugger = Absent NVRAM Size = 0KB Flash Size = 16MB On Board Memory Size = 0MB On Board Expander = Absent Temperature Sensor for ROC = Present Temperature Sensor for Controller = Absent Current Size of CacheCade (GB) = 0 Current Size of FW Cache (MB) = 0 ROC temperature(Degree Celcius) = 61 Policies : ======== Policies Table : ============== ------------------------------------------------ Policy Current Default ------------------------------------------------ Predictive Fail Poll Interval 0 sec Interrupt Throttle Active Count 0 Interrupt Throttle Completion 0 us Rebuild Rate 128 % 30% PR Rate 0 % 30% BGI Rate 128 % 30% Check Consistency Rate 128 % 30% Reconstruction Rate 0 % 30% Cache Flush Interval 0s ------------------------------------------------ Flush Time(Default) = 4s Drive Coercion Mode = none Auto Rebuild = On Battery Warning = Off ECC Bucket Size = 0 ECC Bucket Leak Rate (hrs) = 0 Restore HotSpare on Insertion = Off Expose Enclosure Devices = Off Maintain PD Fail History = Off Reorder Host Requests = On Auto detect BackPlane = SGPIO/i2c SEP Load Balance Mode = None Security Key Assigned = Off Disable Online Controller Reset = Off Use drive activity for locate = Off Boot : ==== Max Drives to Spinup at One Time = 0 Maximum number of direct attached drives to spin up in 1 min = 0 Delay Among Spinup Groups (sec) = 0 Allow Boot with Preserved Cache = On Defaults : ======== Phy Polarity = 0 Phy PolaritySplit = 0 Cached IO = Off Default spin down time (mins) = 0 Coercion Mode = None ZCR Config = Unknown Max Chained Enclosures = 0 Direct PD Mapping = No Restore Hot Spare on Insertion = No Expose Enclosure Devices = No Maintain PD Fail History = No Zero Based Enclosure Enumeration = No Disable Puncturing = No Un-Certified Hard Disk Drives = Block SMART Mode = Mode 6 Enable LED Header = No LED Show Drive Activity = No Dirty LED Shows Drive Activity = No EnableCrashDump = No Disable Online Controller Reset = No Treat Single span R1E as R10 = No Power Saving option = Enable TTY Log In Flash = No Auto Enhanced Import = No Enable Shield State = No Time taken to detect CME = 60 sec Capabilities : ============ Supported Drives = SAS, SATA Enable JBOD = Not Allowed Max Parallel Commands = 4096 Max SGE Count = 128 Max Data Transfer Size = 32 sectors Max Strips PerIO = 0 Max Configurable CacheCade Size = 0 Min Strip Size = 64 KB Max Strip Size = 64 KB Scheduled Tasks = NA Security Protocol properties : ============================ Security Protocol = None Physical Device Information : =========================== Drive /c0/s0 : ============ ----------------------------------------------------------------------------------- EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp ----------------------------------------------------------------------------------- :0 1 UGood - 893.137 GB SATA SSD N N 512B SAMSUNG MZ7LH960HAJR-00005 U ----------------------------------------------------------------------------------- EID-Enclosure Device ID|Slt-Slot No.|DID-Device ID|DG-DriveGroup UGood-Unconfigured Good|UBad-Unconfigured Bad|Intf-Interface Med-Media Type|SED-Self Encryptive Drive|PI-Protection Info SeSz-Sector Size|Sp-Spun|U-Up|D-Down|T-Transition Drive /c0/s0 - Detailed Information : =================================== Drive /c0/s0 State : ================== Shield Counter = 0 Media Error Count = 0 Other Error Count = 0 Predictive Failure Count = 0 S.M.A.R.T alert flagged by drive = No Drive /c0/s0 Device attributes : ============================== Manufacturer Id = ATA Model Number = SAMSUNG MZ7LH960HAJR-00005 NAND Vendor = NA SN = S45NNA0T801190 WWN = 5002538E02800BE6 Firmware Revision = 904Q Raw size = 894.252 GB [0x6fc81aaf Sectors] Coerced size = 893.137 GB [0x6fa46800 Sectors] Non Coerced size = 893.752 GB [0x6fb81aaf Sectors] Device Speed = Unknown Link Speed = 6.0Gb/s NCQ setting = N/A Sector Size = 512B Config ID = NA Number of Blocks = 1875385007 Connector Name = N/A Drive /c0/s0 Policies/Settings : ============================== Enclosure position = 0 Connected Port Number = 2 Sequence Number = 0 Commissioned Spare = No Emergency Spare = No Last Predictive Failure Event Sequence Number = 0 Successful diagnostics completion on = N/A SED Capable = No SED Enabled = No Secured = No Needs EKM Attention = No PI Eligible = No Certified = Yes Wide Port Capable = No Multipath = No Port Information : ================ ----------------------------------------- Port Status Linkspeed SAS address ----------------------------------------- 0 Active 6.0Gb/s 0x4433221102000000 ----------------------------------------- Inquiry Data = 40 00 ff 3f 37 c8 10 00 00 00 00 00 3f 00 00 00 00 00 00 00 34 53 4e 35 41 4e 54 30 30 38 31 31 30 39 20 20 20 20 20 20 00 00 00 00 00 00 58 48 37 54 30 39 51 34 41 53 53 4d 4e 55 20 47 5a 4d 4c 37 39 48 30 36 41 48 52 4a 30 2d 30 30 35 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 80 00 40 00 2f 00 40 00 02 00 02 07 00 ff 3f 10 00 3f 00 10 fc fb 00 10 bd ff ff ff 0f 00 00 07 00 Drive /c0/s1 : ============ -------------------------------------------------------------------------- EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp -------------------------------------------------------------------------- :1 2 - - 3.637 TB SATA HDD N N 512B ST4000NM000A-2HZ100 U -------------------------------------------------------------------------- EID-Enclosure Device ID|Slt-Slot No.|DID-Device ID|DG-DriveGroup UGood-Unconfigured Good|UBad-Unconfigured Bad|Intf-Interface Med-Media Type|SED-Self Encryptive Drive|PI-Protection Info SeSz-Sector Size|Sp-Spun|U-Up|D-Down|T-Transition Drive /c0/s1 - Detailed Information : =================================== Drive /c0/s1 State : ================== Shield Counter = 0 Media Error Count = 0 Other Error Count = 0 Predictive Failure Count = 0 S.M.A.R.T alert flagged by drive = No Drive /c0/s1 Device attributes : ============================== Manufacturer Id = ATA Model Number = ST4000NM000A-2HZ100 NAND Vendor = NA SN = WS244KWV WWN = 5000C500EDA5C92C Firmware Revision = TN02 Raw size = 3.638 TB [0x1d1c0beaf Sectors] Coerced size = 3.637 TB [0x1d1a94800 Sectors] Non Coerced size = 3.637 TB [0x1d1b0beaf Sectors] Device Speed = Unknown Link Speed = 6.0Gb/s NCQ setting = N/A Sector Size = 512B Config ID = NA Number of Blocks = 7814037167 Connector Name = N/A Drive /c0/s1 Policies/Settings : ============================== Enclosure position = 0 Connected Port Number = 3 Sequence Number = 0 Commissioned Spare = No Emergency Spare = No Last Predictive Failure Event Sequence Number = 0 Successful diagnostics completion on = N/A SED Capable = No SED Enabled = No Secured = No Needs EKM Attention = No PI Eligible = No Certified = Yes Wide Port Capable = No Multipath = No Port Information : ================ ----------------------------------------- Port Status Linkspeed SAS address ----------------------------------------- 0 Active 6.0Gb/s 0x4433221103000000 ----------------------------------------- Inquiry Data = 5a 0c ff 3f 37 c8 10 00 00 00 00 00 3f 00 00 00 00 00 00 00 20 20 20 20 20 20 20 20 20 20 20 20 53 57 34 32 4b 34 56 57 00 00 00 00 00 00 4e 54 32 30 20 20 20 20 54 53 30 34 30 30 4d 4e 30 30 41 30 32 2d 5a 48 30 31 20 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 80 00 40 00 2f 00 40 00 02 00 02 07 00 ff 3f 10 00 3f 00 10 fc fb 00 10 5d ff ff ff 0f 00 00 07 00 Drive /c0/s2 : ============ -------------------------------------------------------------------------- EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp -------------------------------------------------------------------------- :2 0 - - 3.637 TB SATA HDD N N 512B ST4000NM000A-2HZ100 U -------------------------------------------------------------------------- EID-Enclosure Device ID|Slt-Slot No.|DID-Device ID|DG-DriveGroup UGood-Unconfigured Good|UBad-Unconfigured Bad|Intf-Interface Med-Media Type|SED-Self Encryptive Drive|PI-Protection Info SeSz-Sector Size|Sp-Spun|U-Up|D-Down|T-Transition Drive /c0/s2 - Detailed Information : =================================== Drive /c0/s2 State : ================== Shield Counter = 0 Media Error Count = 0 Other Error Count = 0 Predictive Failure Count = 0 S.M.A.R.T alert flagged by drive = No Drive /c0/s2 Device attributes : ============================== Manufacturer Id = ATA Model Number = ST4000NM000A-2HZ100 NAND Vendor = NA SN = WS244H3Y WWN = 5000C500EDA54BED Firmware Revision = TN02 Raw size = 3.638 TB [0x1d1c0beaf Sectors] Coerced size = 3.637 TB [0x1d1a94800 Sectors] Non Coerced size = 3.637 TB [0x1d1b0beaf Sectors] Device Speed = Unknown Link Speed = 6.0Gb/s NCQ setting = N/A Sector Size = 512B Config ID = NA Number of Blocks = 7814037167 Connector Name = N/A Drive /c0/s2 Policies/Settings : ============================== Enclosure position = 0 Connected Port Number = 1 Sequence Number = 0 Commissioned Spare = No Emergency Spare = No Last Predictive Failure Event Sequence Number = 0 Successful diagnostics completion on = N/A SED Capable = No SED Enabled = No Secured = No Needs EKM Attention = No PI Eligible = No Certified = Yes Wide Port Capable = No Multipath = No Port Information : ================ ----------------------------------------- Port Status Linkspeed SAS address ----------------------------------------- 0 Active 6.0Gb/s 0x4433221101000000 ----------------------------------------- Inquiry Data = 5a 0c ff 3f 37 c8 10 00 00 00 00 00 3f 00 00 00 00 00 00 00 20 20 20 20 20 20 20 20 20 20 20 20 53 57 34 32 48 34 59 33 00 00 00 00 00 00 4e 54 32 30 20 20 20 20 54 53 30 34 30 30 4d 4e 30 30 41 30 32 2d 5a 48 30 31 20 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 80 00 40 00 2f 00 40 00 02 00 02 07 00 ff 3f 10 00 3f 00 10 fc fb 00 10 5d ff ff ff 0f 00 00 07 00 [root@localhost storcli]# 这里面可以看出是系统盘吗?盘符组的什么系统
10-10
1.#E:\AI_System\agent\diagnostic_system.py import logging import psutil import time import random import traceback from typing import Optional, Any, Dict, Union from agent.base_module import UnifiedCognitiveModule class DiagnosticSystem(UnifiedCognitiveModule): """系统诊断模块 - 增强安全版(支持协调器安全连接)""" def __init__( self, name: str = "DiagnosticSystem", coordinator: Optional[Any] = None, config: Optional[Dict] = None ): """ 诊断系统初始化 :param name: 系统名称 :param coordinator: 协调器实例 :param config: 配置字典 """ super().__init__(name=name, coordinator=coordinator, config=config) # 配置参数处理 config = config or {} self.log_level = config.get("log_level", "INFO") self.diagnostic_interval = config.get("diagnostic_interval", 30) # 默认30秒 # 日志配置 - 确保使用字符串名称 self.logger = logging.getLogger("DiagnosticSystem") log_level = getattr(logging, self.log_level.upper(), logging.INFO) self.logger.setLevel(log_level) # 初始化计数器 self.diagnostic_count = 0 self.last_diagnostic_time = time.time() # 星型架构协调器引用 self.orchestrator = None self.logger.info(f"🔧 初始化诊断系统: {name}") def set_orchestrator(self, orchestrator_info: Union[dict, Any]): """ 安全设置协调器引用 :param orchestrator_info: 协调器信息(字典)或协调器实例 """ try: # 统一处理两种参数类型 if isinstance(orchestrator_info, dict): self.orchestrator = orchestrator_info.get("instance") orchestrator_name = orchestrator_info.get("name", "UnknownOrchestrator") else: self.orchestrator = orchestrator_info orchestrator_name = getattr(orchestrator_info, "name", "UnknownOrchestrator") self.logger.info(f"🔗 连接到星型协调器: {orchestrator_name}") except Exception as e: self.logger.error(f"❌ 设置协调器失败: {str(e)}", exc_info=True) def shutdown(self) -> bool: """ 关闭诊断系统 :return: 是否成功关闭 """ try: self.logger.info("🛑 正在关闭诊断系统...") # 执行必要的清理操作 self.disconnect() self.logger.info("✅ 诊断系统已安全关闭") return True except Exception as e: self.logger.error(f"❌ 关闭失败: {str(e)}") return False # ============ 抽象方法实现 ============ def process(self, input_data: Any) -> Dict: """ 处理输入数据 - 实现抽象方法 :param input_data: 输入数据 :return: 处理结果字典 """ try: self.logger.info(f"🔍 处理诊断输入: {input_data}") self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 执行诊断检查 diagnostic_results = self.check_modules() return { "status": "success", "message": f"诊断系统 '{self.name}' 完成处理", "input": input_data, "results": diagnostic_results, "timestamp": time.time() } except Exception as e: self.logger.error(f"❌ 处理输入失败: {str(e)}") return { "status": "error", "error": str(e), "traceback": traceback.format_exc() } def process_command(self, command: str) -> Dict: """ 处理命令 - 实现抽象方法 :param command: 命令字符串 :return: 处理结果字典 """ try: self.logger.info(f"⚙️ 处理诊断命令: {command}") self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 命令处理逻辑 if command == "full_diagnostic": results = self.check_modules() return { "status": "success", "command": command, "results": results } elif command == "resource_check": return { "status": "success", "command": command, "resources": self._check_resources() } elif command == "health_check": return { "status": "success", "command": command, "health_status": self.is_healthy() } elif command == "system_status": # 获取协调器状态(如果可用) if self.orchestrator and hasattr(self.orchestrator, "get_system_status"): status = self.orchestrator.get_system_status() else: status = {"error": "协调器不可用"} return { "status": "success", "command": command, "system_status": status } else: return { "status": "error", "command": command, "message": "未知命令", "valid_commands": ["full_diagnostic", "resource_check", "health_check", "system_status"] } except Exception as e: self.logger.error(f"❌ 处理命令失败: {str(e)}") return { "status": "error", "command": command, "error": str(e) } def connect(self) -> bool: """ 连接环境 - 实现抽象方法 :return: 连接是否成功 """ self.logger.info("🔌 正在连接诊断系统环境...") try: # 初始化资源监控 psutil.cpu_percent(interval=None) # 初始化CPU监控 # 尝试初始化GPU监控 try: import gpustat gpustat.new_query() self.logger.info("✅ GPU监控已初始化") except ImportError: self.logger.warning("⚠️ gpustat未安装,GPU监控不可用") except Exception: self.logger.exception("❌ GPU监控初始化失败") self.logger.info("✅ 诊断系统连接成功") return True except Exception as e: self.logger.error(f"❌ 连接失败: {str(e)}") return False def disconnect(self) -> None: """ 断开连接 - 实现抽象方法 """ try: self.logger.info("🔌 正在断开诊断系统连接...") # 清理资源 if hasattr(self, '_gpu_monitor'): del self._gpu_monitor self.logger.info("✅ 诊断系统已安全断开") except Exception as e: self.logger.error(f"断开连接时出错: {str(e)}") # ============ 诊断系统特定功能 ============ def is_healthy(self) -> bool: """ 健康检查:系统资源是否在正常范围内 :return: 健康状态 """ try: cpu_usage = psutil.cpu_percent(interval=1) mem_usage = psutil.virtual_memory().percent # 详细记录 self.logger.debug(f"CPU使用率: {cpu_usage}%, 内存使用率: {mem_usage}%") # 阈值判断 healthy = cpu_usage < 90 and mem_usage < 85 status = "健康 ✅" if healthy else "警告 ⚠️" self.logger.info(f"系统健康检查: {status} (CPU: {cpu_usage}%, 内存: {mem_usage}%)") return healthy except Exception as e: self.logger.error(f"健康检查失败: {e}", exc_info=True) return False def get_status(self) -> dict: """ 返回诊断系统自身的状态 :return: 状态字典 """ try: return { "name": self.name, "status": "运行中", "last_check": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.last_diagnostic_time)), "diagnostic_count": self.diagnostic_count, "system_load": f"{psutil.cpu_percent()}% CPU, {psutil.virtual_memory().percent}% RAM", "orchestrator": getattr(self.orchestrator, "name", "未连接") if self.orchestrator else "未连接" } except Exception as e: self.logger.error(f"获取状态失败: {str(e)}") return {"error": str(e)} def check_modules(self) -> Dict[str, dict]: """ 检查核心模块状态 :return: 各模块状态字典 """ try: results = { "diagnostic_system": self.get_status(), "system_resources": self._check_resources() } # 如果连接到协调器,检查其他模块 if self.orchestrator: try: results["cognitive_system"] = self._check_cognitive() results["environment_interface"] = self._check_environment() results["affective_system"] = self._check_affective() # 获取协调器管理的模块状态 if hasattr(self.orchestrator, "get_modules"): modules = self.orchestrator.get_modules() for name, module in modules.items(): if module and hasattr(module, "get_status"): results[f"{name}_module"] = module.get_status() except Exception as e: self.logger.error(f"协调器模块检查失败: {str(e)}") results["coordinator_error"] = str(e) # 更新状态计数器 self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 记录结果 self.logger.info("✅ 完成诊断检查") return results except Exception as e: self.logger.exception("❌ 模块诊断失败") return {"error": str(e)} def run_periodic_diagnostics(self): """运行周期性诊断检查""" while self.active: try: self.logger.info("🔄 运行周期性诊断检查...") results = self.check_modules() self.logger.debug(f"诊断结果: {results}") # 发送结果到协调器 if self.orchestrator and hasattr(self.orchestrator, "report_diagnostic"): self.orchestrator.report_diagnostic(results) except Exception as e: self.logger.error(f"❌ 周期性诊断失败: {str(e)}") time.sleep(self.diagnostic_interval) def _check_cognitive(self) -> dict: """ 检查认知系统模块 :return: 状态字典 """ try: # 尝试访问协调器的认知模块 if self.orchestrator and hasattr(self.orchestrator, "get_module"): cognitive = self.orchestrator.get_module("cognitive") if cognitive: return { "status": "✅ 已连接", "version": getattr(cognitive, "version", "未知"), "last_activity": getattr(cognitive, "last_activity", "未知") } # 回退到模拟数据 return { "status": "⚠️ 未连接", "version": "1.2.5", "last_heartbeat": time.time() - random.randint(1, 10) } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_environment(self) -> dict: """ 检查环境接口模块 :return: 状态字典 """ try: # 尝试访问协调器的环境模块 if self.orchestrator and hasattr(self.orchestrator, "get_module"): env = self.orchestrator.get_module("environment") if env: return { "status": "✅ 已连接", "sensors": getattr(env, "sensors", []), "last_update": getattr(env, "last_update", "未知") } # 回退到模拟数据 return { "status": "⚠️ 未连接", "connection": "inactive", "last_ping": time.time() - random.randint(1, 5) } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_affective(self) -> dict: """ 检查情感系统模块 :return: 状态字典 """ try: # 尝试访问协调器的情感模块 if self.orchestrator and hasattr(self.orchestrator, "get_module"): affective = self.orchestrator.get_module("affective") if affective: return { "status": "✅ 已连接", "state": affective.get_state() if hasattr(affective, "get_state") else "未知" } # 回退到模拟数据 emotions = ["neutral", "happy", "sad", "angry", "excited"] return { "status": "⚠️ 未连接", "emotion_state": random.choice(emotions), "intensity": random.randint(1, 100) } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_resources(self) -> dict: """ 检查系统资源使用情况 :return: 资源状态字典 """ try: return { "cpu": self._get_cpu_status(), "memory": self._get_memory_status(), "gpu": self._get_gpu_status(), "disk": self._get_disk_usage() } except Exception as e: return {"error": f"资源检查失败: {str(e)}"} def _get_cpu_status(self) -> dict: """获取CPU状态""" try: return { "usage": f"{psutil.cpu_percent(interval=1)}%", "cores": psutil.cpu_count(logical=False), "threads": psutil.cpu_count(logical=True), "freq": f"{psutil.cpu_freq().current:.2f} MHz" } except Exception as e: return {"error": f"CPU检测失败: {str(e)}"} def _get_memory_status(self) -> dict: """获取内存状态""" try: mem = psutil.virtual_memory() return { "total": f"{mem.total // (1024 ** 3)} GB", "used": f"{mem.used // (1024 ** 3)} GB", "free": f"{mem.free // (1024 ** 3)} GB", "percent": f"{mem.percent}%" } except Exception as e: return {"error": f"内存检测失败: {str(e)}"} def _get_gpu_status(self) -> Any: """ 获取GPU状态 :return: GPU状态信息 """ try: import gpustat stats = gpustat.new_query() return [ { "id": gpu.index, "name": gpu.name, "utilization": f"{gpu.utilization}%", "memory": f"{gpu.memory_used}/{gpu.memory_total} MB", "temperature": f"{gpu.temperature}°C", "power": f"{gpu.power_draw}W" } for gpu in stats.gpus ] except ImportError: return {"warning": "gpustat 未安装"} except Exception as e: return {"error": f"GPU检测失败: {str(e)}"} def _get_disk_usage(self) -> Dict[str, Any]: """ 获取磁盘使用情况 :return: 磁盘状态字典 """ try: partitions = [] for partition in psutil.disk_partitions(): try: usage = psutil.disk_usage(partition.mountpoint) partitions.append({ "device": partition.device, "mountpoint": partition.mountpoint, "fstype": partition.fstype, "total": f"{usage.total // (1024 ** 3)} GB", "used": f"{usage.used // (1024 ** 3)} GB", "free": f"{usage.free // (1024 ** 3)} GB", "percent": f"{usage.percent}%" }) except Exception as e: partitions.append({ "device": partition.device, "error": str(e) }) return partitions except Exception as e: return {"error": f"磁盘检测失败: {str(e)}"} 2.# diagnostic_system.py class DiagnosticSystem: # ... 现有代码 ... def model_health_check(self, model_manager): """检查模型健康状况""" results = {} for name, model in model_manager.loaded_models.items(): try: # 测试模型是否响应 if hasattr(model, 'generate'): test_input = torch.tensor([[0]]) # 简单测试输入 model.generate(test_input) results[name] = "healthy" else: results[name] = "no_generate_method" except Exception as e: results[name] = f"error: {str(e)}" return results
09-01
1.# E:\AI_System\agent\diagnostic_system.py import logging import psutil import time import random from typing import Optional, Any, Dict from agent.base_module import UnifiedCognitiveModule class DiagnosticSystem(UnifiedCognitiveModule): def __init__( self, name: str = "DiagnosticSystem", coordinator: Optional[Any] = None, config: Optional[Dict] = None ): """ 诊断系统初始化 :param name: 系统名称 :param coordinator: 协调器实例 :param config: 配置字典 """ super().__init__(name=name, coordinator=coordinator, config=config) # 配置参数处理 config = config or {} self.log_level = config.get("log_level", "INFO") # 日志配置 - 确保使用字符串名称 self.logger = logging.getLogger("DiagnosticSystem") log_level = getattr(logging, self.log_level.upper(), logging.INFO) self.logger.setLevel(log_level) # 初始化计数器 self.diagnostic_count = 0 self.last_diagnostic_time = time.time() # 星型架构协调器引用 self.orchestrator = None self.logger.info(f"🔗 初始化诊断系统: {name}") def shutdown(self) -> bool: """ 关闭诊断系统 :return: 是否成功关闭 """ try: self.logger.info("🛑 关闭诊断系统...") # 执行任何必要的清理操作 return True except Exception as e: self.logger.error(f"❌ 关闭失败: {str(e)}") return False # ============ 抽象方法实现 ============ def process(self, input_data: Any) -> Dict: """ 处理输入数据 - 实现抽象方法 :param input_data: 输入数据 :return: 处理结果字典 """ self.logger.info(f"处理诊断输入: {input_data}") self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 执行诊断检查 diagnostic_results = self.check_modules() return { "status": "success", "message": f"诊断系统 '{self.name}' 完成处理", "input": input_data, "results": diagnostic_results, "timestamp": time.time() } def process_command(self, command: str) -> Dict: """ 处理命令 - 实现抽象方法 :param command: 命令字符串 :return: 处理结果字典 """ self.logger.info(f"处理诊断命令: {command}") self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 命令处理逻辑 if command == "full_diagnostic": results = self.check_modules() return { "status": "success", "command": command, "results": results } elif command == "resource_check": return { "status": "success", "command": command, "resources": self._check_resources() } elif command == "health_check": return { "status": "success", "command": command, "health_status": self.is_healthy() } else: return { "status": "error", "command": command, "message": "未知命令" } def connect(self) -> bool: """ 连接环境 - 实现抽象方法 :return: 连接是否成功 """ self.logger.info("连接到诊断系统环境...") try: # 模拟连接序列 self.logger.info("🔌 正在初始化诊断接口...") time.sleep(0.1) self.logger.info("📡 连接到系统监控服务...") time.sleep(0.1) self.logger.info("✅ 诊断系统连接成功") return True except Exception as e: self.logger.error(f"❌ 连接失败: {str(e)}") return False def disconnect(self) -> None: """ 断开连接 - 实现抽象方法 """ self.logger.info("断开诊断系统连接...") try: # 模拟断开连接序列 self.logger.info("🔌 正在关闭诊断接口...") time.sleep(0.05) self.logger.info("📡 断开系统监控服务...") time.sleep(0.05) self.logger.info("✅ 诊断系统已安全断开") except Exception as e: self.logger.error(f"断开连接时出错: {str(e)}") # ============ 诊断系统特定功能 ============ def set_orchestrator(self, orchestrator): """ 连接中枢协调器 :param orchestrator: 协调器实例 """ self.orchestrator = orchestrator self.logger.info(f"🔗 连接到星型协调器: {orchestrator.name if orchestrator else None}") def is_healthy(self) -> bool: """ 健康检查:系统资源是否在正常范围内 :return: 健康状态 """ try: cpu_usage = psutil.cpu_percent() mem_usage = psutil.virtual_memory().percent # 详细记录 self.logger.debug(f"CPU使用率: {cpu_usage}%, 内存使用率: {mem_usage}%") # 阈值判断 healthy = cpu_usage < 90 and mem_usage < 85 status = "健康 ✅" if healthy else "警告 ⚠️" self.logger.info(f"系统健康检查: {status} (CPU: {cpu_usage}%, 内存: {mem_usage}%)") return healthy except Exception as e: self.logger.error(f"健康检查失败: {e}") return False def get_status(self) -> dict: """ 返回诊断系统自身的状态 :return: 状态字典 """ return { "status": "运行中", "last_check": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.last_diagnostic_time)), "diagnostic_count": self.diagnostic_count, "system_load": f"{psutil.cpu_percent()}% CPU, {psutil.virtual_memory().percent}% RAM" } def check_modules(self) -> Dict[str, dict]: """ 检查核心模块状态 :return: 各模块状态字典 """ results = { "cognitive_system": self._check_cognitive(), "environment_interface": self._check_environment(), "affective_system": self._check_affective(), "system_resources": self._check_resources() } # 更新状态计数器 self.diagnostic_count += 1 self.last_diagnostic_time = time.time() # 记录结果 self.logger.info("完成模块诊断检查") for module, status in results.items(): self.logger.debug(f"{module}: {status.get('status', '未知状态')}") return results def _check_cognitive(self) -> dict: """ 检查认知系统模块 :return: 状态字典 """ try: # 模拟检查认知系统模块 # from .cognitive_architecture import CognitiveSystem # 实际项目中取消注释 # 模拟一些额外信息 return { "status": "✅ 正常运行", "version": "1.2.5", # CognitiveSystem.VERSION "last_heartbeat": time.time() - random.randint(1, 10), "memory_usage": f"{random.randint(100, 500)}MB" } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_environment(self) -> dict: """ 检查环境接口模块 :return: 状态字典 """ try: # 模拟检查环境接口模块 # from .environment_interface import EnvironmentInterface # 实际项目中取消注释 return { "status": "✅ 正常运行", "connection": "active", "last_ping": time.time() - random.randint(1, 5), "sensors": [f"sensor_{i}" for i in range(1, 4)] } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_affective(self) -> dict: """ 检查情感系统模块 :return: 状态字典 """ try: # 模拟检查情感系统模块 # from .affective_system import AffectiveSystem # 实际项目中取消注释 emotions = ["neutral", "happy", "sad", "angry", "excited"] return { "status": "✅ 正常运行", "emotion_state": random.choice(emotions), "intensity": random.randint(1, 100), "last_update": time.time() - random.randint(1, 60) } except Exception as e: return {"status": "❌ 异常", "error": str(e)} def _check_resources(self) -> dict: """ 检查系统资源使用情况 :return: 资源状态字典 """ try: return { "cpu": { "usage": f"{psutil.cpu_percent()}%", "cores": psutil.cpu_count(logical=False), "threads": psutil.cpu_count(logical=True) }, "memory": { "total": f"{psutil.virtual_memory().total // (1024 ** 3)} GB", "used": f"{psutil.virtual_memory().used // (1024 ** 3)} GB", "percent": f"{psutil.virtual_memory().percent}%" }, "gpu": self._get_gpu_status(), "disk": self._get_disk_usage() } except Exception as e: return {"error": f"资源检查失败: {str(e)}"} def _get_gpu_status(self) -> Any: """ 获取GPU状态 :return: GPU状态信息 """ try: import gpustat stats = gpustat.new_query() return [ { "id": gpu.index, "name": gpu.name, "utilization": f"{gpu.utilization}%", "memory": f"{gpu.memory_used}/{gpu.memory_total} MB", "temperature": f"{gpu.temperature}°C", "power": f"{gpu.power_draw}W" } for gpu in stats.gpus ] except ImportError: return "⚠️ gpustat 未安装" except Exception as e: return f"❌ GPU检测失败: {str(e)}" def _get_disk_usage(self) -> Dict[str, Any]: """ 获取磁盘使用情况 :return: 磁盘状态字典 """ try: partitions = [] for partition in psutil.disk_partitions(): usage = psutil.disk_usage(partition.mountpoint) partitions.append({ "device": partition.device, "mountpoint": partition.mountpoint, "fstype": partition.fstype, "total": f"{usage.total // (1024 ** 3)} GB", "used": f"{usage.used // (1024 ** 3)} GB", "free": f"{usage.free // (1024 ** 3)} GB", "percent": f"{usage.percent}%" }) return partitions except Exception as e: return f"❌ 磁盘检测失败: {str(e)}" 2.class DiagnosticSystem(UnifiedCognitiveModule): def set_orchestrator(self, orchestrator_info: dict): """安全设置协调器引用""" try: self.orchestrator = orchestrator_info.get("instance") # 使用安全访问 orchestrator_name = orchestrator_info.get("name", "UnknownOrchestrator") self.logger.info(f"🔗 连接到星型协调器: {orchestrator_name}") except Exception as e: self.logger.error(f"❌ 设置协调器失败: {str(e)}", exc_info=True)
08-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值