// create a bcm clientString endpoint ="bcm.bj.baidubce.com";String userId ="fakeuser1ba678asdf8as7df6a5sdf67";String ak ="ak";String sk ="sk";BcmClientConfiguration config =newBcmClientConfiguration();
config.setCredentials(newDefaultBceCredentials(ak, sk));
config.setEndpoint(endpoint);BcmClient client =newBcmClient(config);// push custom metric data with value and no dimensionPushCustomMetricDataRequest request =PushCustomMetricDataRequest.builder().userId(userId).namespace("test_wang").metricName("test_api_no_dimension").value(10.0).timestamp(DateUtils.formatAlternateIso8601Date(newDate(System.currentTimeMillis()-10*60*1000))).build();PushMetricDataResponse response = client.pushCustomMonitorMetricData(request);System.out.println(JsonUtils.toJsonString(response));// push custom metric data with statistic value and dimensionList<Dimension> dimensions =newArrayList<>();
dimensions.add(newDimension().withName("dimension1").withValue("d1"));
dimensions.add(newDimension().withName("dimension2").withValue("d2"));StatisticValue value =StatisticValue.builder().maximum(1.0).minimum(2.0).sum(3.0).sampleCount(1).average(4.0).build();
request =PushCustomMetricDataRequest.builder().userId(userId).namespace("test_wang").metricName("test_api_time").dimensions(dimensions).statisticValues(value).timestamp(DateUtils.formatAlternateIso8601Date(newDate(System.currentTimeMillis()-10*60*1000))).build();
response = client.pushCustomMonitorMetricData(request);System.out.println(JsonUtils.toJsonString(response));