# 使用统计

您可以通过提交以下内容免费查看您的使用统计数据 一个 API 请求。

下面的端点用于使用统计查询：

```
GET https://data.oxylabs.io/v2/stats
```

### 输入

默认情况下，API 将返回未过滤的（所有时间、所有来源）使用统计数据。如有需要，您可以获取分组和/或过滤后的统计数据。

您可以在同一个查询中组合两个或更多参数，例如按天分组统计并按来源过滤。

| 参数                                                                        | 描述                                           | 有效值                                                                                                                 | URL 示例                                                      |
| ------------------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| `group_by`                                                                | 启用显示按日、按月或按年的使用统计数据（而不是显示总统计数据）              | `day`, `month`, `year`                                                                                              | `https://data.oxylabs.io/v2/stats?group_by=day`             |
| `date_from`                                                               | 较早的日期边界。最好与以下参数一起使用 `date_to`.               | 任意 `Y-m-d` 格式的日期。                                                                                                   | `https://data.oxylabs.io/v2/stats?date_from=2022-01-17`     |
| `date_to`                                                                 | 较晚的日期边界。最好与以下参数一起使用 `date_from`.             | 任意 `Y-m-d` 格式的日期。                                                                                                   | `https://data.oxylabs.io/v2/stats?date_to=2022-06-17`       |
| `来源`                                                                      | 让您获取单个 `来源` 您所选的使用统计数据。                      | 任何有效的 `来源` 值分隔。                                                                                                     | `https://data.oxylabs.io/v2/stats?source=universal`         |
| <p><code>product</code><br><br>此过滤器适用于旧版用户（在 2024 年 9 月 25 日之前创建的账户）。</p> | 让您获取您所选单个产品的使用统计数据。仅当您使用同一用户名访问多个网页爬虫API时适用。 | <p><code>serp\_scraper\_api</code>;</p><p><code>ecommerce\_scraper\_api</code> ; <code>web\_scraper\_api</code></p> | `https://data.oxylabs.io/v2/stats?product=serp_scraper_api` |

下面的查询返回按月统计数据。

{% tabs %}
{% tab title="cURL" %}

```shell
curl --user "user:pass1" 'https://data.oxylabs.io/v2/stats?group_by=month'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# 从 stats 端点获取响应。
response = requests.request(
    method='GET',
    url='https://data.oxylabs.io/v2/stats',
    auth=('user', 'pass1'),
)

# 将格式化后的 JSON 响应打印到标准输出。
pprint(response.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://data.oxylabs.io/v2/stats");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_USERPWD, "user" . ":" . "pass1");

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
```

{% endtab %}
{% endtabs %}

### 输出

该 `v2/stats` 输出包含使用统计数据，包括产品级统计数据（电商爬虫 API / SERP 爬虫 API / 网页爬虫API）。产品级统计数据会进一步拆分为来源级统计数据，而来源级统计数据又会进一步拆分为 HTML 和解析结果的独立统计数据。请参阅 [**数据字典**](#data-dictionary) 部分，了解每个输出键的含义。

#### 示例输出

```json
{
    "meta": {
        "group_by": null,
        "date_from": null,
        "date_to": null,
        "source": null,
        "product": null
    },
    "data": {
        "products": [
            {
                "all_count": 5837,
                "mode_callback_count": 5514,
                "mode_realtime_count": 315,
                "mode_superapi_count": 8,
                "contenttype_parsed_count": 56,
                "contenttype_html_count": 5781,
                "render_count": 3,
                "geo_location_count": 2330,
                "average_response_time": 88.54,
                "request_traffic": 4685091,
                "response_traffic": 602064208,
                "title": "serp_scraper_api",
                "sources": [
                    {
                        "all_count": 5616,
                        "mode_callback_count": 5414,
                        "mode_realtime_count": 194,
                        "mode_superapi_count": 8,
                        "render_count": 0,
                        "geo_location_count": 2190,
                        "average_response_time": 91.59,
                        "request_traffic": 4550507,
                        "response_traffic": 585423946,
                        "title": "serp_source1",
                        "parsed": false
                    },
                    {
                        "all_count": 1,
                        "mode_callback_count": 0,
                        "mode_realtime_count": 1,
                        "mode_superapi_count": 0,
                        "render_count": 0,
                        "geo_location_count": 1,
                        "average_response_time": 11,
                        "request_traffic": 0,
                        "response_traffic": 0,
                        "title": "serp_source2",
                        "parsed": false
                    }
                ]
            }
        ]
    }
}
```

### 数据字典

| 键                          | 描述                                 | 类型      |
| -------------------------- | ---------------------------------- | ------- |
| `meta`                     | 所有已提交统计数据的容器 [**查询参数**](#input).   | -       |
| `data`                     | 所有统计数据的容器。                         | JSON 对象 |
| `products`                 | 产品级统计对象列表。                         | JSON 数组 |
| `all_count`                | 结果总数。                              | 整数      |
| `mode_callback_count`      | 通过 Push-Pull 集成方式完成的结果数量。          | 整数      |
| `mode_realtime_count`      | 通过 Realtime 集成方式完成的结果数量。           | 整数      |
| `mode_superapi_count`      | 通过 Proxy Endpoint 集成方式完成的结果数量。     | 整数      |
| `contenttype_parsed_count` | 解析结果的数量。                           | 整数      |
| `contenttype_html_count`   | HTML 结果的数量。                        | 整数      |
| `render_count`             | 通过 JavaScript 执行完成的结果数量。           | 整数      |
| `geo_location_count`       | 使用用户定义的 `geo_location` 参数值完成的结果数量。 | 整数      |
| `average_response_time`    | 平均响应时间（秒）。                         | 浮点数     |
| `request_traffic`          | 总 **请求** 流量（字节）。                   | 整数      |
| `response_traffic`         | 总 **响应** 流量（字节）。                   | 整数      |
| `title`                    | 产品或来源名称。                           | 字符串     |
| `sources`                  | 属于特定产品的来源列表。                       | 字符串     |
| `parsed`                   | 指示 JSON 对象中的数据是否属于解析结果。            | 布尔值     |


---

# 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://developers.oxylabs.io/products/cn/web-scraper-api/usage-and-billing/usage-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.
