feat:增加批量插入和查询日志告警功能

This commit is contained in:
2025-10-20 13:17:55 +08:00
parent d57b264281
commit 0dd9d36e73
41 changed files with 226 additions and 478 deletions

25
utils/time.py Normal file
View File

@@ -0,0 +1,25 @@
from datetime import datetime
from typing import Tuple
def get_timestamp_range(ts: int, delta_seconds: int = 5, unit: str = "microseconds") -> Tuple[int, int]:
"""
返回时间戳前后delta_seconds秒的范围单位与输入一致
"""
if ts <= 0:
return 0, 0
scale = {
"seconds": 1,
"milliseconds": 1000,
"microseconds": 1_000_000,
"nanoseconds": 1_000_000_000
}.get(unit, 1_000_000) # 默认微秒
delta = delta_seconds * scale
return ts - delta, ts + delta
def format_timestamp(timestamp: int) -> str:
return datetime.fromtimestamp(timestamp / 1_000_000).strftime("%Y-%m-%d %H:%M:%S")