百度智能云

All Product Document

          Cloud Monitor

          Query Data API

          API description

          Retrieve Time Series data for one or more statistics based on specified Metrics, including Cloud Product Monitor data, Site Monitor data, or Custom Monitor data that you have uploaded.

          API restriction

          The number of DataPoints returned in a single response cannot exceed 1,440.

          Request structure

          • Method: GET
          • URL: /json-api/v1/metricdata/{userid}/{scope}/{metricName}?{Query}
          • Query: dimensions={dimensions}&statistics[]={statistics1,statistics2,statistics3...}&periodInSecond={periodInSecond}&startTime={startTime}&endTime={endTime}

          Request parameters

          Name Types Description Required or not Parameter location
          userId String Tenant ID Yes URL parameter
          scope String, limited to the following character set: 0~9, A~Z, a~z, _ Scope Yes URL parameter
          metricName String, limited to the following character set: 0~9, A~Z, a~z, _ Monitor Metric name Yes URL parameter
          statistics[] Statistics, in statistics1, statistics2, statistics3 format, options: average, maximum, minimum, sum, sampleCount Statistic Method Type Yes Query
          dimensions A string formatted as dimensionName:dimensionValue. For Metrics with multiple Dimensions, connect them using semicolons, e.g., dimensionName:dimensionValue;dimensionName:dimensionValue. Each dimension can have only one specified value. Dimension list Yes Query
          startTime DateTime, refer to Date and Time, expressed in UTC date Query start time Yes Query
          endTime DateTime, refer to Date and Time, expressed in UTC date Query end time Yes Query
          periodInSecond Integer, multiple of 60, unit: second (s) Statistical Period Yes Query

          Parameter explanation

          • For concepts like Scope, Metric, Statistic, and Dimension, refer to [Core Concepts](BCM/Product Description/Core concepts.md).

          Response parameters

          Name Types Description
          requestId String Request identifier
          code String Return code
          message String Error message
          dataPoints List(DataPoint) Monitor Metric

          DataPoint

          Name Types Description
          average double Average of Metrics within the statistical period
          sum double Sum of Metrics within the statistical period
          minimum double Minimum value of Metrics within the statistical period
          maximum double Maximum value of Metrics within the counting cycle
          sampleCount Integer Number of DataPoints for the Metric within the statistical period
          timestamp DateTime, refer to [Date and Time](BCM/API Reference/General Description.md#Date and time regulations), expressed in UTC date Time corresponding to the statistical period of Metric

          Request example

          For clarity, the request example has been line-wrapped. In actual request construction, the URL path and query parameters should be written on a single line.

          GET  /json-api/v1/metricdata/fakeuser1ba678asdf8as7df6a5sdf67/BCE_BCC/CpuIdlePercent?
          dimensions=InstanceId:fakeid-2222-8888-1111-13a8469b1fb2
          &statistics[]=average,maximum,minimum
          &periodInSecond=60
          &startTime=2019-04-16T13:55:01Z
          &endTime=2019-04-16T14:00:01Z
          HTTP/1.1
          Host:bcm.bj.baidubce.com:80  

          Response example

          Successful response example

          When querying data, include the statistics\[] parameter, which determines the attributes for each dataPoint in the response.

          When statistics[]=average, the response result example is as follows:

          HTTP/1.1 200 OK
          x-bce-request-id: dwegvad4-dwea-4d3dsa-8ew2-4b7263fs1ecd
          Content-Type: application/json;charset=UTF-8
          {
              "requestId": "17f101a7-67a8-4c2e-93d7-60c0d4a21f0c",
              "code": "OK",
              "message": "OK",
              "dataPoints": [
                  {
                      "average": 2.24,
                      "timestamp": "2019-04-16T13:55:01Z"
                  },
                  {
                      "average": 0.22,
                      "timestamp": "2019-04-16T13:56:01Z"
                  },
                  {
                      "average": 0.19,
                      "timestamp": "2019-04-16T13:57:01Z"
                  },
                  {
                      "average": 0.18,
                      "timestamp": "2019-04-16T13:58:01Z"
                  },
                  {
                      "timestamp": "2019-04-16T13:59:01Z"
                  }
              ]
          }

          When statistics[]=average, sum, minimum, the response result example is as follows:

          HTTP/1.1 200 OK
          x-bce-request-id: dd00bad4-d22a-4d1c-8f12-4b513f0b91ec
          Content-Type: application/json;charset=UTF-8
          {
              "requestId": "dd00bad4-d22a-4d1c-8f12-4b513f0b91ec",
              "code": "OK",
              "message": "OK",
              "successList": [
                  {
                      "dataPoints": [
                          {
                              "average": 40359.0,
                              "sum": 80718.0,
                              ""minimum":39900.0,
                              "timestamp": "2019-04-23T00: 00: 00Z"
                          }
                      ]
                  }
              ]
          }

          Unsuccessful response example

          If your request is correctly structured but no corresponding monitoring data is found, or the input parameters are incorrect, BCM will return a 200 OK response code and provide details about the error in the response body.

          Case 1: No data found. No monitoring data exists under the specified user, Scope, Metric, and Dimension for the given time period.

          When this occurs, the corresponding time point will be returned, but without monitor data

          HTTP/1.1 200 OK
          x-bce-request-id: dd00bad4-d22a-4d1c-8f12-4b513f0b91ec
          Content-Type: application/json;charset=UTF-8
          {
              "requestId": "dd00bad4-d22a-4d1c-8f12-4b513f0b91ec",
              "code": "OK",
              "message": "OK",
              "successList": [
                  {
                      "dataPoints": [
                          {
                              "timestamp": "2019-04-23T00: 00: 00Z"
                          }
                      ]
                  }
              ]
          }

          Case 2: Incorrect parameters. The following example is missing the endTime parameter.

          HTTP/1.1 200 OK
          x-bce-request-id: dd00bad4-d22a-4d1c-8f12-4b513f0b91ec
          Content-Type: application/json;charset=UTF-8
          {
              "requestId": "dd00bad4-d22a-4d1c-8f12-4b513f0b91ec",
              "code": "INVALID_PARAMETER",
              "message": "Required endTime parameter String is not present"
          }

          The example below demonstrates an incorrect format for Dimension parameter values.

          HTTP/1.1 200 OK
          x-bce-request-id: dd00bad4-d22a-4d1c-8f12-4b513f0b91ec
          Content-Type: application/json;charset=UTF-8
          {
              "requestId": "dd00bad4-d22a-4d1c-8f12-4b513f0b91ec",
              "code": "INVALID_PARAMETER_VALUE",
              "message": "Wrong dimensions format, example: name:value;name:value"
          }
          Previous
          Push Data API
          Next
          Query Latest Metric Data for Partial Dimensions