java接入监控数据_通过Java SDK上报监控数据(推荐)

上报原始数据 CMSClientInit.groupId = 101L;//设置公共的应用分组ID。

CMSClient cmsClient = new CMSClient(endpoint, accKey, secret);//初始化client。

CustomMetricUploadRequest request = CustomMetricUploadRequest.builder()

.append(CustomMetric.builder()

.setMetricName("testMetric")//指标名称。

.setGroupId(102L)//设置应用分组ID。

.setTime(new Date())

.setType(CustomMetric.TYPE_VALUE)//类型为原始值。

.appendValue(MetricAttribute.VALUE, 1f)//原始值,key只能是该value,不能自定义。

.appendDimension("key", "value")//添加维度。

.appendDimension("ip", "127.0.0.1")//添加维度。

.build())

.build();

CustomMetricUploadResponse response = cmsClient.putCustomMetric(request);//上报数据。

System.out.println(JSONObject.toJSONString(response));

上报聚合数据 CMSClientInit.groupId = 101L;

CMSClient cmsClient = new CMSClient(endpoint, accKey, secret);

CustomMetricUploadRequest request = CustomMetricUploadRequest.builder()

.append(CustomMetric.builder()

.setMetricName("customTest")

.setTime(new Date())

.setType(CustomMetric.TYPE_AGG)//类型为聚合。

.setPeriod(CustomMetric.PERIOD_1M)//周期为1分钟。

.appendDimension("test", "testValue")//设置维度。

.appendDimension("dimension", "dimensionValue")//设置维度。

.appendValue(MetricAttribute.SUM, 100)//设置求和。

.appendValue(MetricAttribute.MAX, 20)//设置最大值。

.appendValue(MetricAttribute.MIN, 0.1)//设置最小值。

.appendValue(MetricAttribute.COUNT, 20)//设置计数。

.appendValue(MetricAttribute.AVG, 5)//设置平均值。

.appendValue(MetricAttribute.LAST, 10)//设置周期最后一个值。

.appendValue(MetricAttribute.P50, 10)//设置P50。

.appendValue(MetricAttribute.P90, 17)//设置P90。

.appendValue(MetricAttribute.P99, 19)//设置P99。

.build())

.build();

CustomMetricUploadResponse response = cmsClient.putCustomMetric(request);

System.out.println(JSONObject.toJSONString(response));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值