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