0

我正在通过 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()

并在邮递员 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

我不知道如何解决这个问题,请帮助我,因为我是这个谷歌云 API 和 python 的新手。谢谢

4

1 回答 1

1

“单位”字段表示度量正在计算的资源类型。对于字节,它是“By”。读这个。我知道它总是被退回,所以没有办法不收到它;我建议您调整代码以正确处理其在响应中的外观。

于 2020-07-09T15:18:49.207 回答