Query Data API
Updated at:2025-11-03
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 |
|---|---|---|---|---|
| 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](BCM/API Reference/General Description.md#Date and time regulations), expressed in UTC date | Query start time | Yes | Query |
| endTime | DateTime, refer to [Date and Time](BCM/API Reference/General Description.md#Date and time regulations), 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
Java
1 // params definition
2 String endpoint = "http://bj.bcm.baidubce.com";
3 String userId = "fakeuser1ba678asdf8as7df6a5sdf67";
4 String ak = "ak";
5 String sk = "sk";
6 String scope = "BCE_BCC";
7 String metricName = "vCPUUsagePercent";
8 String dimensions = "InstanceId:fakeid-2222-8888-1111-13a8469b1fb2";
9 Statistics[] statistics = new Statistics[]{Statistics.average,Statistics.maximum};
10 long now = System.currentTimeMillis();
11 String startTime = DateUtils.formatAlternateIso8601Date(new Date(now - 60 * 60 * 1000));
12 String endTime = DateUtils.formatAlternateIso8601Date(new Date(now));
13 int periodInSecond = 60;
14 // create a bcm client
15 BcmClientConfiguration config = new BcmClientConfiguration();
16 config.setCredentials(new DefaultBceCredentials(ak, sk));
17 config.setEndpoint(endpoint);
18 BcmClient bcmClient = new BcmClient(config);
19 // query metric data from bcm interface
20 MetricDataRequest request = new MetricDataRequest();
21 request.withUserId(userId)
22 .withScope(scope)
23 .withDimensions(dimensions)
24 .withMetricName(metricName)
25 .withStatistics(statistics)
26 .withStartTime(startTime)
27 .withEndTime(endTime)
28 .withPeriodInSecond(periodInSecond);
29 MetricDataResponse response = bcmClient.getMetricData(request);
30 System.out.println(JsonUtils.toJsonString(response));
