百度智能云

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 parameters

          Name Types Description Required or not Parameter location
          user_id String Tenant ID Yes URL parameter
          scope String, limited to the following character set: 0~9, A~Z, a~z, _ Scope Yes URL parameter
          metric_name 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
          start_time DateTime, refer to Date and Time, expressed in UTC date Query start time Yes Query
          end_time DateTime, refer to Date and Time, expressed in UTC date Query end time Yes Query
          period_in_second 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
          request_id String Request identifier
          code String Return code
          message String Error message
          data_points List(data_point) Monitor Metric

          data_point

          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
          sample_count 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

              # params definition
              user_id = "fakeuser1ba678asdf8as7df6a5sdf67"
              scope = "BCE_BCC"
              metric_name = "vCPUUsagePercent"
              dimensions = "InstanceId:fakeid-2222-8888-1111-13a8469b1fb2"
              statistics = "average,maximum,minimum"
              start_time = "2019-04-16T13:55:01Z"
              end_time = "2019-04-16T14:00:01Z"
              period_in_second = 60
              # create a bcm client
              bcm_client = BcmClient(bcm_sample_conf.config)
              # query metric data from bcm interface
              try:
                  response = bcm_client.get_metric_data(user_id=user_id,
                                                        scope=scope,
                                                        metric_name=metric_name,
                                                        dimensions=dimensions,
                                                        statistics=statistics,
                                                        start_time=start_time,
                                                        end_time=end_time,
                                                        period_in_second=period_in_second)
                  print(response)
              except BceHttpClientError as e:
                  if isinstance(e.last_error, BceServerError):
                      __logger.error('send request failed. Response %s, code: %s, msg: %s'
                                     % (e.last_error.status_code, e.last_error.code, e.last_error.message))
                  else:
                      __logger.error('send request failed. Unknown exception: %s' % e)
          Previous
          Overview
          Next
          Query Latest Metric Data for Partial Dimensions