# 使用统计

住宅代理的流量与请求数据可在三处查看：控制台、REST API、响应头。

## 控制台

**控制台 → 住宅 → 统计** 提供：

* **流量曲线** — 按分钟 / 小时 / 天累计字节数，按子账号分层
* **Top 目标** — 按流量与请求次数排序的域名
* **Top 国家** — 实际使用的出口 IP 地理分布
* **错误分布** — 按 HTTP 状态码与 `X-Helodata-Error-Code` 细分
* **会话数** — 并发粘性会话
* **并发数** — 峰值并行连接

可按子账号、时间范围、标签（若请求带 `X-Helodata-Tag`，详见下文）筛选。

数据每分钟刷新。14 天后降采样（1 分钟 → 5 分钟），90 天后再降（5 分钟 → 1 小时）。

## REST API

适合接计费管线、自建仪表盘、告警。

### 获取聚合流量

```bash
curl -H "Authorization: Bearer API_KEY" \
     "https://api.helodata.com/v1/residential/traffic?from=2026-05-01&to=2026-05-28&group_by=subuser"
```

响应：

```json
{
  "from": "2026-05-01T00:00:00Z",
  "to":   "2026-05-28T00:00:00Z",
  "rows": [
    { "subuser": "s1a2b3c4d5e", "bytes_in": 12345678, "bytes_out": 9876543, "requests": 4210 },
    { "subuser": "s9z8y7x6w5v", "bytes_in": 222345,   "bytes_out": 134567,  "requests": 88 }
  ]
}
```

`group_by` 可取 `subuser`、`region`、`asn`、`tag`、`day`。

### 获取请求日志（采样）

仅用于排障，会消耗 API 配额。返回最近 1,000 条采样请求。

```bash
curl -H "Authorization: Bearer API_KEY" \
     "https://api.helodata.com/v1/residential/requests?subuser=s1a2b3c4d5e&limit=100"
```

每条包含状态码、出口 IP、地理、ASN、字节数、你的标签。

完整 schema 见 [流量与用量](/helodata-zh/api-can-kao/traffic.md)。

## 响应头

每个成功请求都包含使用信息：

```
X-Helodata-Bytes-In: 1248
X-Helodata-Bytes-Out: 38745
X-Helodata-Exit-IP: 198.51.100.42
X-Helodata-Exit-Geo: us/ca/la
X-Helodata-Exit-ASN: 7922
X-Helodata-Request-Id: req_01HX2K3PQ4M5
```

联系客服时附上 `X-Helodata-Request-Id`，我们可凭它调出完整请求记录。

## 给请求打标签

按你自定义类别（活动、客户、任务）切分数据，请发送 `X-Helodata-Tag` 请求头（最多 64 字符，字符集 `[a-z0-9_-]`）：

```bash
curl -x http://helo_s1a2b3c4d5e-type-res-region-us:PASSWORD@gate.helodata.io:7777 \
     -H "X-Helodata-Tag: campaign-acme-q2" \
     https://example.com
```

标签会出现在控制台筛选与流量 API 的 `group_by` 中。

## 账单对账

控制台展示的流量即计费金额。对账方式：

1. 调流量 API 取计费周期内按日的数据。
2. 汇总 `bytes_in + bytes_out`，按子账号求和。
3. 与 **账单 → 发票** 中的条目对比。

差异 > 1% 极少见；若出现，请提交工单并附 `X-Helodata-Request-Id` 范围，我们会复核。

## 告警

在 **控制台 → 告警** 中设置：

* 单日流量超过 X GB
* 错误率在 Z 分钟内超过 Y%
* 子账号并发接近套餐上限

告警通过邮件与可选的 Slack webhook 发送。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.helodata.com/helodata-zh/chan-pin/overview/statistics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
