我正在通过 google timeseries api 读取监控数据。该 api 工作正常,如果给定对齐周期 = 3600s,它会为我提供任何度量类型的开始时间和结束时间之间的时间序列值
我像这样通过python调用它
service.projects().timeSeries().list(
name=api_args["project_name"],
filter=api_args["metric_filter"],
aggregation_alignmentPeriod=api_args["aggregation_alignment_period"],
# aggregation_crossSeriesReducer=api_args["crossSeriesReducer"],
aggregation_perSeriesAligner=api_args["perSeriesAligner"],
aggregation_groupByFields=api_args["group_by"],
interval_endTime=api_args["end_time_str"],
interval_startTime=api_args["start_time_str"],
pageSize=config.PAGE_SIZE,
pageToken=api_args["nextPageToken"]
).execute()
我在这里遇到一个问题
{
"metric": {
"labels": {
"instance_name": "insta-demo1",
"loadbalanced": "false"
},
"type": "compute.googleapis.com/instance/network/received_bytes_count"
},
"resource": {
"type": "gce_instance",
"labels": {
"instance_id": "1234343552",
"zone": "us-central1-f",
"project_id": "my-project"
}
},
"metricKind": "DELTA",
"valueType": "INT64",
"points": [
{
"interval": {
"startTime": "2020-07-04T16:30:01.497Z",
"endTime": "2020-07-04T17:30:01.497Z"
},
"value": {
"int64Value": "6720271"
}
}
]
},
{
"metric": {
"labels": {
"loadbalanced": "true",
"instance_name": "insta-demo2"
},
"type": "compute.googleapis.com/instance/network/received_bytes_count"
},
"resource": {
"type": "gce_instance",
"labels": {
"instance_id": "1234566343",
"project_id": "my-project",
"zone": "us-central1-f"
}
},
"metricKind": "DELTA",
"valueType": "INT64",
"points": [
{
"interval": {
"startTime": "2020-07-04T16:30:01.497Z",
"endTime": "2020-07-04T17:30:01.497Z"
},
"value": {
"int64Value": "579187"
}
}
]
}
],
"unit": "By". //This "By" is the value which is causing problem,
我得到这个值,比如“unit”:“By”或“unit”:“ms”或类似的东西,如果我没有找到任何数据的范围我得到这个值,因为我正在评估这个响应在python中我得到了key error
,因为没有名为“unit”的键
logMessage: "Key Error: ' '"
severity: "ERROR"
As the response is empty I am getting the single key called "unit" . Also at the end of any response I am getting this "unit":"ms" or "unit":"by" is there any way to prevent that unit value coming in the response
我不知道如何解决这个问题,请帮助我,因为我是这个谷歌云 API 和 python 的新手。谢谢