From 9bda526d482a81df64f092e28751350ff519d04f Mon Sep 17 00:00:00 2001
From: wanglihui <949764788@qq.com>
Date: Tue, 17 Aug 2021 11:09:45 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A4=E5=AE=9A=E8=B6=85?=
=?UTF-8?q?=E5=87=BA=E5=9F=BA=E7=BA=BF=E7=99=BE=E5=88=86=E6=AF=94=E9=80=BB?=
=?UTF-8?q?=E8=BE=91bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 19 +------------------
.../java/com/zdjizhi/etl/DosDetection.java | 16 ++++++++++------
2 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/pom.xml b/pom.xml
index 89029f4..d44c210 100644
--- a/pom.xml
+++ b/pom.xml
@@ -118,7 +118,7 @@
org.apache.flink
flink-sql-connector-kafka_2.11
${flink.version}
-
+ provided
@@ -128,23 +128,6 @@
-
-
-
-
-
-
-
-
-
-
- org.apache.flink
- flink-json
- ${flink.version}
- provided
-
-
-
org.apache.kafka
diff --git a/src/main/java/com/zdjizhi/etl/DosDetection.java b/src/main/java/com/zdjizhi/etl/DosDetection.java
index 4f3c7b5..453b72c 100644
--- a/src/main/java/com/zdjizhi/etl/DosDetection.java
+++ b/src/main/java/com/zdjizhi/etl/DosDetection.java
@@ -43,10 +43,9 @@ public class DosDetection extends RichMapFunction {
if (baseline != null && baseline.size() == BASELINE_SIZE){
int timeIndex = getCurrentTimeIndex(value.getSketch_start_time());
Integer base = baseline.get(timeIndex);
- long sketchSessions = value.getSketch_sessions();
- long diff = sketchSessions - base;
+ long diff = value.getSketch_sessions() - base;
if (diff > 0){
- String percent = getDiffPercent(diff, sketchSessions);
+ String percent = getDiffPercent(diff, base);
double diffPercentDouble = getDiffPercentDouble(percent);
Severity severity = judgeSeverity(diffPercentDouble);
if (severity != Severity.NORMAL){
@@ -105,10 +104,15 @@ public class DosDetection extends RichMapFunction {
return Integer.parseInt(Long.toString(indexLong));
}
- private String getDiffPercent(long diff,long sketchSessions){
+ private String getDiffPercent(long diff,long base){
double diffDou = Double.parseDouble(Long.toString(diff));
- double sessDou = Double.parseDouble(Long.toString(sketchSessions));
- return PERCENT_INSTANCE.format(diffDou / sessDou);
+ double baseDou = Double.parseDouble(Long.toString(base));
+ return PERCENT_INSTANCE.format(diffDou / baseDou);
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println(new DosDetection().getDiffPercent(219, 0));
+ System.out.println(new DosDetection().getDiffPercentDouble("∞%"));
}
private double getDiffPercentDouble(String diffPercent) throws ParseException {