文档

实时数据导出API升级说明

更新时间:

实时数据导出API由2021-11-01版升级到2019-01-01版。本文为您介绍实时数据导出API的升级原因、升级说明和升级差异。

升级原因

实时数据导出API由2021-11-01版升级到2019-01-01版的原因如下:

  • 直接使用2019-01-01版SDK包即可,无需另外引入2021-11-01版SDK包,简化操作。

  • API设计更加规范,数据容量不受限且稳定性高。

  • 支持更多接入点(Endpoint),目前已支持上海、杭州、深圳、新加坡和上海金融云。2021-11-01版仅支持上海。

  • 支持资源目录等新特性。

升级说明

实时数据导出API由2021-11-01版升级到2019-01-01版的主要变更如下:

  • SDK包

  • 接入地址(Endpoint)

  • API名称由BatchGet修改为BatchExport。

  • 请求参数中的Matcher结构变更,返回数据变更。

升级差异

SDK包

2019-01-01版

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>cms20190101</artifactId>
    <version><SDK包的最新版本></version>
</dependency>

2021-11-01版

<dependency>
  	<groupId>com.aliyun</groupId>
  	<artifactId>cms_export20211101</artifactId>
  	<version><SDK包的最新版本></version>
</dependency>

请您获取云监控SDK包的最新版本,具体操作如下:

  1. 单击Cursor

  2. OpenAPI页面的SDK示例页签,将鼠标移至SDK依赖信息

    SDK依赖信息对话框,您可以查看SDK包名称和SDK最新版本。SDK_2019

Cursor代码示例

2019-01-01版

private static Config config = null;
private static Config getConfig(Config config){
  config = new Config();
  config.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"));
  config.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
  config.setEndpoint("metrics.cn-hangzhou.aliyuncs.com");
  return config;
}
private static String getCursor() throws Exception {
    Client client = new Client(getConfig(config));
    CursorRequest cursorRequest = new CursorRequest();
    cursorRequest.setNamespace("acs_ecs_dashboard");
    cursorRequest.setMetric("CPUUtilization");
    cursorRequest.setPeriod(60);
    cursorRequest.setStartTime(System.currentTimeMillis() - 60 * 60 * 1000);
    cursorRequest.setEndTime(Long.MAX_VALUE);
  	List<Matcher> matchers = new ArrayList<>();
  	Matcher matcher = new Matcher();
  	matcher.setLabel("userId");
    matcher.setValue("173651113438****");
  	matcher.setOperator("EQUALS");
  	matchers.add(matcher);
    cursorRequest.setMatchers(matchers);
    CursorResponse cursorResponse = client.cursor(cursorRequest);
    if (cursorResponse == null || cursorResponse.getBody() == null || cursorResponse.getBody().getCursor() == null) {
      return null;
    }
    return cursorResponse.getBody().getCursor();
}

2021-11-01版

private static Config config = null;
private static Config getConfig(Config config){
  config = new Config();
  config.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"));
  config.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
  config.setRegionId("cn-shanghai");
  config.setEndpoint("cms-export.cn-shanghai.aliyuncs.com");
  return config;
}
private static String getCursor() throws Exception {
    Client client = new Client(getConfig(config));
    CursorRequest cursorRequest = new CursorRequest();
    cursorRequest.setNamespace("acs_ecs_dashboard");
    cursorRequest.setMetric("CPUUtilization");
    cursorRequest.setPeriod(60);
    cursorRequest.setStartTime(System.currentTimeMillis() - 60 * 60 * 1000);
    cursorRequest.setEndTime(Long.MAX_VALUE);
    CursorRequest.CursorRequestMatchers matcher = new CursorRequest.CursorRequestMatchers();
    matcher.setLabel("userId").setOperator("EQUALS").setValue("173651113438****");
    List<CursorRequest.CursorRequestMatchers> chain = new ArrayList<>();
    chain.add(matcher);
    cursorRequest.setMatchers(chain);
    CursorResponse cursorResponse = client.cursor(cursorRequest);
    if (cursorResponse == null || cursorResponse.getBody() == null || cursorResponse.getBody().getData() == null || cursorResponse.getBody().getData().cursor == null) {
      return null;
    }
    return cursorResponse.getBody().getData().cursor;
}

差异说明

筛选条件的类由CursorRequest.CursorRequestMatchers修改为Matcher,内部参数无变化。

BatchExport和BatchExport代码示例

2019-01-01版BatchExport

private static String BatchExport(String cursor) throws Exception {
    Client client = new Client(getConfig(config));
    BatchExportRequest request = new BatchExportRequest();
    request.setNamespace("acs_ecs_dashboard");
    request.setMetric("CPUUtilization");
    request.setCursor(cursor);
    request.setLength(1000);
    BatchExportResponse response = client.batchExport(request);
    if (response == null || response.getBody() == null) {
      return null;
    }else {
      String json = JSON.toJSONString(response.getBody());
      return json;
    }
}

2021-11-01版BatchGet

private static String BatchGet(String cursor) throws Exception {
    Client client = new Client(getConfig(config));
    BatchGetRequest batchGetRequest = new BatchGetRequest();
    batchGetRequest.setNamespace("acs_ecs_dashboard");
    batchGetRequest.setMetric("CPUUtilization");
    batchGetRequest.setCursor(cursor);
    batchGetRequest.setLength(1000);
    BatchGetResponse batchGetResponse = client.batchGet(batchGetRequest);
    if (batchGetResponse == null || batchGetResponse.getBody() == null
        || batchGetResponse.getBody().getData() == null) {
      return null;
    }else {
      String json = JSON.toJSONString(batchGetResponse.getBody().getData().records);
      return json;
    }
}

差异说明

  • API名称由BatchGet修改为BatchExport。

  • BatchExport的Response的数据格式及字段变更,您获取数据时需要进行修改。

    response.getBody()获取数据格式示例如下,请您根据所需查询目标参。

    {
     	"cursor":"***", //返回下次调用的cursor。
    		"code":200, //返回本地调用的结果code。
    		"length":1 //数据长度。
    		"dataResults": // 返回的监控指标数据列表。
    		[{
    			"associated":{},
    			"dimensions":[{"label":"userId","value":"***"},{"label":"instanceId","value":"***"}],
    			"measurements":{"Maximum":***,"Average":***},
    			"metric":"***",
    			"namespace":"***",
    			"period":60,
    			"timestamp":1687760100000
    		 }]
     	"hasNext":true //是否需要继续查询。
     	"success":true //操作是否成功。
    }{
     	"cursor":"***", //返回下次调用的cursor。
    		"code":200, //返回本地调用的结果code。
    		"length":1 //数据长度。
    		"dataResults": // 返回的监控指标数据列表。
    		[{
    			"associated":{},
    			"dimensions":[{"label":"userId","value":"***"},{"label":"instanceId","value":"***"}],
    			"measurements":{"Maximum":***,"Average":***},
    			"metric":"***",
    			"namespace":"***",
    			"period":60,
    			"timestamp":1687760100000
    		 }]
     	"hasNext":true //是否需要继续查询。
     	"success":true //操作是否成功。
    }

  • 本页导读 (1)
文档反馈