flink内部计算指标的95线-99线等的实现

本文介绍了如何在Flink中实现API监控系统的95线和99线计算,回顾了15年在电商领域的监控系统设计,并分享了18年的相关文章思路。提供了一份2018年的大数据学习资料,同时欢迎讨论优化方案,特别是针对StringBuilder的GC友好改进。
摘要由CSDN通过智能技术生成

15年在某电商从0设计了一个通用的API监控系统,当时只是计算了成功率+平均耗时,没有算75,90,95,99,999,9999线,这次单位需要,所以促使我去思考这个问题,问了单位CAT维护人员,大致了解了计算方式,跟我在18年7月份在单位内网BBS发表的文章思路是一致的,所以就直接写了下面的代码

PercentageCalculation.java

package com.ymm.computation.udf.define;

import org.apache.flink.table.functions.AggregateFunction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//批量计算95line类似的数据
public class PercentageCalculation extends AggregateFunction<Object, PercentageAccumulator> {

    /**  */
    private static final long   serialVersionUID = 4009559061130131166L;
    private static final Logger LOG              = LoggerFactory
        .getLogger(PercentageCalculation.class);
    //private static BlockingQueue<PercentageAggregatorContainer> GLOBAL_QUEUE     = new LinkedBlockingQueue<PercentageAggregatorContainer>();

    @Override
    public PercentageAccumulator createAccumulator() {
        return new PercentageAccumulator();
    }

    public void accumulate(PercentageAccumulator accumulator, Object value) {
        accumulator.accumulate(value);
    }

    @Override
    public Object getValue(PercentageAccumulator accumulator) {
        return accumulator.getValue();
    }

    public void resetAccumulator(PercentageAccumulator acc) {
        acc = null;//help GC
    }

}

 

整理了一份2018年合适程序员学习的大数据的学习资料需要的加群QQ群:834325294 注明CSDN既可免费获取

点击这里就可以加群哦

PercentageAccumulator.java

package com.ymm.computation.udf.define;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//!只针对时间来计算95线等,其它参数不要使用本类
public class PercentageAccumulator {

    private static final Logger LOG            = LoggerFactory
        .getLogger(PercentageAccumulator.class);

    public final static double  PERCENT_50     = 0.5;

    public final static double  PERCENT_75     = 0.25;

    public final static double  PERCENT_90     = 0.1;

    public final static double  PERCENT_95     = 0.05;

    public final static double  PERCENT_99     = 0.01;

    public final static double  PERCENT_999    = 0.001;

    public final static double  PERCE
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值