2024-09-29 23:16:51 发布
网友
我想获取https/backend\u request\u count指标
https://cloud.google.com/monitoring/api/metrics_gcp?hl=ja#loadbalancing/https/backend_request_count
有可能通过python获得它吗
是的,这是可能的。我遵循这个reading metric document并使用后端请求计数对其进行过滤
我所做的是获得过滤器,然后Google Cloud Metrics backend_request_count构建过滤器
The "metric type" strings in this table must be prefixed with loadbalancing.googleapis.com/. That prefix has been omitted from the entries in the table.
按照上述说明,过滤器如下所示:
metric.type = "loadbalancing.googleapis.com/https/backend_request_count"
在代码中应用此过滤器,代码将如下所示:
from google.cloud import monitoring_v3 import time client = monitoring_v3.MetricServiceClient() ## Don't forget to replace this dummy project_id with your actual project_id ## project_name = f"projects/your-project-id-here" interval = monitoring_v3.TimeInterval() now = time.time() seconds = int(now) nanos = int((now - seconds) * 10 ** 9) interval = monitoring_v3.TimeInterval( { "end_time": {"seconds": seconds, "nanos": nanos}, "start_time": {"seconds": (seconds - 1200), "nanos": nanos}, } ) results = client.list_time_series( request={ "name": project_name, "filter": 'metric.type = "loadbalancing.googleapis.com/https/backend_request_count"', "interval": interval, "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL, } ) for result in results: print(result)
这将产生一个ListTimeSeriesResponse,下面是上面代码的片段响应
是的,这是可能的。我遵循这个reading metric document并使用后端请求计数对其进行过滤
我所做的是获得过滤器,然后Google Cloud Metrics backend_request_count构建过滤器
按照上述说明,过滤器如下所示:
在代码中应用此过滤器,代码将如下所示:
这将产生一个ListTimeSeriesResponse,下面是上面代码的片段响应
相关问题 更多 >
编程相关推荐