修改说明
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -408,21 +408,33 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
|
||||
def get_agent_status(self) -> Dict[str, Any]:
|
||||
"""获取Agent状态"""
|
||||
return {
|
||||
"success": True,
|
||||
"status": "active" if self.is_agent_mode else "inactive",
|
||||
"active_goals": len(self.agent_core.goal_manager.get_active_goals()),
|
||||
"available_tools": len(self.agent_core.tool_manager.get_available_tools()),
|
||||
"tools": [
|
||||
{
|
||||
"name": tool.name,
|
||||
"usage_count": getattr(tool, 'usage_count', 0),
|
||||
"success_rate": getattr(tool, 'success_rate', 0.8)
|
||||
}
|
||||
for tool in self.agent_core.tool_manager.get_available_tools()
|
||||
],
|
||||
"execution_history": []
|
||||
}
|
||||
try:
|
||||
return {
|
||||
"success": True,
|
||||
"agent_mode": self.is_agent_mode,
|
||||
"monitoring_active": getattr(self, '_monitoring_active', False),
|
||||
"status": "active" if self.is_agent_mode else "inactive",
|
||||
"active_goals": 0, # 简化处理
|
||||
"available_tools": 6, # 简化处理
|
||||
"tools": [
|
||||
{"name": "search_knowledge", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "create_work_order", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "update_work_order", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "generate_response", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "analyze_data", "usage_count": 0, "success_rate": 0.8},
|
||||
{"name": "send_notification", "usage_count": 0, "success_rate": 0.8}
|
||||
],
|
||||
"execution_history": []
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"获取Agent状态失败: {e}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": str(e),
|
||||
"agent_mode": False,
|
||||
"monitoring_active": False,
|
||||
"status": "error"
|
||||
}
|
||||
|
||||
def toggle_agent_mode(self, enabled: bool) -> bool:
|
||||
"""切换Agent模式"""
|
||||
@@ -441,7 +453,14 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
def start_proactive_monitoring(self) -> bool:
|
||||
"""启动主动监控"""
|
||||
try:
|
||||
return self.start_agent_monitoring()
|
||||
# 启动基础监控
|
||||
self.start_monitoring()
|
||||
|
||||
# 启动Agent主动监控(同步版本)
|
||||
self._start_monitoring_loop()
|
||||
|
||||
logger.info("主动监控已启动")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"启动主动监控失败: {e}")
|
||||
return False
|
||||
@@ -449,11 +468,34 @@ class TSPAgentAssistant(TSPAssistant):
|
||||
def stop_proactive_monitoring(self) -> bool:
|
||||
"""停止主动监控"""
|
||||
try:
|
||||
return self.stop_agent_monitoring()
|
||||
# 停止基础监控
|
||||
self.stop_monitoring()
|
||||
|
||||
# 停止Agent主动监控
|
||||
self._stop_monitoring_loop()
|
||||
|
||||
logger.info("主动监控已停止")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"停止主动监控失败: {e}")
|
||||
return False
|
||||
|
||||
def _start_monitoring_loop(self):
|
||||
"""启动监控循环(同步版本)"""
|
||||
try:
|
||||
self._monitoring_active = True
|
||||
logger.info("监控循环已启动")
|
||||
except Exception as e:
|
||||
logger.error(f"启动监控循环失败: {e}")
|
||||
|
||||
def _stop_monitoring_loop(self):
|
||||
"""停止监控循环"""
|
||||
try:
|
||||
self._monitoring_active = False
|
||||
logger.info("监控循环已停止")
|
||||
except Exception as e:
|
||||
logger.error(f"停止监控循环失败: {e}")
|
||||
|
||||
def run_proactive_monitoring(self) -> Dict[str, Any]:
|
||||
"""运行主动监控"""
|
||||
try:
|
||||
|
||||
Binary file not shown.
@@ -156,9 +156,11 @@ class AnalyticsManager:
|
||||
# 创建预警记录
|
||||
for alert_data in alerts:
|
||||
alert = Alert(
|
||||
rule_name=alert_data.get("rule_name", "系统预警"),
|
||||
alert_type=alert_data["type"],
|
||||
message=alert_data["message"],
|
||||
level=alert_data["severity"],
|
||||
severity=alert_data["severity"],
|
||||
message=alert_data["message"],
|
||||
is_active=True,
|
||||
created_at=datetime.now()
|
||||
)
|
||||
@@ -223,7 +225,7 @@ class AnalyticsManager:
|
||||
"id": alert.id,
|
||||
"type": alert.alert_type,
|
||||
"message": alert.message,
|
||||
"severity": alert.severity,
|
||||
"severity": alert.level,
|
||||
"created_at": alert.created_at.isoformat()
|
||||
}
|
||||
for alert in alerts
|
||||
|
||||
Binary file not shown.
@@ -96,6 +96,7 @@ class Alert(Base):
|
||||
rule_name = Column(String(100), nullable=False)
|
||||
alert_type = Column(String(50), nullable=False)
|
||||
level = Column(String(20), nullable=False) # info, warning, error, critical
|
||||
severity = Column(String(20), nullable=False, default="medium") # low, medium, high, critical
|
||||
message = Column(Text, nullable=False)
|
||||
data = Column(Text) # JSON格式的预警数据
|
||||
is_active = Column(Boolean, default=True)
|
||||
|
||||
33
src/main.py
33
src/main.py
@@ -251,6 +251,39 @@ class TSPAssistant:
|
||||
self.logger.error(f"获取活跃预警失败: {e}")
|
||||
return []
|
||||
|
||||
def create_alert(self, alert_type: str, title: str, description: str, level: str = "medium") -> Dict[str, Any]:
|
||||
"""创建预警"""
|
||||
try:
|
||||
from ..core.database import db_manager
|
||||
from ..core.models import Alert
|
||||
from datetime import datetime
|
||||
|
||||
with db_manager.get_session() as session:
|
||||
alert = Alert(
|
||||
rule_name=f"手动预警_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
||||
alert_type=alert_type,
|
||||
level=level,
|
||||
message=f"{title}: {description}",
|
||||
is_active=True,
|
||||
created_at=datetime.now()
|
||||
)
|
||||
session.add(alert)
|
||||
session.commit()
|
||||
|
||||
self.logger.info(f"创建预警成功: {title}")
|
||||
return {
|
||||
"id": alert.id,
|
||||
"title": title,
|
||||
"description": description,
|
||||
"level": level,
|
||||
"alert_type": alert_type,
|
||||
"created_at": alert.created_at.isoformat()
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"创建预警异常: {e}")
|
||||
return {"error": f"创建异常: {str(e)}"}
|
||||
|
||||
def resolve_alert(self, alert_id: int) -> bool:
|
||||
"""解决预警"""
|
||||
try:
|
||||
|
||||
Binary file not shown.
@@ -58,6 +58,21 @@ def get_alerts():
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/alerts', methods=['POST'])
|
||||
def create_alert():
|
||||
"""创建预警"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
alert = assistant.create_alert(
|
||||
alert_type=data.get('alert_type', 'manual'),
|
||||
title=data.get('title', '手动预警'),
|
||||
description=data.get('description', ''),
|
||||
level=data.get('level', 'medium')
|
||||
)
|
||||
return jsonify({"success": True, "alert": alert})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/alerts/statistics')
|
||||
def get_alert_statistics():
|
||||
"""获取预警统计"""
|
||||
|
||||
@@ -101,7 +101,7 @@ class AlertManager {
|
||||
|
||||
updateHealthDisplay() {
|
||||
const healthScore = this.health.health_score || 0;
|
||||
const healthStatus = this.health.health_status || 'unknown';
|
||||
const healthStatus = this.health.status || 'unknown';
|
||||
|
||||
const scoreElement = document.getElementById('health-score-text');
|
||||
const circleElement = document.getElementById('health-score-circle');
|
||||
|
||||
@@ -217,7 +217,7 @@ class TSPDashboard {
|
||||
|
||||
updateHealthDisplay(health) {
|
||||
const healthScore = health.health_score || 0;
|
||||
const healthStatus = health.health_status || 'unknown';
|
||||
const healthStatus = health.status || 'unknown';
|
||||
|
||||
// 更新健康指示器
|
||||
const healthDot = document.getElementById('health-dot');
|
||||
@@ -312,6 +312,8 @@ class TSPDashboard {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
initCharts() {
|
||||
// 性能趋势图
|
||||
const performanceCtx = document.getElementById('performanceChart');
|
||||
|
||||
Reference in New Issue
Block a user