> ## Documentation Index
> Fetch the complete documentation index at: https://yumebox.oom-wg.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取实时流量



## OpenAPI

````yaml /api/openapi.json get /traffic
openapi: 3.1.0
info:
  title: Mihomo 外部控制器 API
  version: 1.0.0
  description: >-
    Mihomo（clash.meta）内核通过外部控制器（external-controller）暴露的 RESTful
    API，可用于查询状态、切换节点、测试延迟、管理连接等。TCP / TLS 外部控制器在配置了 secret 时需要携带 Bearer 密钥；Unix
    socket / Windows named pipe 访问不会校验 secret。可在右侧 Try it 面板中将服务器地址 host/port
    修改为你自己的后端地址（mihomo 示例配置为 http://127.0.0.1:9093）。
servers:
  - url: http://{host}:{port}
    variables:
      host:
        default: 127.0.0.1
        description: 外部控制器监听地址 / mihomo 后端的局域网 IP。
      port:
        default: '9093'
        description: '外部控制器监听端口；默认值对齐 mihomo 示例配置 external-controller: 0.0.0.0:9093。'
security:
  - bearerAuth: []
tags:
  - name: 日志
    description: 实时日志流。
  - name: 流量信息
    description: 实时上下行流量统计。
  - name: 内存信息
    description: 实时内存占用统计。
  - name: 版本信息
    description: 内核版本信息。
  - name: 缓存
    description: FakeIP / DNS 缓存清理。
  - name: 运行配置
    description: 运行配置的读取、重载与修改。
  - name: 更新
    description: 内核、面板与 GEO 数据库的更新。
  - name: 策略组
    description: 策略组的查询与延迟测试。
  - name: 代理
    description: 代理节点的查询、选择与延迟测试。
  - name: 代理集合
    description: 代理集合（proxy provider）的查询、更新与健康检查。
  - name: 规则
    description: 规则的查询与临时禁用。
  - name: 规则集合
    description: 规则集合（rule provider）的查询与更新。
  - name: 连接
    description: 连接信息的查询与关闭。
  - name: 域名查询
    description: 通过内核 DNS 进行域名解析。
  - name: 存储
    description: 内核键值存储的读写。
  - name: DEBUG
    description: 调试相关端点（需内核日志级别为 debug）。
paths:
  /traffic:
    get:
      tags:
        - 流量信息
      summary: 获取实时流量
      operationId: getTraffic
      parameters:
        - name: once
          in: query
          required: false
          description: 设置为 true 时立即返回当前流量快照；不设置时保持实时流式输出。
          schema:
            type: boolean
        - name: token
          in: query
          required: false
          description: 仅 WebSocket 场景使用。浏览器无法设置 Authorization 头时，可用 token=${secret} 进行鉴权。
          schema:
            type: string
      responses:
        '200':
          description: 默认流式流量数据，每秒一行 JSON；once=true 时立即返回一次快照。
          content:
            application/json:
              schema:
                type: object
                properties:
                  up:
                    type: integer
                    description: 上行字节/秒。
                  down:
                    type: integer
                    description: 下行字节/秒。
                  upTotal:
                    type: integer
                    description: 累计上行字节。
                  downTotal:
                    type: integer
                    description: 累计下行字节。
              example:
                up: 58527
                down: 154391
                upTotal: 1747227807
                downTotal: 1106864138
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        在请求头中携带 Authorization: Bearer ${secret}，其中 secret 对应配置中的 secret 字段。若未设置
        secret 可省略，但强烈建议设置。

````