Skip to content

Conversation

@xgopilot
Copy link

@xgopilot xgopilot bot commented Nov 26, 2025

Requested by @callmefisher

此 PR 优化了 query_live_traffic_stats 函数的实现,提供更有用的流量和带宽统计数据。

主要变更

  1. 流量数据累加: 解析 HTTP 响应的 JSON 数据,计算所有流量数据点的总和(单位:字节)
  2. 带宽转换: 将 5 分钟粒度的流量数据转换为带宽数据(比特/秒)
    • 计算公式:带宽 (bps) = 流量字节 / 300 秒 × 8 比特/字节
  3. 统计指标:
    • 总流量(字节)
    • 平均带宽(bps)
    • 峰值带宽(bps)
    • 数据点数量
  4. 人类可读格式: 自动转换为合适的单位(B/KB/MB/GB/TB,bps/Kbps/Mbps/Gbps)
  5. 优化返回数据: 默认不返回原始 JSON 数据,仅返回汇总统计信息
  6. 可选原始数据: 添加 include_raw_data 参数,当设置为 true 时返回原始数据供下载使用

示例响应

默认响应(不包含原始数据):

{
  "status": "success",
  "summary": {
    "total_traffic_bytes": 1073741824,
    "total_traffic_formatted": "1.00 GB",
    "data_points_count": 288,
    "average_bandwidth_bps": 29826.67,
    "average_bandwidth_formatted": "29.83 Kbps",
    "peak_bandwidth_bps": 102400.00,
    "peak_bandwidth_formatted": "102.40 Kbps",
    "granularity": "5 minutes"
  }
}

包含原始数据(include_raw_data=true):

{
  "status": "success",
  "summary": { ... },
  "raw_data": [...],
  "data_points": [...]
}

测试

此更改向后兼容,现有调用将继续工作但返回优化后的数据格式。

Fixes #58

- Parse JSON response to calculate total traffic (sum of all flow bytes)
- Convert traffic to bandwidth metrics (bits per second) using 5-minute granularity
- Calculate average and peak bandwidth values
- Add human-readable formatting for traffic and bandwidth
- Remove raw JSON from default response
- Add include_raw_data parameter to optionally return raw data for download
- Update tool schema to document new parameter and behavior

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: callmefisher <[email protected]>
@xgopilot xgopilot bot mentioned this pull request Nov 26, 2025
@callmefisher callmefisher merged commit 033a231 into main Nov 26, 2025
2 checks passed
@xgopilot xgopilot bot deleted the xgopilot/claude/issue-58-1764151462 branch November 26, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

miku-mcp优化

3 participants