开发者社区 问答 正文

CID 投递统计该怎么做?

OnsTrendGroupOutputTps 接口可以查询指定 Consumer ID 在一段时间内获消费消息的统计信息。

使用场景

线上环境生成消费数据报表时,可以根据该接口查询消费消息的数量或者 TPS 统计。

查询场景:

查询消费总量曲线的统计
查询消费 TPS 曲线的统计
如果应用方消息量比较小,间隔不均匀,此时采用 TPS 查询可能会导致数据不明显,建议使用总量查询。

请求参数列表

名称    类型    是否必须    描述
OnsRegionId    String    是    当前查询 MQ 所在区域,可以通过 OnsRegionList 方法获取
OnsPlatform    String    否    该请求来源,默认是从 POP 平台
PreventCache    Long    是    用于 CSRF 校验,设置为系统当前时间即可
Topic    String    是    需要查询的 Topic 名称
ConsumerId    String    是    需要查询的 CID 名称
BeginTime    Long    是    查询区间起始毫秒时间戳
EndTime    Long    是    查询区间终止毫秒时间戳
Period    Long    是    采样周期,单位分钟,支持(1,5,10)
Type    Integer    是    查询的类型(0代表总量,1代表TPS)
返回参数列表

名称    类型    描述
RequestId    String    为公共参数,每个请求独一无二
HelpUrl    String    帮助链接
data    Data    数据集合
Data 数据集定义

名称    类型    描述
Title    String    table 的名称
Records    List(StatsDataDo)    采集点信息
StatsDataDo 数据集定义

名称    类型    描述
X    Long    横轴,毫秒时间戳
Y    Float    纵轴,数据(TPS 或者总量)
相关 API

OnsTrendTopicInputTps:查询消息写入的统计信息
使用示例

        public static void main(String []args) {
            String regionId = "cn-hangzhou";
            String accessKey = "XXXXXXXXXXXXXXXXX";
            String secretKey = "XXXXXXXXXXXXXXXXX";
            String endPointName ="cn-hangzhou";
            String productName ="Ons";
            String domain ="ons.cn-hangzhou.aliyuncs.com";
            /**
            *根据自己需要访问的区域选择Region,并设置对应的接入点
            */
            try {
                DefaultProfile.addEndpoint(endPointName,regionId,productName,domain);
            } catch (ClientException e) {
                e.printStackTrace();
            }
            IClientProfile profile= DefaultProfile.getProfile(regionId,accessKey,secretKey);
            IAcsClient iAcsClient= new DefaultAcsClient(profile);
            OnsTrendGroupOutputTpsRequest request =new OnsTrendGroupOutputTpsRequest();
            request.setOnsRegionId("cn-qingdao-publictest");
            request.setPreventCache(System.currentTimeMillis());
            request.setAcceptFormat(FormatType.JSON);
            request.setTopic("MingduanTestAPI");
            request.setConsumerId("CID_Mingduan");
            request.setBeginTime(System.currentTimeMillis()-4*3600*1000);
            request.setEndTime(System.currentTimeMillis());
            request.setPeriod(1);
            request.setType(0);
            try {
                OnsTrendGroupOutputTpsResponse response =iAcsClient.getAcsResponse(request);
                OnsTrendGroupOutputTpsResponse.Data data =response.getData();
                System.out.println(data.getTitle()+"\n"+
                data.getRecords());
            } catch (ClientException e) {
                e.printStackTrace();
            }

展开
收起
猫饭先生 2017-10-27 13:44:08 1717 分享 版权
0 条回答
写回答
取消 提交回答
问答分类:
问答地址: