--- title: "示例站点带宽与 accountMetrics API" slug: "example-site-bandwidth-with-accountmetrics-api" updated: 2026-07-30T03:34:56Z published: 2026-07-30T03:34:56Z canonical: "knowledge.catonetworks.com/example-site-bandwidth-with-accountmetrics-api" --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.catonetworks.com/llms.txt > Use this file to discover all available pages before exploring further. # 示例站点带宽与 accountMetrics API 本文解释了一份样本 accountMetrics API 查询,用于监控站点的最大上游和下游吞吐量。 ## 创建查询 我们建议使用 bytesUpstreamMax 和 bytesDownstreamMax,这是峰值指标。 Cato 许可证基于这些值,而不是平均吞吐量。 这是一个查询,用于检索 2024 年 2 月 6 日 15:00:00 至 15:10:00 时间段的 10 个桶的时间序列,站点 ID=12345。 10 分钟时间段内的 10 个桶意味着每个桶实际上是一分钟。 ``` {    accountMetrics(        accountID: 7890        timeFrame: "utc.2024-02-06/{15:00:00--15:10:00}"        groupDevices: true        groupInterfaces: true    ) {        from        to        sites (siteIDs:[12345]) {            interfaces {                name                timeseries (labels:[bytesUpstreamMax] buckets:10) {                    label                    units                    data                }            }        }    } } ``` 这就是查询在 GraphQL API Playground 中的样子: ![01_accountMetrics.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/25296975243037.png?sv=2026-02-06&spr=https&st=2026-11-19T05%3A45%3A38Z&se=2026-11-19T06%3A45%3A38Z&sr=b&sp=r&sig=8Mp8IKLXoQEwvsvZkm6blea3yhhw4dA8IsVd6YtYIv0%3D) 完整响应如下: ``` {  "data": {    "accountMetrics": {      "from": "2024-02-06T15:00:00Z",      "to": "2024-02-06T15:10:00Z",      "sites": [        {          "interfaces": [            {              "name": "all",              "timeseries": [                {                  "label": "bytesUpstreamMax",                  "units": "bytes",                  "data": [                    [                      1707231600000,                      6008                    ],                    [                      1707231660000,                      12802                    ],                    [                      1707231720000,                      6557                    ],                    [                      1707231780000,                      3467                    ],                    [                      1707231840000,                      7168                    ],                    [                      1707231900000,                      3660                    ],                    [                      1707231960000,                      6791                    ],                    [                      1707232020000,                      5839                    ],                    [                      1707232080000,                      4183                    ],                    [                      1707232140000,                      4684                    ]                  ]                }              ]            }          ]        }      ]    }  } } ``` ## 解释时间序列结果 ### 时间戳 时间序列/数据数组的每个元素都是一个列表,其中第一个元素是该桶开始时的时间戳,第二个元素是该桶的指标。 时间戳为 UTC,Unix 纪元时间为纳秒。 Python 一行命令将第一个桶中的时间戳转换为人类可读字符串: ``` python3 -c "import datetime;print(datetime.datetime.fromtimestamp(1707231600000/1000))" ``` 在 Mac 上运行该命令显示如下: ``` sh-3.2$ python3 -c "import datetime;print(datetime.datetime.fromtimestamp (1707231600000/1000))" 2024-02-06 15:00:00 sh-3.2$ ``` 还可以运行以下 bash 命令: ``` date -r $((1707231600000/1000)) ``` 这是 bash 命令的结果: ``` Cato-admin-M:tools catoadmin$ date -r $((1707231600000/1000)) Tue 6 Feb 2024 15:00:00 GMT ``` 使用这些技术将上述输出中的所有时间戳转换,可以看到它们与我们时间段中每分钟桶的开始时间相匹配: ``` 1707231600000 -> 2024-02-06 15:00:00 1707231660000 -> 2024-02-06 15:01:00 1707231720000 -> 2024-02-06 15:02:00 1707231780000 -> 2024-02-06 15:03:00 1707231840000 -> 2024-02-06 15:04:00 1707231900000 -> 2024-02-06 15:05:00 1707231960000 -> 2024-02-06 15:06:00 1707232020000 -> 2024-02-06 15:07:00 1707232080000 -> 2024-02-06 15:08:00 1707232140000 -> 2024-02-06 15:09:00 ``` ### 峰值上游吞吐量 每个时间序列元素的第二个项目是指标,在这种情况下是该桶的峰值上游吞吐量。 可以在单个查询中请求多个指标——通常请求 bytesUpstreamMax 和 bytesDownstreamMax。 无论 perSecond 输入参数如何,指标始终以速度表示。 `units` 字段指示这些是字节,因此我们必须乘以 8 来转换为更常见的比特每秒。 查看我们上面的响应中的第一个元素: ``` [ 1707231600000, 6008 ], ``` 我们可以将此解析为: - 2024-02-06 15:00:00 UTC 是这个桶的开始 - 我们从参数中知道这是一个一分钟的桶(如果不确定,也可以请求 API 返回桶粒度) - 在这个桶中,最高吞吐量是每秒 6008 字节。 乘以 8,我们得到一个峰值,即 8*6008 = 48,064 比特每秒 = 48 千比特每秒。 应用这个简单原则到我们返回的时间序列中的所有项目,我们得到了这些值: ``` 1707231600000 -> 2024-02-06 15:00:00 48 千比特每秒 1707231660000 -> 2024-02-06 15:01:00 102 千比特每秒 1707231720000 -> 2024-02-06 15:02:00 52 千比特每秒 1707231780000 -> 2024-02-06 15:03:00 27 千比特每秒 1707231840000 -> 2024-02-06 15:04:00 57 千比特每秒 1707231900000 -> 2024-02-06 15:05:00 29 千比特每秒 1707231960000 -> 2024-02-06 15:06:00 54 千比特每秒 1707232020000 -> 2024-02-06 15:07:00 46 千比特每秒 1707232080000 -> 2024-02-06 15:08:00 33 千比特每秒 1707232140000 -> 2024-02-06 15:09:00 37 千比特每秒 ``` 如果我们在 Excel 中将这些值绘制成图表,折线图看起来是这样的: ![02_excel.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/25296996693789.png?sv=2026-02-06&spr=https&st=2026-11-19T05%3A45%3A38Z&se=2026-11-19T06%3A45%3A38Z&sr=b&sp=r&sig=w8hlZBQk3mo9uOW%2FMWZ3FT6jpJlggS8FYYeCxYKXbgA%3D) 对于相应的时间段和站点,“最大吞吐量 - 上游”图表看起来是这样的: ![03_excel.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/25296996785949.png?sv=2026-02-06&spr=https&st=2026-11-19T05%3A45%3A38Z&se=2026-11-19T06%3A45%3A38Z&sr=b&sp=r&sig=TuVwlIrtPmJIUkEQ%2BDWch5xa00XJChQnzdA2auz2kVg%3D) 乍一看,这些图表看起来有些不同,但主要是因为 CMA 图表来自具有更多桶的查询——为了便于演示,我们使用了一个较少桶数(10)的 Playground 查询。 如果我们将来自查询数据的 Excel 图表放在 CMA 图表上,您可以看到强相关性: ![04-excel.png](https://cdn.document360.io/81d0367c-2b69-4ba8-b412-1c8f46ce677e/Images/Documentation/25296952629789.png?sv=2026-02-06&spr=https&st=2026-11-19T05%3A45%3A38Z&se=2026-11-19T06%3A45%3A38Z&sr=b&sp=r&sig=lZlfN3ui7%2FYXGPvL0fvAsc%2FXTvAL8xbDnIxk06wtjPA%3D)