You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API获取Google reCAPTCHA Enterprise API的请求次数?

获取GCP API请求次数的可用API

当然可以,你可以通过Cloud Monitoring API获取GCP控制台展示的API请求次数数据——控制台的请求统计本身就基于Cloud Monitoring的监控指标。

核心说明

  • 对应的监控指标为requests,不同GCP服务的指标名称带有服务前缀,比如:
    • Compute Engine API:compute.googleapis.com/api/requests
    • Cloud Storage API:storage.googleapis.com/api/requests
    • 其他服务的指标可直接在GCP Cloud Monitoring的指标库中搜索查询

获取数据的方式

使用Cloud Monitoring API的timeSeries.list方法,指定以下关键参数:

  1. 指标类型(metric.type):对应服务的requests指标
  2. 时间范围:设置为目标时间段(比如过去24小时)
  3. 聚合方式:选择求和(ALIGN_SUM)来获取总请求次数

示例gcloud命令(替代API调用的便捷方式)

gcloud monitoring time-series list \
    --filter='metric.type="YOUR_SERVICE_API_REQUESTS_METRIC"' \
    --aggregation-alignment-period=24h \
    --aggregation-per-series-aligner=ALIGN_SUM \
    --start-time=$(date -u -d "24 hours ago" +%Y-%m-%dT%H:%M:%SZ) \
    --end-time=$(date -u +%Y-%m-%dT%H:%M:%SZ)

将YOUR_SERVICE_API_REQUESTS_METRIC替换为对应服务的指标名称即可。

权限要求

需要拥有monitoring.timeSeries.list权限,通常分配Monitoring Viewer角色即可满足需求。

内容的提问来源于stack exchange,提问作者Joshua Swink

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:42:32