在 google 中监视 api 给出 "By" 作为响应

monitoring api in google gives "By" as response

我正在通过 google 时间序列 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()

在邮递员中 https://monitoring.googleapis.com/v3/projects/my-project/timeSeries?pageSize=500&interval.startTime=2020-07-04T16%3A39%3A37.230000Z&aggregation.alignmentPeriod=3600s&aggregation.perSeriesAligner=ALIGN_SUM&filter=metric.type%3D%22compute.googleapis.com%2Finstance%2Fnetwork%2Freceived_bytes_count%22+&pageToken=&interval.endTime=2020-07-04T17%3A30%3A01.497Z&alt=json&aggregation.groupByFields=metric.labels.key

我遇到了一个问题

{
      "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

我不确定如何解决这个问题,请帮助我,因为我是这个 google 云 apis 和 python 的新手。谢谢

“单位”字段表示指标计算的资源种类。对于字节,它是“By”。阅读this。我知道它总是被退回,所以没有办法不收到它;我建议您调整代码以正确处理它在响应中的出现。