借助 Google Play Developer Reporting API,您可以检索在指标集中检测到的异常情况。每次指标值超出预期范围时,系统都会生成异常,而预期范围是根据同一指标前 28 天的值确定的。连续多天的异常会合并为单个异常结果。
如果某项指标的值出现异常增加的情况并持续足够长的时间,检测模型会进行调整并扩大预期值范围,直到后续数据点不再被视为异常。
检索异常值
您可以使用 anomalies.list 方法列出异常。
简单请求:
此 HTTP GET
请求指定了应用名称参数,并返回应用的完整检测到的异常列表。
GET https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/anomalies
异常响应:
响应包含足够的信息,可用于准确查询异常发生的位置:
{ "anomalies": [ { "name": "apps/com.example.app/anomalies/12345" "metric_set": "apps/com.example.app/anrRateMetricSet" "timeline_spec": { "aggregation_period": "DAILY" "start_time": { "year": 2022 "month": 1 "day": 23 "time_zone": { "id": "America/Los_Angeles" } } "end_time": { "year": 2022 "month": 1 "day": 23 "time_zone": { "id": "America/Los_Angeles" } } } "metric": { "metric": "anrRate", "decimal_value": { "value": "3.1415926535" } } }, { "name": "apps/com.example.app/anomalies/12345" "metric_set": "apps/com.example.app/crashRateMetricSet" "timeline_spec": { "aggregation_period": "DAILY" "start_time": { "year": 2021 "month": 12 "day": 10 "time_zone": { "id": "America/Los_Angeles" } } "end_time": { "year": 2021 "month": 12 "day": 10 "time_zone": { "id": "America/Los_Angeles" } } } "metric": { "metric": "crashRate", "decimal_value": { "value": "2.7182818284" } } }, ] }
过滤后的请求:
您可以应用过滤条件,仅返回在特定时间段内处于有效状态的异常。为此,请在请求的过滤条件字段中指定 activeBetween(start, end)
函数。您可以使用特殊关键字 UNBOUNDED
在范围的任一侧指定无界限的限制。如果指定开始或结束界限,则必须遵循 RFC 3339 格式,例如 2022-02-22T04:00Z
。
GET https://playdeveloperreporting.googleapis.com/v1beta1/apps/com.example.app/anomalies?filter=activeBetween("2022-01-01T00:00:00Z", UNBOUNDED)
过滤后的响应:
响应仅包含在指定时间范围内处于有效状态的异常:
{ "anomalies": [ { "name": "apps/com.example.app/anomalies/12345" "metric_set": "apps/com.example.app/anrRateMetricSet" "timeline_spec": { "aggregation_period": "DAILY" "start_time": { "year": 2022 "month": 1 "day": 23 "time_zone": { "id": "America/Los_Angeles" } } "end_time": { "year": 2022 "month": 1 "day": 23 "time_zone": { "id": "America/Los_Angeles" } } } "metric": { "metric": "anrRate", "decimal_value": { "value": "3.1415926535" } } }, ] }
可用指标
目前,并非所有指标和指标集都支持异常检测。以下是目前支持的指标列表:
指标集 | 支持的指标 |
---|---|
vitals.anrrate |
anrRate |
vitals.crashrate |
crashRate |
vitals.excessivewakeuprate |
excessiveWakeupRate |
vitals.stuckbackgroundwakelockrate |
stuckBgWakelockRate |