feat: 告警HTTP上报 + 日志精简 + 边缘节点统一为edge

- 新增 alarm_upload_worker.py 异步告警上报(COS+HTTP)
- result_reporter 重构为Redis队列模式
- config_sync 适配WVP直推的聚合配置格式
- settings 默认 EDGE_DEVICE_ID 改为 edge
- 日志设置非告警模块为WARNING级别减少噪音
- main.py 集成新的告警上报流程

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 15:21:45 +08:00
parent 93a2278626
commit 0191e498f1
6 changed files with 1279 additions and 1075 deletions

View File

@@ -34,7 +34,7 @@ class SQLiteConfig:
@dataclass
class RedisConfig:
"""Redis配置类"""
"""Redis配置类(本地 Redis边缘侧缓存"""
host: str = "localhost"
port: int = 6379
db: int = 0
@@ -43,13 +43,35 @@ class RedisConfig:
max_connections: int = 50
@dataclass
class CloudRedisConfig:
"""云端 Redis 配置(三层权威模型 - 云端层)"""
host: str = "localhost"
port: int = 6379
db: int = 0
password: Optional[str] = None
decode_responses: bool = True
max_connections: int = 20
@dataclass
class LocalRedisConfig:
"""本地 Redis 配置(三层权威模型 - 边缘层缓存)"""
host: str = "localhost"
port: int = 6379
db: int = 1
password: Optional[str] = None
decode_responses: bool = True
max_connections: int = 20
@dataclass
class MQTTConfig:
"""MQTT配置类"""
"""MQTT配置类(保留配置结构,不再用于告警上报)"""
broker_host: str = "localhost"
broker_port: int = 1883
client_id: str = "edge_inference_service"
device_id: str = "edge-001"
device_id: str = "edge"
username: Optional[str] = None
password: Optional[str] = None
keepalive: int = 60
@@ -58,6 +80,24 @@ class MQTTConfig:
max_reconnect_attempts: int = 10
@dataclass
class COSConfig:
"""腾讯云 COS 配置"""
secret_id: str = ""
secret_key: str = ""
region: str = "ap-beijing"
bucket: str = ""
@dataclass
class AlarmUploadConfig:
"""告警上报配置"""
cloud_api_url: str = "http://124.221.55.225:8000"
edge_token: str = ""
retry_max: int = 3
retry_interval: int = 5
@dataclass
class VideoStreamConfig:
"""视频流配置类"""
@@ -157,15 +197,43 @@ class Settings:
port=int(os.getenv("REDIS_PORT", "6379")),
password=os.getenv("REDIS_PASSWORD"),
)
self.cloud_redis = CloudRedisConfig(
host=os.getenv("CLOUD_REDIS_HOST", "localhost"),
port=int(os.getenv("CLOUD_REDIS_PORT", "6379")),
db=int(os.getenv("CLOUD_REDIS_DB", "0")),
password=os.getenv("CLOUD_REDIS_PASSWORD"),
)
self.local_redis = LocalRedisConfig(
host=os.getenv("LOCAL_REDIS_HOST", "localhost"),
port=int(os.getenv("LOCAL_REDIS_PORT", "6379")),
db=int(os.getenv("LOCAL_REDIS_DB", "1")),
password=os.getenv("LOCAL_REDIS_PASSWORD"),
)
self.mqtt = MQTTConfig(
broker_host=os.getenv("MQTT_BROKER_HOST", "localhost"),
broker_port=int(os.getenv("MQTT_BROKER_PORT", "1883")),
client_id=os.getenv("MQTT_CLIENT_ID", "edge_inference_service"),
device_id=os.getenv("EDGE_DEVICE_ID", "edge-001"),
device_id=os.getenv("EDGE_DEVICE_ID", "edge"),
username=os.getenv("MQTT_USERNAME"),
password=os.getenv("MQTT_PASSWORD"),
)
self.cos = COSConfig(
secret_id=os.getenv("COS_SECRET_ID", ""),
secret_key=os.getenv("COS_SECRET_KEY", ""),
region=os.getenv("COS_REGION", "ap-beijing"),
bucket=os.getenv("COS_BUCKET", ""),
)
self.alarm_upload = AlarmUploadConfig(
cloud_api_url=os.getenv("CLOUD_API_URL", "http://124.221.55.225:8000"),
edge_token=os.getenv("EDGE_TOKEN", ""),
retry_max=int(os.getenv("ALARM_RETRY_MAX", "3")),
retry_interval=int(os.getenv("ALARM_RETRY_INTERVAL", "5")),
)
self.video_stream = VideoStreamConfig(
default_fps=int(os.getenv("VIDEO_DEFAULT_FPS", "5")),