2021-07-29 10:02:31 +08:00
|
|
|
package com.zdjizhi.sink;
|
|
|
|
|
|
|
|
|
|
import com.zdjizhi.common.CommonConfig;
|
|
|
|
|
import com.zdjizhi.common.DosEventLog;
|
|
|
|
|
import com.zdjizhi.common.DosMetricsLog;
|
|
|
|
|
import com.zdjizhi.common.DosSketchLog;
|
|
|
|
|
import com.zdjizhi.etl.DosDetection;
|
2021-08-05 18:42:34 +08:00
|
|
|
import com.zdjizhi.etl.EtlProcessFunction;
|
2021-07-29 10:02:31 +08:00
|
|
|
import com.zdjizhi.etl.ParseSketchLog;
|
|
|
|
|
import com.zdjizhi.utils.FlinkEnvironmentUtils;
|
|
|
|
|
import org.apache.flink.api.java.functions.KeySelector;
|
2022-09-23 18:37:33 +08:00
|
|
|
import org.apache.flink.api.java.tuple.Tuple3;
|
2021-07-29 10:02:31 +08:00
|
|
|
import org.apache.flink.streaming.api.datastream.*;
|
|
|
|
|
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
|
|
|
|
|
import org.apache.flink.streaming.api.windowing.time.Time;
|
|
|
|
|
import org.apache.flink.util.OutputTag;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author 94976
|
|
|
|
|
*/
|
|
|
|
|
public class OutputStreamSink {
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(OutputStreamSink.class);
|
|
|
|
|
|
|
|
|
|
public static OutputTag<DosMetricsLog> outputTag = new OutputTag<DosMetricsLog>("traffic server ip metrics"){};
|
|
|
|
|
|
|
|
|
|
public static void finalOutputSink(){
|
2021-07-30 10:55:01 +08:00
|
|
|
try {
|
|
|
|
|
SingleOutputStreamOperator<DosSketchLog> middleStream = getMiddleStream();
|
2021-08-18 19:15:49 +08:00
|
|
|
DosEventSink.dosEventOutputSink(getEventSinkStream(middleStream));
|
2021-07-30 10:55:01 +08:00
|
|
|
TrafficServerIpMetricsSink.sideOutputMetricsSink(middleStream);
|
|
|
|
|
FlinkEnvironmentUtils.streamExeEnv.execute(CommonConfig.STREAM_EXECUTION_JOB_NAME);
|
|
|
|
|
} catch (Exception e) {
|
2021-08-04 16:30:13 +08:00
|
|
|
logger.error("任务启动失败 {}",e);
|
2021-07-30 10:55:01 +08:00
|
|
|
}
|
2021-07-29 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
2021-08-18 19:15:49 +08:00
|
|
|
private static SingleOutputStreamOperator<DosEventLog> getEventSinkStream(SingleOutputStreamOperator<DosSketchLog> middleStream){
|
2022-09-23 18:37:33 +08:00
|
|
|
return middleStream.process(new DosDetection()).setParallelism(CommonConfig.FLINK_DETECTION_MAP_PARALLELISM);
|
2021-07-29 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static SingleOutputStreamOperator<DosSketchLog> getMiddleStream(){
|
|
|
|
|
return ParseSketchLog.getSketchSource()
|
2021-08-18 19:15:49 +08:00
|
|
|
.keyBy(new KeysSelector())
|
2021-07-29 10:02:31 +08:00
|
|
|
.window(TumblingEventTimeWindows.of(Time.seconds(CommonConfig.FLINK_WINDOW_MAX_TIME)))
|
2021-08-02 18:11:29 +08:00
|
|
|
.process(new EtlProcessFunction())
|
|
|
|
|
.setParallelism(CommonConfig.FLINK_FIRST_AGG_PARALLELISM);
|
2021-07-29 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
|
2022-09-23 18:37:33 +08:00
|
|
|
private static class KeysSelector implements KeySelector<DosSketchLog, Tuple3<String, String, Integer>>{
|
2021-07-29 10:02:31 +08:00
|
|
|
@Override
|
2022-09-23 18:37:33 +08:00
|
|
|
public Tuple3<String, String, Integer> getKey(DosSketchLog dosSketchLog){
|
|
|
|
|
return Tuple3.of(
|
2021-07-29 10:02:31 +08:00
|
|
|
dosSketchLog.getAttack_type(),
|
2022-09-23 18:37:33 +08:00
|
|
|
dosSketchLog.getDestination_ip(),
|
|
|
|
|
dosSketchLog.getVsys_id());
|
2021-07-29 10:02:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|