我正在尝试获取GCP SQL实例最近5分钟的CPU利用率,但得到以下错误。请帮我解决。我使用的服务帐户拥有对监控的完全读取权限。
我的脚本:
from google.cloud import monitoring_v3
from google.cloud.monitoring_v3 import query
credential_file = "/home/user/my-first-project.json"
GCP_SCOPES = [
'https://www.googleapis.com/auth/sqlservice.admin',
"https://www.googleapis.com/auth/logging.read",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/monitoring.read"
]
gcp_credential = service_account.Credentials.from_service_account_file(credential_file,scopes=GCP_SCOPES)
client = monitoring_v3.MetricServiceClient(credentials=gcp_credential)
project_name = f"projects/my-first-project"
cpu_query = query.Query(client,
project=project_name,
metric_type='cloudsql.googleapis.com/database/cpu/utilization',
minutes=5)
next(cpu_query.iter())
错误:
File "$PATH\grpc_helpers.py", line 75, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.PermissionDenied: 403 Permission monitoring.timeSeries.list denied (or the resource may not exist).
发布于 2021-09-09 10:11:42
删除前缀"projects/“起作用了。因此,基本上使用项目id而不是project_name是可行的。
cpu_query = query.Query(
client,
project="my-first-project",
metric_type='cloudsql.googleapis.com/database/cpu/utilization',
minutes=5
)
https://stackoverflow.com/questions/69083095
复制相似问题