Compare commits
15 Commits
ip-learnin
...
ip-learnin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60d688f289 | ||
|
|
57fd13d053 | ||
|
|
1017d8fe6c | ||
|
|
17ec1eff72 | ||
|
|
67c2dfd4d2 | ||
|
|
33c0d826ab | ||
|
|
6265bb5e90 | ||
|
|
a1589b4905 | ||
|
|
40e76754d0 | ||
|
|
b7a156b0b8 | ||
|
|
233cf20d50 | ||
|
|
b13fc2bce1 | ||
|
|
cbeba6372b | ||
|
|
1750549c7d | ||
|
|
5a039bb492 |
@@ -13,7 +13,8 @@ public class ApplicationConfig {
|
|||||||
public static final Integer ARANGODB_TTL = ConfigUtils.getIntProperty( "arangoDB.ttl");
|
public static final Integer ARANGODB_TTL = ConfigUtils.getIntProperty( "arangoDB.ttl");
|
||||||
public static final Integer ARANGODB_BATCH = ConfigUtils.getIntProperty( "arangoDB.batch");
|
public static final Integer ARANGODB_BATCH = ConfigUtils.getIntProperty( "arangoDB.batch");
|
||||||
|
|
||||||
public static final Integer UPDATE_ARANGO_BATCH =ConfigUtils.getIntProperty("update.arango.batch");
|
public static final Integer UPDATE_ARANGO_BATCH = ConfigUtils.getIntProperty("update.arango.batch");
|
||||||
|
public static final String ARANGODB_READ_LIMIT = ConfigUtils.getStringProperty("arangoDB.read.limit");
|
||||||
|
|
||||||
public static final Integer THREAD_POOL_NUMBER = ConfigUtils.getIntProperty( "thread.pool.number");
|
public static final Integer THREAD_POOL_NUMBER = ConfigUtils.getIntProperty( "thread.pool.number");
|
||||||
public static final Integer THREAD_AWAIT_TERMINATION_TIME = ConfigUtils.getIntProperty( "thread.await.termination.time");
|
public static final Integer THREAD_AWAIT_TERMINATION_TIME = ConfigUtils.getIntProperty( "thread.await.termination.time");
|
||||||
@@ -21,19 +22,11 @@ public class ApplicationConfig {
|
|||||||
public static final Long READ_CLICKHOUSE_MAX_TIME = ConfigUtils.getLongProperty("read.clickhouse.max.time");
|
public static final Long READ_CLICKHOUSE_MAX_TIME = ConfigUtils.getLongProperty("read.clickhouse.max.time");
|
||||||
public static final Long READ_CLICKHOUSE_MIN_TIME = ConfigUtils.getLongProperty("read.clickhouse.min.time");
|
public static final Long READ_CLICKHOUSE_MIN_TIME = ConfigUtils.getLongProperty("read.clickhouse.min.time");
|
||||||
|
|
||||||
public static final Integer CLICKHOUSE_TIME_LIMIT_TYPE = ConfigUtils.getIntProperty("clickhouse.time.limit.type");
|
public static final Integer TIME_LIMIT_TYPE = ConfigUtils.getIntProperty("time.limit.type");
|
||||||
public static final Integer UPDATE_INTERVAL = ConfigUtils.getIntProperty("update.interval");
|
public static final Integer UPDATE_INTERVAL = ConfigUtils.getIntProperty("update.interval");
|
||||||
|
|
||||||
public static final Integer DISTINCT_CLIENT_IP_NUM = ConfigUtils.getIntProperty("distinct.client.ip.num");
|
public static final Integer DISTINCT_CLIENT_IP_NUM = ConfigUtils.getIntProperty("distinct.client.ip.num");
|
||||||
public static final Integer RECENT_COUNT_HOUR = ConfigUtils.getIntProperty("recent.count.hour");
|
public static final Integer RECENT_COUNT_HOUR = ConfigUtils.getIntProperty("recent.count.hour");
|
||||||
|
|
||||||
public static final String TOP_DOMAIN_FILE_NAME = ConfigUtils.getStringProperty("top.domain.file.name");
|
|
||||||
|
|
||||||
public static final String ARANGODB_READ_LIMIT = ConfigUtils.getStringProperty("arangoDB.read.limit");
|
|
||||||
|
|
||||||
public static final Integer ARANGO_TIME_LIMIT_TYPE = ConfigUtils.getIntProperty("arango.time.limit.type");
|
|
||||||
|
|
||||||
public static final Long READ_ARANGO_MAX_TIME = ConfigUtils.getLongProperty("read.arango.max.time");
|
|
||||||
public static final Long READ_ARANGO_MIN_TIME = ConfigUtils.getLongProperty("read.arango.min.time");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,129 +0,0 @@
|
|||||||
package cn.ac.iie.dao;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import cn.ac.iie.service.read.ReadHistoryArangoData;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import cn.ac.iie.utils.ExecutorThreadPool;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取arangoDB历史数据
|
|
||||||
*
|
|
||||||
* @author wlh
|
|
||||||
*/
|
|
||||||
public class BaseArangoData {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BaseArangoData.class);
|
|
||||||
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexIpMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexSubscriberMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationFqdnAddressIpMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationIpVisitFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationFqdnSameFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationSubsciberLocateIpMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private static ArangoDBConnect arangoDBConnect = ArangoDBConnect.getInstance();
|
|
||||||
|
|
||||||
private ExecutorThreadPool threadPool = ExecutorThreadPool.getInstance();
|
|
||||||
|
|
||||||
<T extends BaseDocument> void readHistoryData(String table,
|
|
||||||
ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> historyMap,
|
|
||||||
Class<T> type) {
|
|
||||||
try {
|
|
||||||
LOG.info("开始更新" + table);
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++) {
|
|
||||||
historyMap.put(i, new ConcurrentHashMap<>());
|
|
||||||
}
|
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER);
|
|
||||||
// long[] timeRange = getTimeRange(table);
|
|
||||||
Long countTotal = getCountTotal(table);
|
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++) {
|
|
||||||
// String sql = getQuerySql(timeRange, i, table);
|
|
||||||
String sql = getQuerySql(countTotal, i, table);
|
|
||||||
ReadHistoryArangoData<T> readHistoryArangoData = new ReadHistoryArangoData<>(arangoDBConnect, sql, historyMap, type, table, countDownLatch);
|
|
||||||
threadPool.executor(readHistoryArangoData);
|
|
||||||
}
|
|
||||||
countDownLatch.await();
|
|
||||||
long last = System.currentTimeMillis();
|
|
||||||
LOG.info("读取" + table + " arangoDB 共耗时:" + (last - start));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private long[] getTimeRange(String table) {
|
|
||||||
long minTime = 0L;
|
|
||||||
long maxTime = 0L;
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
String sql = "LET doc = (FOR doc IN " + table + " RETURN doc) return {max_time:MAX(doc[*].FIRST_FOUND_TIME),min_time:MIN(doc[*].FIRST_FOUND_TIME)}";
|
|
||||||
switch (ApplicationConfig.ARANGO_TIME_LIMIT_TYPE) {
|
|
||||||
case 0:
|
|
||||||
ArangoCursor<BaseDocument> timeDoc = arangoDBConnect.executorQuery(sql, BaseDocument.class);
|
|
||||||
try {
|
|
||||||
if (timeDoc != null) {
|
|
||||||
while (timeDoc.hasNext()) {
|
|
||||||
BaseDocument doc = timeDoc.next();
|
|
||||||
maxTime = Long.parseLong(doc.getAttribute("max_time").toString()) + ApplicationConfig.THREAD_POOL_NUMBER;
|
|
||||||
minTime = Long.parseLong(doc.getAttribute("min_time").toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG.warn("获取ArangoDb时间范围为空");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
maxTime = ApplicationConfig.READ_ARANGO_MAX_TIME;
|
|
||||||
minTime = ApplicationConfig.READ_ARANGO_MIN_TIME;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
long lastTime = System.currentTimeMillis();
|
|
||||||
LOG.info(sql + "\n查询最大最小时间用时:" + (lastTime - startTime));
|
|
||||||
return new long[]{minTime, maxTime};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Long getCountTotal(String table){
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
Long cnt = 0L;
|
|
||||||
String sql = "RETURN LENGTH("+table+")";
|
|
||||||
try {
|
|
||||||
ArangoCursor<Long> longs = arangoDBConnect.executorQuery(sql, Long.class);
|
|
||||||
while (longs.hasNext()){
|
|
||||||
cnt = longs.next();
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
LOG.error(sql +"执行异常");
|
|
||||||
}
|
|
||||||
long last = System.currentTimeMillis();
|
|
||||||
LOG.info(sql+" 结果:"+cnt+" 执行时间:"+(last-start));
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getQuerySql(long[] timeRange, int threadNumber, String table) {
|
|
||||||
long minTime = timeRange[0];
|
|
||||||
long maxTime = timeRange[1];
|
|
||||||
long diffTime = (maxTime - minTime) / ApplicationConfig.THREAD_POOL_NUMBER;
|
|
||||||
long maxThreadTime = minTime + (threadNumber + 1) * diffTime;
|
|
||||||
long minThreadTime = minTime + threadNumber * diffTime;
|
|
||||||
return "FOR doc IN " + table + " filter doc.FIRST_FOUND_TIME >= " + minThreadTime + " and doc.FIRST_FOUND_TIME <= " + maxThreadTime + " " + ApplicationConfig.ARANGODB_READ_LIMIT + " RETURN doc";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getQuerySql(Long cnt,int threadNumber, String table){
|
|
||||||
long sepNum = cnt / ApplicationConfig.THREAD_POOL_NUMBER + 1;
|
|
||||||
long offsetNum = threadNumber * sepNum;
|
|
||||||
return "FOR doc IN " + table + " limit "+offsetNum+","+sepNum+" RETURN doc";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ import java.util.HashMap;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static cn.ac.iie.service.read.ReadClickhouseData.putMapByHashcode;
|
import static cn.ac.iie.service.ingestion.ReadClickhouseData.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取clickhouse数据,封装到map
|
* 读取clickhouse数据,封装到map
|
||||||
@@ -24,25 +24,22 @@ import static cn.ac.iie.service.read.ReadClickhouseData.putMapByHashcode;
|
|||||||
public class BaseClickhouseData {
|
public class BaseClickhouseData {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BaseClickhouseData.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BaseClickhouseData.class);
|
||||||
|
|
||||||
|
private static ClickhouseConnect manger = ClickhouseConnect.getInstance();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseDocument>>> newVertexFqdnMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String, ArrayList<BaseDocument>>> newVertexFqdnMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseDocument>>> newVertexIpMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String, ArrayList<BaseDocument>>> newVertexIpMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String,ArrayList<BaseDocument>>> newVertexSubscriberMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String,ArrayList<BaseDocument>>> newVertexSubscriberMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationFqdnAddressIpMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationFqdnAddressIpMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationIpVisitFqdnMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationIpVisitFqdnMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationSubsciberLocateIpMap = new HashMap<>();
|
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationSubsciberLocateIpMap = new HashMap<>();
|
||||||
static HashMap<Integer, HashMap<String, ArrayList<BaseEdgeDocument>>> newRelationFqdnSameFqdnMap = new HashMap<>();
|
|
||||||
|
|
||||||
private static ClickhouseConnect manger = ClickhouseConnect.getInstance();
|
|
||||||
private DruidPooledConnection connection;
|
private DruidPooledConnection connection;
|
||||||
private Statement statement;
|
private Statement statement;
|
||||||
|
|
||||||
<T extends BaseDocument> void baseDocumentFromClickhouse(HashMap<Integer, HashMap<String, ArrayList<T>>> newMap,
|
<T extends BaseDocument> HashMap<Integer, HashMap<String,ArrayList<T>>> baseDocumentFromClickhouse(Supplier<String> getSqlSupplier,
|
||||||
Supplier<String> getSqlSupplier,
|
Function<ResultSet,T> formatResultFunc) {
|
||||||
Function<ResultSet,T> formatResultFunc){
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
initializeMap(newMap);
|
HashMap<Integer, HashMap<String, ArrayList<T>>> newMap = initializeMap();
|
||||||
String sql = getSqlSupplier.get();
|
String sql = getSqlSupplier.get();
|
||||||
LOG.info(sql);
|
|
||||||
try {
|
try {
|
||||||
connection = manger.getConnection();
|
connection = manger.getConnection();
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
@@ -56,24 +53,29 @@ public class BaseClickhouseData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long last = System.currentTimeMillis();
|
long last = System.currentTimeMillis();
|
||||||
LOG.info("读取"+i+"条数据,运行时间:" + (last - start));
|
LOG.info(sql + "\n读取"+i+"条数据,运行时间:" + (last - start));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
manger.clear(statement,connection);
|
manger.clear(statement,connection);
|
||||||
}
|
}
|
||||||
|
return newMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends BaseDocument> void initializeMap(HashMap<Integer, HashMap<String,ArrayList<T>>> map){
|
private <T extends BaseDocument> HashMap<Integer, HashMap<String,ArrayList<T>>> initializeMap(){
|
||||||
try {
|
try {
|
||||||
|
HashMap<Integer, HashMap<String, ArrayList<T>>> newDataMap = new HashMap<>();
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++) {
|
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++) {
|
||||||
map.put(i, new HashMap<>(16));
|
newDataMap.put(i, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
return newDataMap;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LOG.error("初始化数据失败");
|
LOG.error("数据初始化失败 "+e.toString());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
package cn.ac.iie.dao;
|
package cn.ac.iie.dao;
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
import cn.ac.iie.config.ApplicationConfig;
|
||||||
import cn.ac.iie.service.read.ReadClickhouseData;
|
import cn.ac.iie.service.ingestion.ReadClickhouseData;
|
||||||
import cn.ac.iie.service.update.Document;
|
import cn.ac.iie.service.update.Document;
|
||||||
import cn.ac.iie.service.update.relationship.LocateFqdn2Ip;
|
import cn.ac.iie.service.update.relationship.LocateFqdn2Ip;
|
||||||
import cn.ac.iie.service.update.relationship.SameFqdn2Fqdn;
|
|
||||||
import cn.ac.iie.service.update.relationship.VisitIp2Fqdn;
|
|
||||||
import cn.ac.iie.service.update.vertex.Fqdn;
|
|
||||||
import cn.ac.iie.service.update.vertex.Ip;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import cn.ac.iie.utils.ExecutorThreadPool;
|
import cn.ac.iie.utils.ExecutorThreadPool;
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -19,14 +13,10 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static cn.ac.iie.dao.BaseArangoData.*;
|
|
||||||
import static cn.ac.iie.dao.BaseClickhouseData.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新图数据库业务类
|
* 更新图数据库业务类
|
||||||
* @author wlh
|
* @author wlh
|
||||||
@@ -34,71 +24,46 @@ import static cn.ac.iie.dao.BaseClickhouseData.*;
|
|||||||
public class UpdateGraphData {
|
public class UpdateGraphData {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(UpdateGraphData.class);
|
private static final Logger LOG = LoggerFactory.getLogger(UpdateGraphData.class);
|
||||||
private static ExecutorThreadPool pool = ExecutorThreadPool.getInstance();
|
private static ExecutorThreadPool pool = ExecutorThreadPool.getInstance();
|
||||||
private static ArangoDBConnect arangoManger = ArangoDBConnect.getInstance();
|
|
||||||
|
|
||||||
private static BaseArangoData baseArangoData = new BaseArangoData();
|
|
||||||
private static BaseClickhouseData baseClickhouseData = new BaseClickhouseData();
|
private static BaseClickhouseData baseClickhouseData = new BaseClickhouseData();
|
||||||
|
|
||||||
|
|
||||||
public void updateArango(){
|
public void updateArango(){
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
updateDocument(newVertexFqdnMap, historyVertexFqdnMap, "FQDN",
|
updateDocument("ip_learning.r_locate_fqdn2ip_local", LocateFqdn2Ip.class,
|
||||||
Fqdn.class,BaseDocument.class,
|
ReadClickhouseData::getRelationshipFqdnAddressIpSqlYsp,ReadClickhouseData::getRelationFqdnAddressIpDocument);
|
||||||
ReadClickhouseData::getVertexFqdnSql, ReadClickhouseData::getVertexFqdnDocument);
|
|
||||||
|
|
||||||
updateDocument(newVertexIpMap,historyVertexIpMap,"IP",
|
|
||||||
Ip.class,BaseDocument.class,
|
|
||||||
ReadClickhouseData::getVertexIpSql, ReadClickhouseData::getVertexIpDocument);
|
|
||||||
|
|
||||||
updateDocument(newRelationFqdnAddressIpMap,historyRelationFqdnAddressIpMap,"R_LOCATE_FQDN2IP",
|
|
||||||
LocateFqdn2Ip.class,BaseEdgeDocument.class,
|
|
||||||
ReadClickhouseData::getRelationshipFqdnAddressIpSql, ReadClickhouseData::getRelationFqdnAddressIpDocument);
|
|
||||||
|
|
||||||
updateDocument(newRelationIpVisitFqdnMap,historyRelationIpVisitFqdnMap,"R_VISIT_IP2FQDN",
|
|
||||||
VisitIp2Fqdn.class,BaseEdgeDocument.class,
|
|
||||||
ReadClickhouseData::getRelationshipIpVisitFqdnSql, ReadClickhouseData::getRelationIpVisitFqdnDocument);
|
|
||||||
|
|
||||||
updateDocument(newRelationFqdnSameFqdnMap,historyRelationFqdnSameFqdnMap,"R_SAME_ORIGIN_FQDN2FQDN",
|
|
||||||
SameFqdn2Fqdn.class,BaseEdgeDocument.class,
|
|
||||||
ReadClickhouseData::getRelationshipFqdnSameFqdnSql, ReadClickhouseData::getRelationshipFqdnSameFqdnDocument);
|
|
||||||
|
|
||||||
|
|
||||||
long last = System.currentTimeMillis();
|
long last = System.currentTimeMillis();
|
||||||
LOG.info("更新图数据库时间共计:"+(last - start));
|
LOG.info("iplearning application运行完毕,用时:"+(last - start));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
arangoManger.clean();
|
|
||||||
pool.shutdown();
|
pool.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends BaseDocument> void updateDocument(HashMap<Integer, HashMap<String, ArrayList<T>>> newMap,
|
|
||||||
ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> historyMap,
|
private <T extends BaseDocument> void updateDocument(String collection,
|
||||||
String collection,
|
|
||||||
Class<? extends Document<T>> taskType,
|
Class<? extends Document<T>> taskType,
|
||||||
Class<T> docmentType,
|
|
||||||
Supplier<String> getSqlSupplier,
|
Supplier<String> getSqlSupplier,
|
||||||
Function<ResultSet,T> formatResultFunc) {
|
Function<ResultSet,T> formatResultFunc
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
baseArangoData.readHistoryData(collection,historyMap,docmentType);
|
|
||||||
LOG.info(collection+" 读取clickhouse,封装结果集");
|
LOG.info(collection+" 读取clickhouse,封装结果集");
|
||||||
baseClickhouseData.baseDocumentFromClickhouse(newMap, getSqlSupplier,formatResultFunc);
|
HashMap<Integer, HashMap<String, ArrayList<T>>> newMap =
|
||||||
|
baseClickhouseData.baseDocumentFromClickhouse(getSqlSupplier, formatResultFunc);
|
||||||
|
|
||||||
LOG.info(collection+" 开始更新");
|
LOG.info(collection+" 开始更新");
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER);
|
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER);
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++){
|
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER; i++){
|
||||||
HashMap<String, ArrayList<T>> tmpNewMap = newMap.get(i);
|
HashMap<String, ArrayList<T>> tmpNewMap = newMap.get(i);
|
||||||
ConcurrentHashMap<String, T> tmpHisMap = historyMap.get(i);
|
|
||||||
Constructor constructor = taskType.getConstructor(
|
Constructor constructor = taskType.getConstructor(
|
||||||
HashMap.class,
|
HashMap.class,
|
||||||
ArangoDBConnect.class,
|
|
||||||
String.class,
|
String.class,
|
||||||
ConcurrentHashMap.class,
|
|
||||||
CountDownLatch.class);
|
CountDownLatch.class);
|
||||||
Document docTask = (Document)constructor.newInstance(tmpNewMap, arangoManger, collection, tmpHisMap, countDownLatch);
|
Document docTask = (Document)constructor.newInstance(tmpNewMap, collection, countDownLatch);
|
||||||
pool.executor(docTask);
|
pool.executor(docTask);
|
||||||
}
|
}
|
||||||
countDownLatch.await();
|
countDownLatch.await();
|
||||||
@@ -106,11 +71,6 @@ public class UpdateGraphData {
|
|||||||
LOG.info(collection+" 更新完毕,共耗时:"+(last-start));
|
LOG.info(collection+" 更新完毕,共耗时:"+(last-start));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
|
||||||
newMap.clear();
|
|
||||||
historyMap.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cn.ac.iie.service.read;
|
package cn.ac.iie.service.ingestion;
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
import cn.ac.iie.config.ApplicationConfig;
|
||||||
import cn.ac.iie.utils.TopDomainUtils;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -23,10 +22,10 @@ public class ReadClickhouseData {
|
|||||||
private static Pattern pattern = Pattern.compile("^[\\d]*$");
|
private static Pattern pattern = Pattern.compile("^[\\d]*$");
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ReadClickhouseData.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ReadClickhouseData.class);
|
||||||
|
|
||||||
|
|
||||||
private static long[] timeLimit = getTimeLimit();
|
private static long[] timeLimit = getTimeLimit();
|
||||||
private static long maxTime = timeLimit[0];
|
private static long maxTime = timeLimit[0];
|
||||||
private static long minTime = timeLimit[1];
|
private static long minTime = timeLimit[1];
|
||||||
|
|
||||||
public static final Integer DISTINCT_CLIENT_IP_NUM = ApplicationConfig.DISTINCT_CLIENT_IP_NUM;
|
public static final Integer DISTINCT_CLIENT_IP_NUM = ApplicationConfig.DISTINCT_CLIENT_IP_NUM;
|
||||||
static final Integer RECENT_COUNT_HOUR = ApplicationConfig.RECENT_COUNT_HOUR;
|
static final Integer RECENT_COUNT_HOUR = ApplicationConfig.RECENT_COUNT_HOUR;
|
||||||
public static final HashSet<String> PROTOCOL_SET;
|
public static final HashSet<String> PROTOCOL_SET;
|
||||||
@@ -38,11 +37,10 @@ public class ReadClickhouseData {
|
|||||||
PROTOCOL_SET.add("DNS");
|
PROTOCOL_SET.add("DNS");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseDocument getVertexFqdnDocument(ResultSet resultSet){
|
public static BaseDocument getVertexFqdnDocument(ResultSet resultSet) {
|
||||||
BaseDocument newDoc = null;
|
BaseDocument newDoc = null;
|
||||||
try {
|
try {
|
||||||
String fqdnOrReferer = resultSet.getString("FQDN");
|
String fqdnName = resultSet.getString("FQDN");
|
||||||
String fqdnName = TopDomainUtils.getDomainFromUrl(fqdnOrReferer);
|
|
||||||
if (isDomain(fqdnName)) {
|
if (isDomain(fqdnName)) {
|
||||||
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
||||||
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
||||||
@@ -52,13 +50,13 @@ public class ReadClickhouseData {
|
|||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseDocument getVertexIpDocument(ResultSet resultSet){
|
public static BaseDocument getVertexIpDocument(ResultSet resultSet) {
|
||||||
BaseDocument newDoc = new BaseDocument();
|
BaseDocument newDoc = new BaseDocument();
|
||||||
try {
|
try {
|
||||||
String ip = resultSet.getString("IP");
|
String ip = resultSet.getString("IP");
|
||||||
@@ -67,6 +65,13 @@ public class ReadClickhouseData {
|
|||||||
long sessionCount = resultSet.getLong("SESSION_COUNT");
|
long sessionCount = resultSet.getLong("SESSION_COUNT");
|
||||||
long bytesSum = resultSet.getLong("BYTES_SUM");
|
long bytesSum = resultSet.getLong("BYTES_SUM");
|
||||||
String ipType = resultSet.getString("ip_type");
|
String ipType = resultSet.getString("ip_type");
|
||||||
|
String[] commonLinkInfos = (String[]) resultSet.getArray("common_link_info").getArray();
|
||||||
|
String commonLinkInfo;
|
||||||
|
if (commonLinkInfos.length > 1 && !commonLinkInfos[1].equals("")){
|
||||||
|
commonLinkInfo = commonLinkInfos[1];
|
||||||
|
}else {
|
||||||
|
commonLinkInfo = commonLinkInfos[0];
|
||||||
|
}
|
||||||
newDoc.setKey(ip);
|
newDoc.setKey(ip);
|
||||||
newDoc.addAttribute("IP", ip);
|
newDoc.addAttribute("IP", ip);
|
||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
@@ -85,20 +90,15 @@ public class ReadClickhouseData {
|
|||||||
newDoc.addAttribute("CLIENT_BYTES_SUM", 0L);
|
newDoc.addAttribute("CLIENT_BYTES_SUM", 0L);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newDoc.addAttribute("SERVER_SESSION_COUNT", 0L);
|
|
||||||
newDoc.addAttribute("SERVER_BYTES_SUM", 0L);
|
|
||||||
newDoc.addAttribute("CLIENT_SESSION_COUNT", 0L);
|
|
||||||
newDoc.addAttribute("CLIENT_BYTES_SUM", 0L);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// newDoc.addAttribute("COMMON_LINK_INFO", "");
|
newDoc.addAttribute("COMMON_LINK_INFO", commonLinkInfo);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseDocument getVertexSubscriberDocument(ResultSet resultSet){
|
public static BaseDocument getVertexSubscriberDocument(ResultSet resultSet) {
|
||||||
BaseDocument newDoc = new BaseDocument();
|
BaseDocument newDoc = new BaseDocument();
|
||||||
try {
|
try {
|
||||||
String subscriberId = resultSet.getString("common_subscriber_id");
|
String subscriberId = resultSet.getString("common_subscriber_id");
|
||||||
@@ -107,13 +107,14 @@ public class ReadClickhouseData {
|
|||||||
newDoc.setKey(subscriberId);
|
newDoc.setKey(subscriberId);
|
||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
||||||
}catch (Exception e){
|
newDoc.addAttribute("SUBSCRIBER_ID",subscriberId);
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseEdgeDocument getRelationshipSubsciberLocateIpDocument(ResultSet resultSet){
|
public static BaseEdgeDocument getRelationshipSubsciberLocateIpDocument(ResultSet resultSet) {
|
||||||
BaseEdgeDocument newDoc = new BaseEdgeDocument();
|
BaseEdgeDocument newDoc = new BaseEdgeDocument();
|
||||||
try {
|
try {
|
||||||
String subscriberId = resultSet.getString("common_subscriber_id");
|
String subscriberId = resultSet.getString("common_subscriber_id");
|
||||||
@@ -129,14 +130,14 @@ public class ReadClickhouseData {
|
|||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
||||||
newDoc.addAttribute("COUNT_TOTAL", countTotal);
|
newDoc.addAttribute("COUNT_TOTAL", countTotal);
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseEdgeDocument getRelationFqdnAddressIpDocument(ResultSet resultSet){
|
public static BaseEdgeDocument getRelationFqdnAddressIpDocument(ResultSet resultSet) {
|
||||||
BaseEdgeDocument newDoc = null;
|
BaseEdgeDocument newDoc = null;
|
||||||
try {
|
try {
|
||||||
String vFqdn = resultSet.getString("FQDN");
|
String vFqdn = resultSet.getString("FQDN");
|
||||||
@@ -145,6 +146,8 @@ public class ReadClickhouseData {
|
|||||||
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
||||||
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
||||||
long countTotal = resultSet.getLong("COUNT_TOTAL");
|
long countTotal = resultSet.getLong("COUNT_TOTAL");
|
||||||
|
// String schemaType = resultSet.getString("schema_type");
|
||||||
|
String schemaType = "";
|
||||||
String[] distCipRecents = (String[]) resultSet.getArray("DIST_CIP_RECENT").getArray();
|
String[] distCipRecents = (String[]) resultSet.getArray("DIST_CIP_RECENT").getArray();
|
||||||
long[] clientIpTs = new long[distCipRecents.length];
|
long[] clientIpTs = new long[distCipRecents.length];
|
||||||
for (int i = 0; i < clientIpTs.length; i++) {
|
for (int i = 0; i < clientIpTs.length; i++) {
|
||||||
@@ -154,47 +157,22 @@ public class ReadClickhouseData {
|
|||||||
String key = vFqdn + "-" + vIp;
|
String key = vFqdn + "-" + vIp;
|
||||||
newDoc = new BaseEdgeDocument();
|
newDoc = new BaseEdgeDocument();
|
||||||
newDoc.setKey(key);
|
newDoc.setKey(key);
|
||||||
newDoc.setFrom("FQDN/" + vFqdn);
|
newDoc.setFrom(vFqdn);
|
||||||
newDoc.setTo("IP/" + vIp);
|
newDoc.setTo(vIp);
|
||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
||||||
newDoc.addAttribute("CNT_TOTAL",countTotal);
|
|
||||||
newDoc.addAttribute("DIST_CIP", distCipRecents);
|
newDoc.addAttribute("DIST_CIP", distCipRecents);
|
||||||
newDoc.addAttribute("DIST_CIP_TS", clientIpTs);
|
newDoc.addAttribute("DIST_CIP_TS", clientIpTs);
|
||||||
|
newDoc.addAttribute("PROTOCOL_TYPE", schemaType);
|
||||||
|
checkSchemaProperty(newDoc, schemaType, countTotal);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseEdgeDocument getRelationshipFqdnSameFqdnDocument(ResultSet resultSet){
|
public static BaseEdgeDocument getRelationIpVisitFqdnDocument(ResultSet resultSet) {
|
||||||
BaseEdgeDocument newDoc = null;
|
|
||||||
try {
|
|
||||||
String domainFqdn = resultSet.getString("domainFqdn");
|
|
||||||
String referer = resultSet.getString("referer");
|
|
||||||
String refererFqdn = TopDomainUtils.getDomainFromUrl(referer);
|
|
||||||
if (isDomain(refererFqdn) && isDomain(domainFqdn)){
|
|
||||||
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
|
||||||
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
|
||||||
long countTotal = resultSet.getLong("COUNT_TOTAL");
|
|
||||||
String key = domainFqdn + "-" + refererFqdn;
|
|
||||||
newDoc = new BaseEdgeDocument();
|
|
||||||
newDoc.setKey(key);
|
|
||||||
newDoc.setFrom("FQDN/" + domainFqdn);
|
|
||||||
newDoc.setTo("FQDN/" + refererFqdn);
|
|
||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
|
||||||
newDoc.addAttribute("CNT_TOTAL",countTotal);
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return newDoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BaseEdgeDocument getRelationIpVisitFqdnDocument(ResultSet resultSet){
|
|
||||||
BaseEdgeDocument newDoc = null;
|
BaseEdgeDocument newDoc = null;
|
||||||
try {
|
try {
|
||||||
String vFqdn = resultSet.getString("FQDN");
|
String vFqdn = resultSet.getString("FQDN");
|
||||||
@@ -204,16 +182,18 @@ public class ReadClickhouseData {
|
|||||||
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
long firstFoundTime = resultSet.getLong("FIRST_FOUND_TIME");
|
||||||
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
long lastFoundTime = resultSet.getLong("LAST_FOUND_TIME");
|
||||||
long countTotal = resultSet.getLong("COUNT_TOTAL");
|
long countTotal = resultSet.getLong("COUNT_TOTAL");
|
||||||
|
String schemaType = resultSet.getString("schema_type");
|
||||||
|
|
||||||
newDoc = new BaseEdgeDocument();
|
newDoc = new BaseEdgeDocument();
|
||||||
newDoc.setKey(key);
|
newDoc.setKey(key);
|
||||||
newDoc.setFrom("IP/" + vIp);
|
newDoc.setFrom(vIp);
|
||||||
newDoc.setTo("FQDN/" + vFqdn);
|
newDoc.setTo(vFqdn);
|
||||||
newDoc.addAttribute("CNT_TOTAL",countTotal);
|
|
||||||
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
newDoc.addAttribute("FIRST_FOUND_TIME", firstFoundTime);
|
||||||
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
newDoc.addAttribute("LAST_FOUND_TIME", lastFoundTime);
|
||||||
|
newDoc.addAttribute("PROTOCOL_TYPE", schemaType);
|
||||||
|
checkSchemaProperty(newDoc, schemaType, countTotal);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return newDoc;
|
return newDoc;
|
||||||
@@ -222,8 +202,8 @@ public class ReadClickhouseData {
|
|||||||
public static <T extends BaseDocument> void putMapByHashcode(T newDoc, HashMap<Integer, HashMap<String, ArrayList<T>>> map) {
|
public static <T extends BaseDocument> void putMapByHashcode(T newDoc, HashMap<Integer, HashMap<String, ArrayList<T>>> map) {
|
||||||
if (newDoc != null) {
|
if (newDoc != null) {
|
||||||
String key = newDoc.getKey();
|
String key = newDoc.getKey();
|
||||||
int i = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER;
|
int hashCode = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER;
|
||||||
HashMap<String, ArrayList<T>> documentHashMap = map.getOrDefault(i, new HashMap<>());
|
HashMap<String, ArrayList<T>> documentHashMap = map.getOrDefault(hashCode, new HashMap<>());
|
||||||
ArrayList<T> documentArrayList = documentHashMap.getOrDefault(key, new ArrayList<>());
|
ArrayList<T> documentArrayList = documentHashMap.getOrDefault(key, new ArrayList<>());
|
||||||
documentArrayList.add(newDoc);
|
documentArrayList.add(newDoc);
|
||||||
documentHashMap.put(key, documentArrayList);
|
documentHashMap.put(key, documentArrayList);
|
||||||
@@ -235,12 +215,8 @@ public class ReadClickhouseData {
|
|||||||
if (fqdn == null || fqdn.length() == 0){
|
if (fqdn == null || fqdn.length() == 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (fqdn.contains(":")){
|
fqdn = fqdn.split(":")[0];
|
||||||
String s = fqdn.split(":")[0];
|
|
||||||
if (s.contains(":")){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] fqdnArr = fqdn.split("\\.");
|
String[] fqdnArr = fqdn.split("\\.");
|
||||||
if (fqdnArr.length < 4 || fqdnArr.length > 4) {
|
if (fqdnArr.length < 4 || fqdnArr.length > 4) {
|
||||||
return true;
|
return true;
|
||||||
@@ -262,17 +238,16 @@ public class ReadClickhouseData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void checkSchemaProperty(BaseEdgeDocument newDoc, String schema, long countTotal) {
|
private static void checkSchemaProperty(BaseEdgeDocument newDoc, String schema, long countTotal) {
|
||||||
long[] recentCnt = new long[RECENT_COUNT_HOUR];
|
long[] recentCnt = new long[RECENT_COUNT_HOUR];
|
||||||
recentCnt[0] = countTotal;
|
recentCnt[0] = countTotal;
|
||||||
for (String protocol: PROTOCOL_SET){
|
for (String protocol : PROTOCOL_SET) {
|
||||||
String protocolRecent = protocol +"_CNT_RECENT";
|
String protocolRecent = protocol + "_CNT_RECENT";
|
||||||
String protocolTotal = protocol + "_CNT_TOTAL";
|
String protocolTotal = protocol + "_CNT_TOTAL";
|
||||||
if (protocol.equals(schema)){
|
if (protocol.equals(schema)) {
|
||||||
newDoc.addAttribute(protocolTotal, countTotal);
|
newDoc.addAttribute(protocolTotal, countTotal);
|
||||||
newDoc.addAttribute(protocolRecent, recentCnt);
|
newDoc.addAttribute(protocolRecent, recentCnt);
|
||||||
}else {
|
} else {
|
||||||
newDoc.addAttribute(protocolTotal, 0L);
|
newDoc.addAttribute(protocolTotal, 0L);
|
||||||
newDoc.addAttribute(protocolRecent, new long[RECENT_COUNT_HOUR]);
|
newDoc.addAttribute(protocolRecent, new long[RECENT_COUNT_HOUR]);
|
||||||
}
|
}
|
||||||
@@ -280,32 +255,36 @@ public class ReadClickhouseData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getVertexFqdnSql() {
|
public static String getVertexFqdnSql() {
|
||||||
String where = "recv_time >= "+minTime+" and recv_time <= "+maxTime;
|
String where = "common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime;
|
||||||
String mediaDomainSql = "SELECT s1_domain AS FQDN,MIN(recv_time) AS FIRST_FOUND_TIME,MAX(recv_time) AS LAST_FOUND_TIME FROM media_expire_patch WHERE "+where+" and s1_domain != '' GROUP BY s1_domain";
|
String sslSql = "SELECT ssl_sni AS FQDN,MAX( common_recv_time ) AS LAST_FOUND_TIME,MIN( common_recv_time ) AS FIRST_FOUND_TIME FROM tsg_galaxy_v3.connection_record_log WHERE " + where + " and common_schema_type = 'SSL' GROUP BY ssl_sni";
|
||||||
String refererSql = "SELECT s1_referer AS FQDN,MIN(recv_time) AS FIRST_FOUND_TIME,MAX(recv_time) AS LAST_FOUND_TIME FROM media_expire_patch WHERE "+where+" and s1_referer != '' GROUP BY s1_referer";
|
String httpSql = "SELECT http_host AS FQDN,MAX( common_recv_time ) AS LAST_FOUND_TIME,MIN( common_recv_time ) AS FIRST_FOUND_TIME FROM tsg_galaxy_v3.connection_record_log WHERE " + where + " and common_schema_type = 'HTTP' GROUP BY http_host";
|
||||||
return "SELECT * FROM((" + mediaDomainSql + ") UNION ALL (" + refererSql + "))";
|
return "SELECT FQDN,MAX( LAST_FOUND_TIME ) AS LAST_FOUND_TIME,MIN( FIRST_FOUND_TIME ) AS FIRST_FOUND_TIME FROM ((" + sslSql + ") UNION ALL (" + httpSql + ")) GROUP BY FQDN HAVING FQDN != ''";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVertexIpSql() {
|
public static String getVertexIpSql() {
|
||||||
String where = " recv_time >= " + minTime + " AND recv_time < " + maxTime;
|
String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime + " AND common_schema_type != 'BASE'";
|
||||||
String clientIpSql = "SELECT s1_s_ip AS IP, MIN(recv_time) AS FIRST_FOUND_TIME,MAX(recv_time) AS LAST_FOUND_TIME,count(*) as SESSION_COUNT,sum(media_len) as BYTES_SUM,'client' as ip_type FROM media_expire_patch where " + where + " group by IP";
|
String clientIpSql = "SELECT common_client_ip AS IP, MIN(common_recv_time) AS FIRST_FOUND_TIME,MAX(common_recv_time) AS LAST_FOUND_TIME,count(*) as SESSION_COUNT,sum(common_c2s_byte_num+common_s2c_byte_num) as BYTES_SUM,groupUniqArray(2)(common_link_info_c2s) as common_link_info,'client' as ip_type FROM tsg_galaxy_v3.connection_record_log where " + where + " group by IP";
|
||||||
String serverIpSql = "SELECT s1_d_ip AS IP, MIN(recv_time) AS FIRST_FOUND_TIME,MAX(recv_time) AS LAST_FOUND_TIME,count(*) as SESSION_COUNT,sum(media_len) as BYTES_SUM,'server' as ip_type FROM media_expire_patch where " + where + " group by IP";
|
String serverIpSql = "SELECT common_server_ip AS IP, MIN(common_recv_time) AS FIRST_FOUND_TIME,MAX(common_recv_time) AS LAST_FOUND_TIME,count(*) as SESSION_COUNT,sum(common_c2s_byte_num+common_s2c_byte_num) as BYTES_SUM,groupUniqArray(2)(common_link_info_s2c) as common_link_info,'server' as ip_type FROM tsg_galaxy_v3.connection_record_log where " + where + " group by IP";
|
||||||
return "SELECT * FROM((" + clientIpSql + ") UNION ALL (" + serverIpSql + "))";
|
return "SELECT * FROM((" + clientIpSql + ") UNION ALL (" + serverIpSql + "))";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRelationshipFqdnAddressIpSql() {
|
public static String getRelationshipFqdnAddressIpSql() {
|
||||||
|
String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime;
|
||||||
|
String sslSql = "SELECT ssl_sni AS FQDN,common_server_ip,MAX(common_recv_time) AS LAST_FOUND_TIME,MIN(common_recv_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,groupUniqArray("+DISTINCT_CLIENT_IP_NUM+")(common_client_ip) AS DIST_CIP_RECENT,'TLS' AS schema_type FROM tsg_galaxy_v3.connection_record_log WHERE " + where + " and common_schema_type = 'SSL' GROUP BY ssl_sni,common_server_ip";
|
||||||
|
String httpSql = "SELECT http_host AS FQDN,common_server_ip,MAX(common_recv_time) AS LAST_FOUND_TIME,MIN(common_recv_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,groupUniqArray("+DISTINCT_CLIENT_IP_NUM+")(common_client_ip) AS DIST_CIP_RECENT,'HTTP' AS schema_type FROM tsg_galaxy_v3.connection_record_log WHERE " + where + " and common_schema_type = 'HTTP' GROUP BY http_host,common_server_ip";
|
||||||
|
return "SELECT * FROM ((" + sslSql + ") UNION ALL (" + httpSql + "))WHERE FQDN != ''";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRelationshipFqdnAddressIpSqlYsp() {
|
||||||
String where = "recv_time >= "+minTime+" and recv_time <= "+maxTime +" AND s1_domain != '' AND s1_d_ip != '' ";
|
String where = "recv_time >= "+minTime+" and recv_time <= "+maxTime +" AND s1_domain != '' AND s1_d_ip != '' ";
|
||||||
return "SELECT s1_domain AS FQDN,s1_d_ip AS common_server_ip,MIN( recv_time ) AS FIRST_FOUND_TIME,MAX( recv_time ) AS LAST_FOUND_TIME,COUNT( * ) AS COUNT_TOTAL,groupUniqArray("+DISTINCT_CLIENT_IP_NUM+")(s1_s_ip) AS DIST_CIP_RECENT FROM media_expire_patch WHERE "+where+" GROUP BY s1_d_ip,s1_domain";
|
return "SELECT s1_domain AS FQDN,s1_d_ip AS common_server_ip,MIN( recv_time ) AS FIRST_FOUND_TIME,MAX( recv_time ) AS LAST_FOUND_TIME,COUNT( * ) AS COUNT_TOTAL,groupUniqArray("+DISTINCT_CLIENT_IP_NUM+")(s1_s_ip) AS DIST_CIP_RECENT FROM media_expire_patch WHERE "+where+" GROUP BY s1_d_ip,s1_domain";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRelationshipFqdnSameFqdnSql(){
|
|
||||||
String where = "recv_time >= "+minTime+" and recv_time <= "+maxTime +" AND s1_domain != '' AND s1_referer != '' ";
|
|
||||||
return "SELECT s1_domain AS domainFqdn,s1_referer AS referer,MIN(recv_time) AS FIRST_FOUND_TIME,MAX(recv_time) AS LAST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL FROM media_expire_patch where "+where+" GROUP BY s1_domain,s1_referer";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getRelationshipIpVisitFqdnSql() {
|
public static String getRelationshipIpVisitFqdnSql() {
|
||||||
String where = "recv_time >= "+minTime+" and recv_time <= "+maxTime+" AND s1_s_ip != '' AND s1_domain != '' ";
|
String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime;
|
||||||
return "SELECT s1_s_ip AS common_client_ip,s1_domain AS FQDN,MIN( recv_time ) AS FIRST_FOUND_TIME,MAX( recv_time ) AS LAST_FOUND_TIME,COUNT( * ) AS COUNT_TOTAL FROM media_expire_patch WHERE "+where+" GROUP BY s1_s_ip,s1_domain";
|
String httpSql = "SELECT http_host AS FQDN,common_client_ip,MAX(common_recv_time) AS LAST_FOUND_TIME,MIN(common_recv_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,'HTTP' AS schema_type FROM tsg_galaxy_v3.connection_record_log WHERE " + where + " and common_schema_type = 'HTTP' GROUP BY http_host,common_client_ip";
|
||||||
|
String sslSql = "SELECT ssl_sni AS FQDN,common_client_ip,MAX(common_recv_time) AS LAST_FOUND_TIME,MIN(common_recv_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,'TLS' AS schema_type FROM tsg_galaxy_v3.connection_record_log WHERE common_schema_type = 'SSL' GROUP BY ssl_sni,common_client_ip";
|
||||||
|
return "SELECT * FROM ((" + sslSql + ") UNION ALL (" + httpSql + "))WHERE FQDN != ''";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVertexSubscriberSql() {
|
public static String getVertexSubscriberSql() {
|
||||||
@@ -321,7 +300,7 @@ public class ReadClickhouseData {
|
|||||||
private static long[] getTimeLimit() {
|
private static long[] getTimeLimit() {
|
||||||
long maxTime = 0L;
|
long maxTime = 0L;
|
||||||
long minTime = 0L;
|
long minTime = 0L;
|
||||||
switch (ApplicationConfig.CLICKHOUSE_TIME_LIMIT_TYPE) {
|
switch (ApplicationConfig.TIME_LIMIT_TYPE) {
|
||||||
case 0:
|
case 0:
|
||||||
maxTime = currentHour;
|
maxTime = currentHour;
|
||||||
minTime = maxTime - ApplicationConfig.UPDATE_INTERVAL;
|
minTime = maxTime - ApplicationConfig.UPDATE_INTERVAL;
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package cn.ac.iie.service.read;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import static cn.ac.iie.service.read.ReadClickhouseData.RECENT_COUNT_HOUR;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author wlh
|
|
||||||
* 多线程全量读取arangoDb历史数据,封装到map
|
|
||||||
*/
|
|
||||||
public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ReadHistoryArangoData.class);
|
|
||||||
|
|
||||||
private ArangoDBConnect arangoConnect;
|
|
||||||
private String query;
|
|
||||||
private ConcurrentHashMap<Integer,ConcurrentHashMap<String, T>> map;
|
|
||||||
private Class<T> type;
|
|
||||||
private String table;
|
|
||||||
private CountDownLatch countDownLatch;
|
|
||||||
|
|
||||||
public ReadHistoryArangoData(ArangoDBConnect arangoConnect,
|
|
||||||
String query,
|
|
||||||
ConcurrentHashMap<Integer,ConcurrentHashMap<String, T>> map,
|
|
||||||
Class<T> type,
|
|
||||||
String table,
|
|
||||||
CountDownLatch countDownLatch) {
|
|
||||||
this.arangoConnect = arangoConnect;
|
|
||||||
this.query = query;
|
|
||||||
this.map = map;
|
|
||||||
this.type = type;
|
|
||||||
this.table = table;
|
|
||||||
this.countDownLatch = countDownLatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
long s = System.currentTimeMillis();
|
|
||||||
ArangoCursor<T> docs = arangoConnect.executorQuery(query, type);
|
|
||||||
if (docs != null) {
|
|
||||||
List<T> baseDocuments = docs.asListRemaining();
|
|
||||||
int i = 0;
|
|
||||||
for (T doc : baseDocuments) {
|
|
||||||
String key = doc.getKey();
|
|
||||||
int hashCode = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER;
|
|
||||||
ConcurrentHashMap<String, T> tmpMap = map.get(hashCode);
|
|
||||||
tmpMap.put(key, doc);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
long l = System.currentTimeMillis();
|
|
||||||
LOG.info(query + "\n读取" + i + "条数据,运行时间:" + (l - s));
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}finally {
|
|
||||||
countDownLatch.countDown();
|
|
||||||
LOG.info("本线程读取完毕,剩余线程数量:"+countDownLatch.getCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateProtocolDocument(T doc) {
|
|
||||||
if (doc.getProperties().containsKey("PROTOCOL_TYPE")) {
|
|
||||||
for (String protocol : ReadClickhouseData.PROTOCOL_SET) {
|
|
||||||
String protocolRecent = protocol + "_CNT_RECENT";
|
|
||||||
ArrayList<Long> cntRecent = (ArrayList<Long>) doc.getAttribute(protocolRecent);
|
|
||||||
Long[] cntRecentsSrc = cntRecent.toArray(new Long[cntRecent.size()]);
|
|
||||||
Long[] cntRecentsDst = new Long[RECENT_COUNT_HOUR];
|
|
||||||
System.arraycopy(cntRecentsSrc, 0, cntRecentsDst, 1, cntRecentsSrc.length - 1);
|
|
||||||
cntRecentsDst[0] = 0L;
|
|
||||||
doc.addAttribute(protocolRecent, cntRecentsDst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,32 @@
|
|||||||
package cn.ac.iie.service.update;
|
package cn.ac.iie.service.update;
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
import cn.ac.iie.config.ApplicationConfig;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
import cn.ac.iie.utils.ClickhouseConnect;
|
||||||
|
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class Document<T extends BaseDocument> extends Thread{
|
public class Document<T extends BaseDocument> extends Thread{
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Document.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Document.class);
|
||||||
private HashMap<String, ArrayList<T>> newDocumentMap;
|
private HashMap<String, ArrayList<T>> newDocumentMap;
|
||||||
private ArangoDBConnect arangoManger;
|
|
||||||
private String collectionName;
|
private String collectionName;
|
||||||
private ConcurrentHashMap<String, T> historyDocumentMap;
|
|
||||||
private CountDownLatch countDownLatch;
|
private CountDownLatch countDownLatch;
|
||||||
|
|
||||||
|
private ClickhouseConnect manger = ClickhouseConnect.getInstance();
|
||||||
|
|
||||||
Document(HashMap<String, ArrayList<T>> newDocumentMap,
|
Document(HashMap<String, ArrayList<T>> newDocumentMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, T> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
this.newDocumentMap = newDocumentMap;
|
this.newDocumentMap = newDocumentMap;
|
||||||
this.arangoManger = arangoManger;
|
|
||||||
this.collectionName = collectionName;
|
this.collectionName = collectionName;
|
||||||
this.historyDocumentMap = historyDocumentMap;
|
|
||||||
this.countDownLatch = countDownLatch;
|
this.countDownLatch = countDownLatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,28 +34,32 @@ public class Document<T extends BaseDocument> extends Thread{
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
LOG.info("新读取数据"+newDocumentMap.size()+"条,历史数据"+historyDocumentMap.size()+"条");
|
LOG.info("读取数据"+newDocumentMap.size()+"条");
|
||||||
try {
|
try {
|
||||||
Set<String> keySet = newDocumentMap.keySet();
|
Set<String> keySet = newDocumentMap.keySet();
|
||||||
ArrayList<T> resultDocumentList = new ArrayList<>();
|
DruidPooledConnection connection = manger.getConnection();
|
||||||
|
String sql = "INSERT INTO "+collectionName+" VALUES(?,?,?,?,?,?,?,?,?)";
|
||||||
|
PreparedStatement pstm = connection.prepareStatement(sql);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String key : keySet) {
|
for (String key : keySet) {
|
||||||
ArrayList<T> newDocumentSchemaList = newDocumentMap.getOrDefault(key, null);
|
ArrayList<T> newDocumentSchemaList = newDocumentMap.getOrDefault(key, null);
|
||||||
if (newDocumentSchemaList != null) {
|
if (newDocumentSchemaList != null) {
|
||||||
T newDocument = mergeDocument(newDocumentSchemaList);
|
T newDocument = mergeDocument(newDocumentSchemaList);
|
||||||
|
pstm = setPstm(pstm, newDocument);
|
||||||
i += 1;
|
i += 1;
|
||||||
T historyDocument = historyDocumentMap.getOrDefault(key, null);
|
pstm.addBatch();
|
||||||
updateDocument(newDocument,historyDocument,resultDocumentList);
|
|
||||||
if (i >= ApplicationConfig.UPDATE_ARANGO_BATCH) {
|
if (i >= ApplicationConfig.UPDATE_ARANGO_BATCH) {
|
||||||
arangoManger.overwrite(resultDocumentList, collectionName);
|
pstm.executeBatch();
|
||||||
LOG.info("更新"+collectionName+":" + i);
|
connection.commit();
|
||||||
|
LOG.warn("写入clickhouse数据量:" + i);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
arangoManger.overwrite(resultDocumentList, collectionName);
|
pstm.executeBatch();
|
||||||
LOG.info("更新"+collectionName+":" + i);
|
connection.commit();
|
||||||
|
LOG.warn("写入clickhouse数据量:" + i);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -69,18 +71,8 @@ public class Document<T extends BaseDocument> extends Thread{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDocument(T newDocument, T historyDocument, ArrayList<T> resultDocumentList) {
|
protected PreparedStatement setPstm(PreparedStatement pstm,T newDocument) throws SQLException {
|
||||||
if (historyDocument != null){
|
return pstm;
|
||||||
updateFunction(newDocument,historyDocument);
|
|
||||||
resultDocumentList.add(historyDocument);
|
|
||||||
}else {
|
|
||||||
resultDocumentList.add(newDocument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateFunction(T newDocument, T historyDocument) {
|
|
||||||
Object lastFoundTime = newDocument.getAttribute("LAST_FOUND_TIME");
|
|
||||||
historyDocument.addAttribute("LAST_FOUND_TIME",lastFoundTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private T mergeDocument(ArrayList<T> newDocumentSchemaList){
|
private T mergeDocument(ArrayList<T> newDocumentSchemaList){
|
||||||
@@ -124,5 +116,10 @@ public class Document<T extends BaseDocument> extends Thread{
|
|||||||
lastDoc.addAttribute(attribute,firstSumAttribute+lastSumAttribute);
|
lastDoc.addAttribute(attribute,firstSumAttribute+lastSumAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void replaceAttribute(T firstDoc,T lastDoc,String attribute){
|
||||||
|
Object attributeObj = firstDoc.getAttribute(attribute);
|
||||||
|
lastDoc.addAttribute(attribute,attributeObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,18 @@
|
|||||||
package cn.ac.iie.service.update;
|
package cn.ac.iie.service.update;
|
||||||
|
|
||||||
import cn.ac.iie.service.read.ReadClickhouseData;
|
import cn.ac.iie.service.ingestion.ReadClickhouseData;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class Relationship extends Document<BaseEdgeDocument> {
|
public class Relationship extends Document<BaseEdgeDocument> {
|
||||||
|
|
||||||
public Relationship(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
public Relationship(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseEdgeDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap,arangoManger,collectionName,historyDocumentMap,countDownLatch);
|
super(newDocumentHashMap,collectionName,countDownLatch);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseEdgeDocument newEdgeDocument, BaseEdgeDocument historyEdgeDocument){
|
|
||||||
super.updateFunction(newEdgeDocument,historyEdgeDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateProcotol(BaseEdgeDocument historyEdgeDocument, String schema, BaseEdgeDocument newEdgeDocument){
|
|
||||||
String recentSchema = schema +"_CNT_RECENT";
|
|
||||||
String totalSchema = schema + "_CNT_TOTAL";
|
|
||||||
long countTotal = Long.parseLong(newEdgeDocument.getAttribute(totalSchema).toString());
|
|
||||||
if (countTotal > 0L){
|
|
||||||
long updateCountTotal = Long.parseLong(historyEdgeDocument.getAttribute(totalSchema).toString());
|
|
||||||
|
|
||||||
Long[] cntRecent = (Long[]) historyEdgeDocument.getAttribute(recentSchema);
|
|
||||||
cntRecent[0] = countTotal;
|
|
||||||
|
|
||||||
historyEdgeDocument.addAttribute(recentSchema, cntRecent);
|
|
||||||
historyEdgeDocument.addAttribute(totalSchema, countTotal + updateCountTotal);
|
|
||||||
String hisProtocolType = historyEdgeDocument.getAttribute("PROTOCOL_TYPE").toString();
|
|
||||||
if (!hisProtocolType.contains(schema)){
|
|
||||||
hisProtocolType = hisProtocolType + "," + schema;
|
|
||||||
historyEdgeDocument.addAttribute("PROTOCOL_TYPE",hisProtocolType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package cn.ac.iie.service.update;
|
package cn.ac.iie.service.update;
|
||||||
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,26 +13,9 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
public class Vertex extends Document<BaseDocument> {
|
public class Vertex extends Document<BaseDocument> {
|
||||||
|
|
||||||
public Vertex(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
public Vertex(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch);
|
super(newDocumentHashMap, collectionName, countDownLatch);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseDocument newDocument, BaseDocument historyDocument) {
|
|
||||||
super.updateFunction(newDocument, historyDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void mergeFunction(BaseDocument lastDoc,BaseDocument newDocument) {
|
|
||||||
super.mergeFunction(lastDoc, newDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
super.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,49 @@
|
|||||||
package cn.ac.iie.service.update.relationship;
|
package cn.ac.iie.service.update.relationship;
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Relationship;
|
import cn.ac.iie.service.update.Relationship;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
|
import ru.yandex.clickhouse.ClickHouseArray;
|
||||||
|
import ru.yandex.clickhouse.domain.ClickHouseDataType;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import static cn.ac.iie.service.read.ReadClickhouseData.DISTINCT_CLIENT_IP_NUM;
|
import static cn.ac.iie.service.ingestion.ReadClickhouseData.currentHour;
|
||||||
import static cn.ac.iie.service.read.ReadClickhouseData.currentHour;
|
|
||||||
|
|
||||||
public class LocateFqdn2Ip extends Relationship {
|
public class LocateFqdn2Ip extends Relationship {
|
||||||
|
|
||||||
public LocateFqdn2Ip(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
public LocateFqdn2Ip(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseEdgeDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap,countDownLatch);
|
super(newDocumentHashMap, collectionName,countDownLatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mergeFunction(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument){
|
protected void mergeFunction(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument){
|
||||||
super.mergeFunction(lastDoc, newDocument);
|
super.mergeFunction(lastDoc, newDocument);
|
||||||
mergeDistinctClientIp(lastDoc, newDocument);
|
mergeDistinctClientIp(lastDoc, newDocument);
|
||||||
putSumAttribute(lastDoc, newDocument,"CNT_TOTAL");
|
mergeProtocol(lastDoc, newDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeDistinctClientIp(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument){
|
@Override
|
||||||
|
protected PreparedStatement setPstm(PreparedStatement pstm,BaseEdgeDocument newDocument) throws SQLException {
|
||||||
|
pstm.setString(1,newDocument.getFrom());
|
||||||
|
pstm.setString(2,newDocument.getTo());
|
||||||
|
pstm.setLong(3,Long.parseLong(newDocument.getAttribute("FIRST_FOUND_TIME").toString()));
|
||||||
|
pstm.setLong(4,Long.parseLong(newDocument.getAttribute("LAST_FOUND_TIME").toString()));
|
||||||
|
pstm.setLong(5,Long.parseLong(newDocument.getAttribute("DNS_CNT_TOTAL").toString()));
|
||||||
|
pstm.setLong(6,Long.parseLong(newDocument.getAttribute("TLS_CNT_TOTAL").toString()));
|
||||||
|
pstm.setLong(7,Long.parseLong(newDocument.getAttribute("HTTP_CNT_TOTAL").toString()));
|
||||||
|
Object[] distCips = (Object[]) newDocument.getAttribute("DIST_CIP");
|
||||||
|
pstm.setArray(8,new ClickHouseArray(ClickHouseDataType.Int64, distCips));
|
||||||
|
pstm.setLong(9,currentHour);
|
||||||
|
|
||||||
|
return pstm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeDistinctClientIp(BaseEdgeDocument lastDoc, BaseEdgeDocument newDocument){
|
||||||
HashSet<String> clientIpSet = new HashSet<>();
|
HashSet<String> clientIpSet = new HashSet<>();
|
||||||
String[] distCips = (String[]) newDocument.getAttribute("DIST_CIP");
|
String[] distCips = (String[]) newDocument.getAttribute("DIST_CIP");
|
||||||
String[] lastDistCips = (String[]) lastDoc.getAttribute("DIST_CIP");
|
String[] lastDistCips = (String[]) lastDoc.getAttribute("DIST_CIP");
|
||||||
@@ -42,54 +57,5 @@ public class LocateFqdn2Ip extends Relationship {
|
|||||||
newDocument.addAttribute("DIST_CIP_TS", clientIpTs);
|
newDocument.addAttribute("DIST_CIP_TS", clientIpTs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseEdgeDocument newEdgeDocument, BaseEdgeDocument historyEdgeDocument) {
|
|
||||||
super.updateFunction(newEdgeDocument, historyEdgeDocument);
|
|
||||||
updateDistinctClientIp(newEdgeDocument, historyEdgeDocument);
|
|
||||||
putSumAttribute(newEdgeDocument, historyEdgeDocument,"CNT_TOTAL");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDistinctClientIp(BaseEdgeDocument newEdgeDocument,BaseEdgeDocument edgeDocument){
|
|
||||||
ArrayList<String> distCip = (ArrayList<String>) edgeDocument.getAttribute("DIST_CIP");
|
|
||||||
ArrayList<Long> distCipTs = (ArrayList<Long>) edgeDocument.getAttribute("DIST_CIP_TS");
|
|
||||||
HashMap<String, Long> distCipToTs = new HashMap<>();
|
|
||||||
if (distCip.size() == distCipTs.size()){
|
|
||||||
for (int i = 0;i < distCip.size();i++){
|
|
||||||
distCipToTs.put(distCip.get(i),distCipTs.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object[] distCipRecent = (Object[])newEdgeDocument.getAttribute("DIST_CIP");
|
|
||||||
for (Object cip:distCipRecent){
|
|
||||||
distCipToTs.put(cip.toString(), currentHour);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Long> sortDistCip = sortMapByValue(distCipToTs);
|
|
||||||
edgeDocument.addAttribute("DIST_CIP",sortDistCip.keySet().toArray());
|
|
||||||
edgeDocument.addAttribute("DIST_CIP_TS",sortDistCip.values().toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用 Map按value进行排序
|
|
||||||
*/
|
|
||||||
private Map<String, Long> sortMapByValue(Map<String, Long> oriMap) {
|
|
||||||
if (oriMap == null || oriMap.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Map<String, Long> sortedMap = new LinkedHashMap<>();
|
|
||||||
List<Map.Entry<String, Long>> entryList = new ArrayList<>(oriMap.entrySet());
|
|
||||||
entryList.sort((o1, o2) -> o2.getValue().compareTo(o1.getValue()));
|
|
||||||
|
|
||||||
if(entryList.size() > DISTINCT_CLIENT_IP_NUM){
|
|
||||||
for(Map.Entry<String, Long> set:entryList.subList(0, DISTINCT_CLIENT_IP_NUM)){
|
|
||||||
sortedMap.put(set.getKey(), set.getValue());
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
for(Map.Entry<String, Long> set:entryList){
|
|
||||||
sortedMap.put(set.getKey(), set.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sortedMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
package cn.ac.iie.service.update.relationship;
|
package cn.ac.iie.service.update.relationship;
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Relationship;
|
import cn.ac.iie.service.update.Relationship;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class LocateSubscriber2Ip extends Relationship {
|
public class LocateSubscriber2Ip extends Relationship {
|
||||||
|
|
||||||
public LocateSubscriber2Ip(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
public LocateSubscriber2Ip(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseEdgeDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch);
|
super(newDocumentHashMap, collectionName, countDownLatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package cn.ac.iie.service.update.relationship;
|
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Relationship;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
public class SameFqdn2Fqdn extends Relationship {
|
|
||||||
|
|
||||||
public SameFqdn2Fqdn(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
|
||||||
ConcurrentHashMap<String, BaseEdgeDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseEdgeDocument newEdgeDocument, BaseEdgeDocument historyEdgeDocument) {
|
|
||||||
super.updateFunction(newEdgeDocument, historyEdgeDocument);
|
|
||||||
putSumAttribute(newEdgeDocument,historyEdgeDocument,"CNT_TOTAL");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void mergeFunction(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument) {
|
|
||||||
super.mergeFunction(lastDoc, newDocument);
|
|
||||||
putSumAttribute(lastDoc,newDocument,"CNT_TOTAL");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,32 +1,23 @@
|
|||||||
package cn.ac.iie.service.update.relationship;
|
package cn.ac.iie.service.update.relationship;
|
||||||
|
|
||||||
|
import cn.ac.iie.service.ingestion.ReadClickhouseData;
|
||||||
import cn.ac.iie.service.update.Relationship;
|
import cn.ac.iie.service.update.Relationship;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class VisitIp2Fqdn extends Relationship {
|
public class VisitIp2Fqdn extends Relationship {
|
||||||
public VisitIp2Fqdn(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
public VisitIp2Fqdn(HashMap<String, ArrayList<BaseEdgeDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseEdgeDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap,countDownLatch);
|
super(newDocumentHashMap, collectionName,countDownLatch);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseEdgeDocument newEdgeDocument, BaseEdgeDocument historyEdgeDocument) {
|
|
||||||
super.updateFunction(newEdgeDocument, historyEdgeDocument);
|
|
||||||
putSumAttribute(newEdgeDocument,historyEdgeDocument,"CNT_TOTAL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mergeFunction(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument) {
|
protected void mergeFunction(BaseEdgeDocument lastDoc,BaseEdgeDocument newDocument) {
|
||||||
super.mergeFunction(lastDoc, newDocument);
|
super.mergeFunction(lastDoc, newDocument);
|
||||||
putSumAttribute(lastDoc,newDocument,"CNT_TOTAL");
|
mergeProtocol(lastDoc,newDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
package cn.ac.iie.service.update.vertex;
|
package cn.ac.iie.service.update.vertex;
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Vertex;
|
import cn.ac.iie.service.update.Vertex;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class Fqdn extends Vertex {
|
public class Fqdn extends Vertex {
|
||||||
|
|
||||||
public Fqdn(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
public Fqdn(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap,countDownLatch);
|
super(newDocumentHashMap, collectionName,countDownLatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,24 @@
|
|||||||
package cn.ac.iie.service.update.vertex;
|
package cn.ac.iie.service.update.vertex;
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Vertex;
|
import cn.ac.iie.service.update.Vertex;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class Ip extends Vertex {
|
public class Ip extends Vertex {
|
||||||
|
|
||||||
public Ip(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
public Ip(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch);
|
super(newDocumentHashMap, collectionName,countDownLatch);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateFunction(BaseDocument newDocument, BaseDocument historyDocument) {
|
|
||||||
super.updateFunction(newDocument, historyDocument);
|
|
||||||
updateIpByType(newDocument, historyDocument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mergeFunction(BaseDocument lastDoc, BaseDocument newDocument) {
|
protected void mergeFunction(BaseDocument lastDoc, BaseDocument newDocument) {
|
||||||
super.mergeFunction(lastDoc, newDocument);
|
super.mergeFunction(lastDoc, newDocument);
|
||||||
mergeIpByType(lastDoc, newDocument);
|
updateIpByType(lastDoc, newDocument);
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeIpByType(BaseDocument lastDoc, BaseDocument newDocument) {
|
|
||||||
putSumAttribute(lastDoc,newDocument,"CLIENT_SESSION_COUNT");
|
|
||||||
putSumAttribute(lastDoc,newDocument,"CLIENT_BYTES_SUM");
|
|
||||||
putSumAttribute(lastDoc,newDocument,"SERVER_SESSION_COUNT");
|
|
||||||
putSumAttribute(lastDoc,newDocument,"SERVER_BYTES_SUM");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIpByType(BaseDocument newDocument, BaseDocument historyDocument) {
|
private void updateIpByType(BaseDocument newDocument, BaseDocument historyDocument) {
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
package cn.ac.iie.service.update.vertex;
|
package cn.ac.iie.service.update.vertex;
|
||||||
|
|
||||||
import cn.ac.iie.service.update.Vertex;
|
import cn.ac.iie.service.update.Vertex;
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
import com.arangodb.entity.BaseDocument;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
public class Subscriber extends Vertex {
|
public class Subscriber extends Vertex {
|
||||||
|
|
||||||
public Subscriber(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
public Subscriber(HashMap<String, ArrayList<BaseDocument>> newDocumentHashMap,
|
||||||
ArangoDBConnect arangoManger,
|
|
||||||
String collectionName,
|
String collectionName,
|
||||||
ConcurrentHashMap<String, BaseDocument> historyDocumentMap,
|
|
||||||
CountDownLatch countDownLatch) {
|
CountDownLatch countDownLatch) {
|
||||||
super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch);
|
super(newDocumentHashMap, collectionName, countDownLatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,9 @@ package cn.ac.iie.test;
|
|||||||
|
|
||||||
import cn.ac.iie.dao.UpdateGraphData;
|
import cn.ac.iie.dao.UpdateGraphData;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* iplearning程序入口
|
|
||||||
* @author wlh
|
|
||||||
*/
|
|
||||||
public class IpLearningApplicationTest {
|
public class IpLearningApplicationTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
UpdateGraphData updateGraphData = new UpdateGraphData();
|
UpdateGraphData updateGraphData = new UpdateGraphData();
|
||||||
updateGraphData.updateArango();
|
updateGraphData.updateArango();
|
||||||
|
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
package cn.ac.iie.utils;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import com.arangodb.ArangoCollection;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.ArangoDB;
|
|
||||||
import com.arangodb.ArangoDatabase;
|
|
||||||
import com.arangodb.entity.DocumentCreateEntity;
|
|
||||||
import com.arangodb.entity.ErrorEntity;
|
|
||||||
import com.arangodb.entity.MultiDocumentEntity;
|
|
||||||
import com.arangodb.model.AqlQueryOptions;
|
|
||||||
import com.arangodb.model.DocumentCreateOptions;
|
|
||||||
import com.arangodb.util.MapBuilder;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ArangoDBConnect {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ArangoDBConnect.class);
|
|
||||||
private static ArangoDB arangoDB = null;
|
|
||||||
private static ArangoDBConnect conn = null;
|
|
||||||
static {
|
|
||||||
getArangoDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void getArangoDatabase(){
|
|
||||||
arangoDB = new ArangoDB.Builder()
|
|
||||||
.maxConnections(ApplicationConfig.THREAD_POOL_NUMBER)
|
|
||||||
.host(ApplicationConfig.ARANGODB_HOST, ApplicationConfig.ARANGODB_PORT)
|
|
||||||
.user(ApplicationConfig.ARANGODB_USER)
|
|
||||||
.password(ApplicationConfig.ARANGODB_PASSWORD)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized ArangoDBConnect getInstance(){
|
|
||||||
if (null == conn){
|
|
||||||
conn = new ArangoDBConnect();
|
|
||||||
}
|
|
||||||
return conn;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArangoDatabase getDatabase(){
|
|
||||||
return arangoDB.db(ApplicationConfig.ARANGODB_DB_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clean(){
|
|
||||||
try {
|
|
||||||
if (arangoDB != null){
|
|
||||||
arangoDB.shutdown();
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> ArangoCursor<T> executorQuery(String query,Class<T> type){
|
|
||||||
ArangoDatabase database = getDatabase();
|
|
||||||
Map<String, Object> bindVars = new MapBuilder().get();
|
|
||||||
AqlQueryOptions options = new AqlQueryOptions().ttl(ApplicationConfig.ARANGODB_TTL);
|
|
||||||
try {
|
|
||||||
return database.query(query, bindVars, options, type);
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}finally {
|
|
||||||
bindVars.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public <T> void insertAndUpdate(ArrayList<T> docInsert,ArrayList<T> docUpdate,String collectionName){
|
|
||||||
ArangoDatabase database = getDatabase();
|
|
||||||
try {
|
|
||||||
ArangoCollection collection = database.collection(collectionName);
|
|
||||||
if (!docInsert.isEmpty()){
|
|
||||||
collection.importDocuments(docInsert);
|
|
||||||
}
|
|
||||||
if (!docUpdate.isEmpty()){
|
|
||||||
collection.replaceDocuments(docUpdate);
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
System.out.println("更新失败");
|
|
||||||
e.printStackTrace();
|
|
||||||
}finally {
|
|
||||||
docInsert.clear();
|
|
||||||
docInsert.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void overwrite(ArrayList<T> docOverwrite,String collectionName){
|
|
||||||
ArangoDatabase database = getDatabase();
|
|
||||||
try {
|
|
||||||
ArangoCollection collection = database.collection(collectionName);
|
|
||||||
if (!docOverwrite.isEmpty()){
|
|
||||||
DocumentCreateOptions documentCreateOptions = new DocumentCreateOptions();
|
|
||||||
documentCreateOptions.overwrite(true);
|
|
||||||
documentCreateOptions.silent(true);
|
|
||||||
MultiDocumentEntity<DocumentCreateEntity<T>> documentCreateEntityMultiDocumentEntity = collection.insertDocuments(docOverwrite, documentCreateOptions);
|
|
||||||
Collection<ErrorEntity> errors = documentCreateEntityMultiDocumentEntity.getErrors();
|
|
||||||
for (ErrorEntity errorEntity:errors){
|
|
||||||
LOG.debug("写入arangoDB异常:"+errorEntity.getErrorMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
System.out.println("更新失败:"+e.toString());
|
|
||||||
}finally {
|
|
||||||
docOverwrite.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ package cn.ac.iie.utils;
|
|||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -10,6 +12,7 @@ import java.sql.Statement;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class ClickhouseConnect {
|
public class ClickhouseConnect {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ClickhouseConnect.class);
|
||||||
private static DruidDataSource dataSource = null;
|
private static DruidDataSource dataSource = null;
|
||||||
private static ClickhouseConnect dbConnect = null;
|
private static ClickhouseConnect dbConnect = null;
|
||||||
private static Properties props = new Properties();
|
private static Properties props = new Properties();
|
||||||
@@ -43,7 +46,7 @@ public class ClickhouseConnect {
|
|||||||
dataSource.setKeepAlive(true);
|
dataSource.setKeepAlive(true);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOG.error(e.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,7 +88,7 @@ public class ClickhouseConnect {
|
|||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -98,7 +101,7 @@ public class ClickhouseConnect {
|
|||||||
pstm = connection.createStatement();
|
pstm = connection.createStatement();
|
||||||
return pstm.executeQuery(query);
|
return pstm.executeQuery(query);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
LOG.error(e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package cn.ac.iie.utils;
|
package cn.ac.iie.utils;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class ConfigUtils {
|
public class ConfigUtils {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ConfigUtils.class);
|
||||||
private static Properties propCommon = new Properties();
|
private static Properties propCommon = new Properties();
|
||||||
|
|
||||||
public static String getStringProperty(String key) {
|
public static String getStringProperty(String key) {
|
||||||
@@ -25,12 +29,12 @@ public class ConfigUtils {
|
|||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
propCommon.load(ConfigUtils.class.getClassLoader().getResourceAsStream("application.properties"));
|
propCommon.load(ConfigUtils.class.getClassLoader().getResourceAsStream("application.properties"));
|
||||||
System.out.println("application.properties加载成功");
|
LOG.info("application.properties加载成功");
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
propCommon = null;
|
propCommon = null;
|
||||||
System.err.println("配置加载失败");
|
LOG.error("配置加载失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ package cn.ac.iie.utils;
|
|||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
import cn.ac.iie.config.ApplicationConfig;
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* 线程池管理
|
|
||||||
* @author wlh
|
|
||||||
*/
|
|
||||||
public class ExecutorThreadPool {
|
public class ExecutorThreadPool {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ExecutorThreadPool.class);
|
||||||
private static ExecutorService pool = null ;
|
private static ExecutorService pool = null ;
|
||||||
private static ExecutorThreadPool poolExecutor = null;
|
private static ExecutorThreadPool poolExecutor = null;
|
||||||
|
|
||||||
@@ -20,13 +19,9 @@ public class ExecutorThreadPool {
|
|||||||
private static void getThreadPool(){
|
private static void getThreadPool(){
|
||||||
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
|
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
|
||||||
.setNameFormat("iplearning-application-pool-%d").build();
|
.setNameFormat("iplearning-application-pool-%d").build();
|
||||||
|
pool = new ThreadPoolExecutor(ApplicationConfig.THREAD_POOL_NUMBER, ApplicationConfig.THREAD_POOL_NUMBER,
|
||||||
//Common Thread Pool
|
0L, TimeUnit.SECONDS,
|
||||||
pool = new ThreadPoolExecutor(ApplicationConfig.THREAD_POOL_NUMBER, ApplicationConfig.THREAD_POOL_NUMBER*2,
|
|
||||||
0L, TimeUnit.MILLISECONDS,
|
|
||||||
new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
|
new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
|
||||||
|
|
||||||
// pool = Executors.newFixedThreadPool(ApplicationConfig.THREAD_POOL_NUMBER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExecutorThreadPool getInstance(){
|
public static ExecutorThreadPool getInstance(){
|
||||||
@@ -44,7 +39,7 @@ public class ExecutorThreadPool {
|
|||||||
public void awaitThreadTask(){
|
public void awaitThreadTask(){
|
||||||
try {
|
try {
|
||||||
while (!pool.awaitTermination(ApplicationConfig.THREAD_AWAIT_TERMINATION_TIME, TimeUnit.SECONDS)) {
|
while (!pool.awaitTermination(ApplicationConfig.THREAD_AWAIT_TERMINATION_TIME, TimeUnit.SECONDS)) {
|
||||||
System.out.println("线程池没有关闭");
|
LOG.warn("线程池没有关闭");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,161 +0,0 @@
|
|||||||
package cn.ac.iie.utils;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class TopDomainUtils {
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(TopDomainUtils.class);
|
|
||||||
|
|
||||||
|
|
||||||
public static String getSecDomain(String urlDomain, HashMap<String, HashMap<String, String>> maps) {
|
|
||||||
String[] split = urlDomain.split("\\.");
|
|
||||||
String secDomain = null;
|
|
||||||
for (int i = split.length - 1; i >= 0; i--) {
|
|
||||||
int mapsIndex = split.length - (i + 1);
|
|
||||||
HashMap<String, String> innerMap = maps.get("map_id_" + mapsIndex);
|
|
||||||
HashMap<String, String> fullTop = maps.get("full");
|
|
||||||
if (!(innerMap.containsKey(split[i]))) {
|
|
||||||
StringBuilder strSec = new StringBuilder();
|
|
||||||
for (int j = i; j < split.length; j++) {
|
|
||||||
strSec.append(split[j]).append(".");
|
|
||||||
}
|
|
||||||
secDomain = strSec.substring(0, strSec.length() - 1);
|
|
||||||
if (fullTop.containsKey(getTopDomainFromSecDomain(secDomain))) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
while (!fullTop.containsKey(getTopDomainFromSecDomain(secDomain)) && getTopDomainFromSecDomain(secDomain).contains(".")) {
|
|
||||||
secDomain = getTopDomainFromSecDomain(secDomain);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return secDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTopDomainFromSecDomain(String secDomain) {
|
|
||||||
String quFirstDian = secDomain;
|
|
||||||
if (secDomain.contains(".")) {
|
|
||||||
quFirstDian = secDomain.substring(secDomain.indexOf(".")).substring(1);
|
|
||||||
}
|
|
||||||
return quFirstDian;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getTopDomainFile(){
|
|
||||||
URL url = TopDomainUtils.class.getClassLoader().getResource(ApplicationConfig.TOP_DOMAIN_FILE_NAME);
|
|
||||||
File file = null;
|
|
||||||
if (url!=null){
|
|
||||||
file = new File(url.getFile());
|
|
||||||
}
|
|
||||||
if (file != null && file.isFile() && file.exists()){
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HashMap<String, HashMap<String, String>> readTopDomainFile() {
|
|
||||||
URL url = TopDomainUtils.class.getClassLoader().getResource(ApplicationConfig.TOP_DOMAIN_FILE_NAME);
|
|
||||||
assert url != null;
|
|
||||||
HashMap<String, HashMap<String, String>> maps = makeHashMap(url.getFile());
|
|
||||||
try {
|
|
||||||
String encoding = "UTF-8";
|
|
||||||
File file = new File(url.getFile());
|
|
||||||
if (file.isFile() && file.exists()) {
|
|
||||||
InputStreamReader read = new InputStreamReader(
|
|
||||||
new FileInputStream(file), encoding);
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(read);
|
|
||||||
String lineTxt;
|
|
||||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
|
||||||
HashMap<String, String> fullTop = maps.get("full");
|
|
||||||
fullTop.put(lineTxt, lineTxt);
|
|
||||||
maps.put("full", fullTop);
|
|
||||||
String[] split = lineTxt.split("\\.");
|
|
||||||
for (int i = split.length - 1; i >= 0; i--) {
|
|
||||||
int mapsIndex = split.length - (i + 1);
|
|
||||||
HashMap<String, String> innerMap = maps.get("map_id_" + mapsIndex);
|
|
||||||
innerMap.put(split[i], split[i]);
|
|
||||||
maps.put("map_id_" + mapsIndex, innerMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
read.close();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("TopDomainUtils>=>readTopDomainFile get filePathData error--->{" + e + "}<---");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return maps;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getMaxLength(String filePath) {
|
|
||||||
int lengthDomain = 0;
|
|
||||||
try {
|
|
||||||
String encoding = "UTF-8";
|
|
||||||
File file = new File(filePath);
|
|
||||||
if (file.isFile() && file.exists()) {
|
|
||||||
InputStreamReader read = new InputStreamReader(
|
|
||||||
new FileInputStream(file), encoding);
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(read);
|
|
||||||
String lineTxt;
|
|
||||||
while ((lineTxt = bufferedReader.readLine()) != null) {
|
|
||||||
String[] split = lineTxt.split("\\.");
|
|
||||||
if (split.length > lengthDomain) {
|
|
||||||
lengthDomain = split.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
read.close();
|
|
||||||
} else {
|
|
||||||
logger.error("TopDomainUtils>>getMaxLength filePath is wrong--->{" + filePath + "}<---");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("TopDomainUtils>=>getMaxLength get filePathData error--->{" + e + "}<---");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return lengthDomain;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HashMap<String, HashMap<String, String>> makeHashMap(String filePath) {
|
|
||||||
int maxLength = getMaxLength(filePath);
|
|
||||||
HashMap<String, HashMap<String, String>> maps = new HashMap<>();
|
|
||||||
for (int i = 0; i < maxLength; i++) {
|
|
||||||
maps.put("map_id_" + i, new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
maps.put("full", new HashMap<String, String>());
|
|
||||||
return maps;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用方法,传入url,返回domain,这里的domain不包含端口号,含有:一定是v6
|
|
||||||
* @param oriUrl
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getDomainFromUrl(String oriUrl) {
|
|
||||||
//先按照?切分,排除后续干扰
|
|
||||||
String url = oriUrl.split("[?]")[0];
|
|
||||||
//排除http://或https://干扰
|
|
||||||
url = url.replaceAll("https://", "").replaceAll("http://", "");
|
|
||||||
String domain;
|
|
||||||
|
|
||||||
//获取domain
|
|
||||||
if (url.split("/")[0].split(":").length <= 2) {
|
|
||||||
//按照:切分后最终长度为1或2,说明是v4
|
|
||||||
domain = url
|
|
||||||
//按照/切分,索引0包含domain
|
|
||||||
.split("/")[0]
|
|
||||||
//v4按照:切分去除domain上的端口号后,索引0为最终域名
|
|
||||||
.split(":")[0];
|
|
||||||
} else {
|
|
||||||
//按照:切分后长度>2,说明是v6地址,v6地址不包含端口号(暂定),只需要先切分//再切分/
|
|
||||||
domain = url.split("/")[0];
|
|
||||||
}
|
|
||||||
return domain;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,25 @@
|
|||||||
#arangoDB参数配置
|
#arangoDB参数配置
|
||||||
arangoDB.host=192.168.40.182
|
arangoDB.host=192.168.44.12
|
||||||
arangoDB.port=8529
|
arangoDB.port=8529
|
||||||
arangoDB.user=upsert
|
arangoDB.user=upsert
|
||||||
arangoDB.password=ceiec2018
|
arangoDB.password=ceiec2018
|
||||||
arangoDB.DB.name=ip-learning-test
|
arangoDB.DB.name=tsg_galaxy_v3
|
||||||
arangoDB.batch=100000
|
arangoDB.batch=100000
|
||||||
arangoDB.ttl=3600
|
arangoDB.ttl=3600
|
||||||
|
|
||||||
|
arangoDB.read.limit=
|
||||||
update.arango.batch=10000
|
update.arango.batch=10000
|
||||||
|
|
||||||
thread.pool.number=10
|
thread.pool.number=10
|
||||||
thread.await.termination.time=10
|
thread.await.termination.time=10
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#读取clickhouse时间范围方式,0:读取过去一小时,1:指定时间范围
|
#读取clickhouse时间范围方式,0:读取过去一小时,1:指定时间范围
|
||||||
clickhouse.time.limit.type=0
|
time.limit.type=1
|
||||||
read.clickhouse.max.time=1571245230
|
read.clickhouse.max.time=1571241610
|
||||||
read.clickhouse.min.time=1571245220
|
read.clickhouse.min.time=1571241600
|
||||||
|
|
||||||
#读取arangoDB时间范围方式,0:正常读,1:指定时间范围
|
|
||||||
arango.time.limit.type=0
|
|
||||||
read.arango.max.time=1571245220
|
|
||||||
read.arango.min.time=1571245210
|
|
||||||
|
|
||||||
update.interval=3600
|
update.interval=3600
|
||||||
distinct.client.ip.num=10000
|
distinct.client.ip.num=10000
|
||||||
recent.count.hour=24
|
recent.count.hour=24
|
||||||
|
|
||||||
top.domain.file.name=topDomain.txt
|
|
||||||
|
|
||||||
arangoDB.read.limit=
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
drivers=ru.yandex.clickhouse.ClickHouseDriver
|
drivers=ru.yandex.clickhouse.ClickHouseDriver
|
||||||
db.id=192.168.40.193:8123/tsg_galaxy_zx?socket_timeout=3600000
|
|
||||||
#db.id=192.168.40.186:8123/tsg_galaxy_v3?socket_timeout=300000
|
|
||||||
mdb.user=default
|
mdb.user=default
|
||||||
|
#db.id=192.168.44.10:8124/tsg_galaxy_v3?socket_timeout=300000
|
||||||
|
#db.id=192.168.44.12:8123/tsg_galaxy_v3?socket_timeout=300000&compress=0
|
||||||
|
#mdb.password=ceiec2019
|
||||||
|
db.id=192.168.40.193:8123/tsg_galaxy_zx?socket_timeout=3600000
|
||||||
mdb.password=111111
|
mdb.password=111111
|
||||||
initialsize=1
|
initialsize=1
|
||||||
minidle=1
|
minidle=1
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ log4j.logger.org.apache.http.wire=OFF
|
|||||||
|
|
||||||
#Log4j
|
#Log4j
|
||||||
log4j.rootLogger=info,console,file
|
log4j.rootLogger=info,console,file
|
||||||
# <20><><EFBFBD><EFBFBD>̨<EFBFBD><CCA8>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
# <20><><EFBFBD><EFBFBD>̨<EFBFBD><CCA8>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.console.Threshold=info
|
log4j.appender.console.Threshold=info
|
||||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.console.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}] [%-5p] [Thread\:%t] %l %x - <%m>%n
|
log4j.appender.console.layout.ConversionPattern=[%d{yyyy-MM-dd HH\:mm\:ss}] [%-5p] [Thread\:%t] %l %x - <%m>%n
|
||||||
|
|
||||||
# <20>ļ<EFBFBD><C4BC><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
# <20>ļ<EFBFBD><C4BC><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||||
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
|
||||||
log4j.appender.file.Threshold=info
|
log4j.appender.file.Threshold=info
|
||||||
log4j.appender.file.encoding=UTF-8
|
log4j.appender.file.encoding=UTF-8
|
||||||
log4j.appender.file.Append=true
|
log4j.appender.file.Append=true
|
||||||
#·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>
|
#·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>
|
||||||
#log4j.appender.file.file=/home/ceiec/iplearning/logs/ip-learning-application.log
|
#log4j.appender.file.file=/home/ceiec/iplearning/logs/ip-learning-application.log
|
||||||
#log4j.appender.file.file=/home/ceiec/iplearning/testLog/ip-learning-application.log
|
#log4j.appender.file.file=/home/ceiec/iplearning/testLog/ip-learning-application.log
|
||||||
log4j.appender.file.file=./logs/ip-learning-application.log
|
log4j.appender.file.file=./logs/ip-learning-application.log
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
|||||||
package cn.ac.iie;
|
package cn.ac.iie;
|
||||||
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.ArangoCursor;
|
import com.arangodb.ArangoCursor;
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
import com.arangodb.entity.BaseEdgeDocument;
|
||||||
|
|
||||||
@@ -11,6 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class TestList {
|
public class TestList {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
/*
|
||||||
ArangoDBConnect arangoConnect = ArangoDBConnect.getInstance();
|
ArangoDBConnect arangoConnect = ArangoDBConnect.getInstance();
|
||||||
ArangoCursor<BaseEdgeDocument> documents = arangoConnect.executorQuery("FOR doc IN R_LOCATE_FQDN2IP filter doc.FIRST_FOUND_TIME >= 1596080839 and doc.FIRST_FOUND_TIME <= 1596395473 RETURN doc", BaseEdgeDocument.class);
|
ArangoCursor<BaseEdgeDocument> documents = arangoConnect.executorQuery("FOR doc IN R_LOCATE_FQDN2IP filter doc.FIRST_FOUND_TIME >= 1596080839 and doc.FIRST_FOUND_TIME <= 1596395473 RETURN doc", BaseEdgeDocument.class);
|
||||||
List<BaseEdgeDocument> baseEdgeDocuments = documents.asListRemaining();
|
List<BaseEdgeDocument> baseEdgeDocuments = documents.asListRemaining();
|
||||||
@@ -18,8 +18,8 @@ public class TestList {
|
|||||||
doc.updateAttribute("PROTOCOL_TYPE","123");
|
doc.updateAttribute("PROTOCOL_TYPE","123");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
ArrayList<Integer> integers = new ArrayList<>();
|
ArrayList<Integer> integers = new ArrayList<>();
|
||||||
integers.add(10);
|
integers.add(10);
|
||||||
integers.add(8);
|
integers.add(8);
|
||||||
@@ -39,7 +39,9 @@ public class TestList {
|
|||||||
integers.add(5);
|
integers.add(5);
|
||||||
Collections.sort(integers);
|
Collections.sort(integers);
|
||||||
System.out.println(integers);
|
System.out.println(integers);
|
||||||
|
Collections.reverse(integers);
|
||||||
|
System.out.println(integers);
|
||||||
System.out.println(integers.indexOf(5));
|
System.out.println(integers.indexOf(5));
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package cn.ac.iie;
|
package cn.ac.iie;
|
||||||
|
|
||||||
import cn.ac.iie.dao.BaseArangoData;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import cn.ac.iie.utils.ExecutorThreadPool;
|
|
||||||
import com.arangodb.entity.*;
|
import com.arangodb.entity.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class TestMap {
|
public class TestMap {
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package cn.ac.iie;
|
|
||||||
|
|
||||||
import cn.ac.iie.dao.BaseArangoData;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
|
||||||
|
|
||||||
public class readHistoryDataTest {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
ArangoDBConnect instance = ArangoDBConnect.getInstance();
|
|
||||||
// ArangoCursor<Long> baseDocuments = instance.executorQuery("RETURN LENGTH(R_LOCATE_FQDN2IP)", Long.class);
|
|
||||||
// while (baseDocuments.hasNext()){
|
|
||||||
// Long next = baseDocuments.next();
|
|
||||||
// System.out.println(next.toString());
|
|
||||||
// }
|
|
||||||
// instance.clean();
|
|
||||||
|
|
||||||
String sql = "FOR doc IN FQDN filter doc.FIRST_FOUND_TIME >= 1595423493 and doc.FIRST_FOUND_TIME <= 1595809766 limit 763,10 RETURN doc";
|
|
||||||
ArangoCursor<BaseDocument> baseDocuments = instance.executorQuery(sql, BaseDocument.class);
|
|
||||||
while (baseDocuments.hasNext()){
|
|
||||||
BaseDocument next = baseDocuments.next();
|
|
||||||
System.out.println(next.toString());
|
|
||||||
}
|
|
||||||
instance.clean();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,6 +27,12 @@
|
|||||||
<version>4.4.6</version>
|
<version>4.4.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid</artifactId>
|
||||||
|
<version>1.1.10</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
@@ -75,6 +81,12 @@
|
|||||||
<version>3.2.0</version>
|
<version>3.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.scala-lang.modules</groupId>
|
||||||
|
<artifactId>scala-xml_2.11</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.scala-tools</groupId>
|
<groupId>org.scala-tools</groupId>
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
package cn.ac.iie.dao;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import cn.ac.iie.service.read.ReadHistoryArangoData;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import cn.ac.iie.utils.ExecutorThreadPool;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
|
||||||
import com.arangodb.entity.BaseEdgeDocument;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取arangoDB历史数据
|
|
||||||
*
|
|
||||||
* @author wlh
|
|
||||||
*/
|
|
||||||
public class BaseArangoData {
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BaseArangoData.class);
|
|
||||||
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexIpMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseDocument>> historyVertexSubscriberMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationFqdnAddressIpMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationIpVisitFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationFqdnSameFqdnMap = new ConcurrentHashMap<>();
|
|
||||||
public static ConcurrentHashMap<Integer, ConcurrentHashMap<String, BaseEdgeDocument>> historyRelationSubsciberLocateIpMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private static ArangoDBConnect arangoDBConnect = ArangoDBConnect.getInstance();
|
|
||||||
|
|
||||||
private ExecutorThreadPool threadPool = ExecutorThreadPool.getInstance();
|
|
||||||
|
|
||||||
public <T extends BaseDocument> void readHistoryData(String table,
|
|
||||||
ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> historyMap,
|
|
||||||
Class<T> type) {
|
|
||||||
try {
|
|
||||||
LOG.warn("开始更新" + table);
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER(); i++) {
|
|
||||||
historyMap.put(i, new ConcurrentHashMap<>());
|
|
||||||
}
|
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER());
|
|
||||||
long[] timeRange = getTimeRange(table);
|
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER(); i++) {
|
|
||||||
String sql = getQuerySql(timeRange, i, table);
|
|
||||||
ReadHistoryArangoData<T> readHistoryArangoData = new ReadHistoryArangoData<>(arangoDBConnect, sql, historyMap, type, table, countDownLatch);
|
|
||||||
threadPool.executor(readHistoryArangoData);
|
|
||||||
}
|
|
||||||
countDownLatch.await();
|
|
||||||
long last = System.currentTimeMillis();
|
|
||||||
LOG.warn("读取" + table + " arangoDB 共耗时:" + (last - start));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private long[] getTimeRange(String table) {
|
|
||||||
long minTime = 0L;
|
|
||||||
long maxTime = 0L;
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
String sql = "LET doc = (FOR doc IN " + table + " RETURN doc) return {max_time:MAX(doc[*].FIRST_FOUND_TIME),min_time:MIN(doc[*].FIRST_FOUND_TIME)}";
|
|
||||||
switch (ApplicationConfig.ARANGO_TIME_LIMIT_TYPE()) {
|
|
||||||
case 0:
|
|
||||||
ArangoCursor<BaseDocument> timeDoc = arangoDBConnect.executorQuery(sql, BaseDocument.class);
|
|
||||||
try {
|
|
||||||
if (timeDoc != null) {
|
|
||||||
while (timeDoc.hasNext()) {
|
|
||||||
BaseDocument doc = timeDoc.next();
|
|
||||||
maxTime = Long.parseLong(doc.getAttribute("max_time").toString()) + ApplicationConfig.THREAD_POOL_NUMBER();
|
|
||||||
minTime = Long.parseLong(doc.getAttribute("min_time").toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOG.warn("获取ArangoDb时间范围为空");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
maxTime = ApplicationConfig.READ_ARANGO_MAX_TIME();
|
|
||||||
minTime = ApplicationConfig.READ_ARANGO_MIN_TIME();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
long lastTime = System.currentTimeMillis();
|
|
||||||
LOG.warn(sql + "\n查询最大最小时间用时:" + (lastTime - startTime));
|
|
||||||
return new long[]{minTime, maxTime};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getQuerySql(long[] timeRange, int threadNumber, String table) {
|
|
||||||
long minTime = timeRange[0];
|
|
||||||
long maxTime = timeRange[1];
|
|
||||||
long diffTime = (maxTime - minTime) / ApplicationConfig.THREAD_POOL_NUMBER();
|
|
||||||
long maxThreadTime = minTime + (threadNumber + 1) * diffTime;
|
|
||||||
long minThreadTime = minTime + threadNumber * diffTime;
|
|
||||||
return "FOR doc IN " + table + " filter doc.FIRST_FOUND_TIME >= " + minThreadTime + " and doc.FIRST_FOUND_TIME <= " + maxThreadTime + " " + ApplicationConfig.ARANGODB_READ_LIMIT() + " RETURN doc";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
package cn.ac.iie.service.read;
|
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig;
|
|
||||||
import cn.ac.iie.utils.ArangoDBConnect;
|
|
||||||
import com.arangodb.ArangoCursor;
|
|
||||||
import com.arangodb.entity.BaseDocument;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author wlh
|
|
||||||
* 多线程全量读取arangoDb历史数据,封装到map
|
|
||||||
*/
|
|
||||||
public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|
||||||
public static long currentHour = System.currentTimeMillis() / (60 * 60 * 1000) * 60 * 60;
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ReadHistoryArangoData.class);
|
|
||||||
static final Integer RECENT_COUNT_HOUR = ApplicationConfig.RECENT_COUNT_HOUR();
|
|
||||||
|
|
||||||
public static final HashSet<String> PROTOCOL_SET;
|
|
||||||
|
|
||||||
static {
|
|
||||||
PROTOCOL_SET = new HashSet<>();
|
|
||||||
PROTOCOL_SET.add("HTTP");
|
|
||||||
PROTOCOL_SET.add("TLS");
|
|
||||||
PROTOCOL_SET.add("DNS");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArangoDBConnect arangoConnect;
|
|
||||||
private String query;
|
|
||||||
private ConcurrentHashMap<Integer,ConcurrentHashMap<String, T>> map;
|
|
||||||
private Class<T> type;
|
|
||||||
private String table;
|
|
||||||
private CountDownLatch countDownLatch;
|
|
||||||
|
|
||||||
public ReadHistoryArangoData(ArangoDBConnect arangoConnect,
|
|
||||||
String query,
|
|
||||||
ConcurrentHashMap<Integer,ConcurrentHashMap<String, T>> map,
|
|
||||||
Class<T> type,
|
|
||||||
String table,
|
|
||||||
CountDownLatch countDownLatch) {
|
|
||||||
this.arangoConnect = arangoConnect;
|
|
||||||
this.query = query;
|
|
||||||
this.map = map;
|
|
||||||
this.type = type;
|
|
||||||
this.table = table;
|
|
||||||
this.countDownLatch = countDownLatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
long s = System.currentTimeMillis();
|
|
||||||
ArangoCursor<T> docs = arangoConnect.executorQuery(query, type);
|
|
||||||
if (docs != null) {
|
|
||||||
List<T> baseDocuments = docs.asListRemaining();
|
|
||||||
int i = 0;
|
|
||||||
for (T doc : baseDocuments) {
|
|
||||||
String key = doc.getKey();
|
|
||||||
switch (table) {
|
|
||||||
case "R_LOCATE_FQDN2IP":
|
|
||||||
// updateProtocolDocument(doc);
|
|
||||||
deleteDistinctClientIpByTime(doc);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
int hashCode = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER();
|
|
||||||
ConcurrentHashMap<String, T> tmpMap = map.get(hashCode);
|
|
||||||
tmpMap.put(key, doc);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
long l = System.currentTimeMillis();
|
|
||||||
LOG.warn(query + "\n读取" + i + "条数据,运行时间:" + (l - s));
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}finally {
|
|
||||||
countDownLatch.countDown();
|
|
||||||
LOG.warn("本线程读取完毕,剩余线程数量:"+countDownLatch.getCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateProtocolDocument(T doc) {
|
|
||||||
if (doc.getProperties().containsKey("PROTOCOL_TYPE")) {
|
|
||||||
for (String protocol : PROTOCOL_SET) {
|
|
||||||
String protocolRecent = protocol + "_CNT_RECENT";
|
|
||||||
ArrayList<Long> cntRecent = (ArrayList<Long>) doc.getAttribute(protocolRecent);
|
|
||||||
Long[] cntRecentsSrc = cntRecent.toArray(new Long[cntRecent.size()]);
|
|
||||||
Long[] cntRecentsDst = new Long[RECENT_COUNT_HOUR];
|
|
||||||
System.arraycopy(cntRecentsSrc, 0, cntRecentsDst, 1, cntRecentsSrc.length - 1);
|
|
||||||
cntRecentsDst[0] = 0L;
|
|
||||||
doc.addAttribute(protocolRecent, cntRecentsDst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteDistinctClientIpByTime(T doc) {
|
|
||||||
ArrayList<String> distCip = (ArrayList<String>) doc.getAttribute("DIST_CIP");
|
|
||||||
ArrayList<Long> distCipTs = (ArrayList<Long>) doc.getAttribute("DIST_CIP_TS");
|
|
||||||
distCipTs.add(currentHour - RECENT_COUNT_HOUR * 3600);
|
|
||||||
Collections.sort(distCipTs);
|
|
||||||
int index = distCipTs.indexOf(currentHour - RECENT_COUNT_HOUR * 3600);
|
|
||||||
String[] distCipArr = new String[index];
|
|
||||||
long[] disCipTsArr = new long[index];
|
|
||||||
if (distCip.size() + 1 == distCipTs.size()){
|
|
||||||
for (int i = 0; i < index; i++) {
|
|
||||||
distCipArr[i] = distCip.get(i);
|
|
||||||
disCipTsArr[i] = distCipTs.get(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doc.updateAttribute("DIST_CIP", distCipArr);
|
|
||||||
doc.updateAttribute("DIST_CIP_TS", disCipTsArr);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package cn.ac.iie.utils;
|
||||||
|
|
||||||
|
import cn.ac.iie.config.ApplicationConfig;
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class ClickhouseConnect {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ClickhouseConnect.class);
|
||||||
|
private static DruidDataSource dataSource = null;
|
||||||
|
private static ClickhouseConnect dbConnect = null;
|
||||||
|
|
||||||
|
static {
|
||||||
|
getDbConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getDbConnect() {
|
||||||
|
try {
|
||||||
|
if (dataSource == null) {
|
||||||
|
dataSource = new DruidDataSource();
|
||||||
|
//设置连接参数
|
||||||
|
dataSource.setUrl(ApplicationConfig.SPARK_WRITE_CLICKHOUSE_URL());
|
||||||
|
dataSource.setDriverClassName(ApplicationConfig.SPARK_READ_CLICKHOUSE_DRIVER());
|
||||||
|
dataSource.setUsername(ApplicationConfig.SPARK_READ_CLICKHOUSE_USER());
|
||||||
|
dataSource.setPassword(ApplicationConfig.SPARK_READ_CLICKHOUSE_PASSWORD());
|
||||||
|
//配置初始化大小、最小、最大
|
||||||
|
dataSource.setInitialSize(ApplicationConfig.SPARK_WRITE_CLICKHOUSE_INITIALSIZE());
|
||||||
|
dataSource.setMinIdle(ApplicationConfig.SPARK_WRITE_CLICKHOUSE_MINIDLE());
|
||||||
|
dataSource.setMaxActive(ApplicationConfig.SPARK_WRITE_CLICKHOUSE_MAXACTIVE());
|
||||||
|
//配置获取连接等待超时的时间
|
||||||
|
dataSource.setMaxWait(30000);
|
||||||
|
//配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
|
dataSource.setTimeBetweenEvictionRunsMillis(2000);
|
||||||
|
//防止过期
|
||||||
|
dataSource.setValidationQuery("SELECT 1");
|
||||||
|
dataSource.setTestWhileIdle(true);
|
||||||
|
dataSource.setTestOnBorrow(true);
|
||||||
|
dataSource.setKeepAlive(true);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(e.getMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库连接池单例
|
||||||
|
*
|
||||||
|
* @return dbConnect
|
||||||
|
*/
|
||||||
|
public static synchronized ClickhouseConnect getInstance() {
|
||||||
|
if (null == dbConnect) {
|
||||||
|
dbConnect = new ClickhouseConnect();
|
||||||
|
}
|
||||||
|
return dbConnect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回druid数据库连接
|
||||||
|
*
|
||||||
|
* @return 连接
|
||||||
|
* @throws SQLException sql异常
|
||||||
|
*/
|
||||||
|
public DruidPooledConnection getConnection() throws SQLException {
|
||||||
|
return dataSource.getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空PreparedStatement、Connection对象,未定义的置空。
|
||||||
|
*
|
||||||
|
* @param pstmt PreparedStatement对象
|
||||||
|
* @param connection Connection对象
|
||||||
|
*/
|
||||||
|
public void clear(Statement pstmt, Connection connection) {
|
||||||
|
try {
|
||||||
|
if (pstmt != null) {
|
||||||
|
pstmt.close();
|
||||||
|
}
|
||||||
|
if (connection != null) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOG.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package cn.ac.iie.utils;
|
|
||||||
|
|
||||||
public class TopDomainUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用方法,传入url,返回domain,这里的domain不包含端口号,含有:一定是v6
|
|
||||||
* @param oriUrl
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getDomainFromUrl(String oriUrl) {
|
|
||||||
String url = oriUrl.split("[?]")[0];
|
|
||||||
url = url.replaceAll("https://", "").replaceAll("http://", "");
|
|
||||||
String domain;
|
|
||||||
|
|
||||||
if (url.split("/")[0].split(":").length <= 2) {
|
|
||||||
domain = url
|
|
||||||
.split("/")[0]
|
|
||||||
.split(":")[0];
|
|
||||||
} else {
|
|
||||||
domain = url.split("/")[0];
|
|
||||||
}
|
|
||||||
return domain;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,14 +7,21 @@ repartitionNumber=36
|
|||||||
spark.serializer=org.apache.spark.serializer.KryoSerializer
|
spark.serializer=org.apache.spark.serializer.KryoSerializer
|
||||||
master=local[*]
|
master=local[*]
|
||||||
#spark读取clickhouse配置
|
#spark读取clickhouse配置
|
||||||
#spark.read.clickhouse.url=jdbc:clickhouse://192.168.40.186:8123/tsg_galaxy_v3
|
spark.read.clickhouse.url=jdbc:clickhouse://192.168.40.186:8123/tsg_galaxy_v3
|
||||||
spark.read.clickhouse.url=jdbc:clickhouse://192.168.40.193:8123/tsg_galaxy_zx
|
|
||||||
spark.read.clickhouse.driver=ru.yandex.clickhouse.ClickHouseDriver
|
spark.read.clickhouse.driver=ru.yandex.clickhouse.ClickHouseDriver
|
||||||
spark.read.clickhouse.user=default
|
spark.read.clickhouse.user=default
|
||||||
spark.read.clickhouse.password=111111
|
spark.read.clickhouse.password=111111
|
||||||
spark.read.clickhouse.numPartitions=144
|
spark.read.clickhouse.numPartitions=10
|
||||||
spark.read.clickhouse.fetchsize=10000
|
spark.read.clickhouse.fetchsize=10000
|
||||||
spark.read.clickhouse.partitionColumn=recv_time
|
spark.read.clickhouse.partitionColumn=LAST_FOUND_TIME
|
||||||
|
|
||||||
|
spark.write.clickhouse.url=jdbc:clickhouse://192.168.40.194:8123/ip_learning?socket_timeout=3600000
|
||||||
|
spark.write.clickhouse.user=default
|
||||||
|
spark.write.clickhouse.password=111111
|
||||||
|
spark.write.clickhouse.initialsize=1
|
||||||
|
spark.write.clickhouse.minidle=1
|
||||||
|
spark.write.clickhouse.maxactive=50
|
||||||
|
|
||||||
clickhouse.socket.timeout=300000
|
clickhouse.socket.timeout=300000
|
||||||
#arangoDB配置
|
#arangoDB配置
|
||||||
arangoDB.host=192.168.40.182
|
arangoDB.host=192.168.40.182
|
||||||
@@ -29,8 +36,8 @@ thread.pool.number=5
|
|||||||
|
|
||||||
#读取clickhouse时间范围方式,0:读取过去一小时;1:指定时间范围
|
#读取clickhouse时间范围方式,0:读取过去一小时;1:指定时间范围
|
||||||
clickhouse.time.limit.type=1
|
clickhouse.time.limit.type=1
|
||||||
read.clickhouse.max.time=1571241640
|
read.clickhouse.max.time=1598246519
|
||||||
read.clickhouse.min.time=1571241600
|
read.clickhouse.min.time=1597161600
|
||||||
|
|
||||||
#读取arangoDB时间范围方式,0:正常读;1:指定时间范围
|
#读取arangoDB时间范围方式,0:正常读;1:指定时间范围
|
||||||
arango.time.limit.type=0
|
arango.time.limit.type=0
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ object ApplicationConfig {
|
|||||||
val SPARK_READ_CLICKHOUSE_FETCHSIZE: String = config.getString("spark.read.clickhouse.fetchsize")
|
val SPARK_READ_CLICKHOUSE_FETCHSIZE: String = config.getString("spark.read.clickhouse.fetchsize")
|
||||||
val SPARK_READ_CLICKHOUSE_PARTITIONCOLUMN: String = config.getString("spark.read.clickhouse.partitionColumn")
|
val SPARK_READ_CLICKHOUSE_PARTITIONCOLUMN: String = config.getString("spark.read.clickhouse.partitionColumn")
|
||||||
|
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_URL: String = config.getString("spark.write.clickhouse.url")
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_USER: String = config.getString("spark.write.clickhouse.user")
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_PASSWORD: String = config.getString("spark.write.clickhouse.password")
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_INITIALSIZE: Int = config.getInt("spark.write.clickhouse.initialsize")
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_MINIDLE: Int = config.getInt("spark.write.clickhouse.minidle")
|
||||||
|
val SPARK_WRITE_CLICKHOUSE_MAXACTIVE: Int = config.getInt("spark.write.clickhouse.maxactive")
|
||||||
|
|
||||||
val ARANGODB_HOST: String= config.getString("arangoDB.host")
|
val ARANGODB_HOST: String= config.getString("arangoDB.host")
|
||||||
val ARANGODB_PORT: Int = config.getInt("arangoDB.port")
|
val ARANGODB_PORT: Int = config.getInt("arangoDB.port")
|
||||||
val ARANGODB_USER: String= config.getString("arangoDB.user")
|
val ARANGODB_USER: String= config.getString("arangoDB.user")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package cn.ac.iie.dao
|
|||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig
|
import cn.ac.iie.config.ApplicationConfig
|
||||||
import cn.ac.iie.utils.SparkSessionUtil.spark
|
import cn.ac.iie.utils.SparkSessionUtil.spark
|
||||||
import cn.ac.iie.utils.TopDomainUtils
|
|
||||||
import org.apache.spark.sql.DataFrame
|
import org.apache.spark.sql.DataFrame
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
@@ -12,7 +11,7 @@ object BaseClickhouseData {
|
|||||||
val currentHour: Long = System.currentTimeMillis / (60 * 60 * 1000) * 60 * 60
|
val currentHour: Long = System.currentTimeMillis / (60 * 60 * 1000) * 60 * 60
|
||||||
private val timeLimit: (Long, Long) = getTimeLimit
|
private val timeLimit: (Long, Long) = getTimeLimit
|
||||||
|
|
||||||
private def initClickhouseData(sql:String): Unit ={
|
private def initClickhouseData(sql:String): DataFrame ={
|
||||||
|
|
||||||
val dataFrame: DataFrame = spark.read.format("jdbc")
|
val dataFrame: DataFrame = spark.read.format("jdbc")
|
||||||
.option("url", ApplicationConfig.SPARK_READ_CLICKHOUSE_URL)
|
.option("url", ApplicationConfig.SPARK_READ_CLICKHOUSE_URL)
|
||||||
@@ -29,16 +28,17 @@ object BaseClickhouseData {
|
|||||||
.load()
|
.load()
|
||||||
dataFrame.printSchema()
|
dataFrame.printSchema()
|
||||||
dataFrame.createOrReplaceGlobalTempView("dbtable")
|
dataFrame.createOrReplaceGlobalTempView("dbtable")
|
||||||
|
dataFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadConnectionDataFromCk(): Unit ={
|
def loadConnectionDataFromCk(): Unit ={
|
||||||
val where = "recv_time >= " + timeLimit._2 + " AND recv_time < " + timeLimit._1
|
val where = "common_recv_time >= " + timeLimit._2 + " AND common_recv_time < " + timeLimit._1 + " AND common_schema_type != 'BASE'"
|
||||||
val sql =
|
val sql =
|
||||||
s"""
|
s"""
|
||||||
|(SELECT
|
|(SELECT
|
||||||
| s1_domain,s1_referer,s1_s_ip,s1_d_ip,recv_time,media_len
|
| ssl_sni,http_host,common_client_ip,common_server_ip,common_recv_time,common_c2s_byte_num,common_s2c_byte_num,common_schema_type
|
||||||
|FROM
|
|FROM
|
||||||
| media_expire_patch
|
| connection_record_log
|
||||||
|WHERE $where) as dbtable
|
|WHERE $where) as dbtable
|
||||||
""".stripMargin
|
""".stripMargin
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ object BaseClickhouseData {
|
|||||||
private def loadRadiusDataFromCk(): Unit ={
|
private def loadRadiusDataFromCk(): Unit ={
|
||||||
val where =
|
val where =
|
||||||
s"""
|
s"""
|
||||||
| common_start_time >= ${timeLimit._2}
|
| common_recv_time >= ${timeLimit._2}
|
||||||
| AND common_start_time < ${timeLimit._1}
|
| AND common_recv_time < ${timeLimit._1}
|
||||||
| AND common_subscriber_id != ''
|
| AND common_subscriber_id != ''
|
||||||
| AND radius_framed_ip != ''
|
| AND radius_framed_ip != ''
|
||||||
| AND radius_packet_type = 4
|
| AND radius_packet_type = 4
|
||||||
@@ -59,7 +59,7 @@ object BaseClickhouseData {
|
|||||||
val sql =
|
val sql =
|
||||||
s"""
|
s"""
|
||||||
|(SELECT
|
|(SELECT
|
||||||
| common_subscriber_id,radius_framed_ip,common_start_time
|
| common_subscriber_id,radius_framed_ip,common_recv_time
|
||||||
|FROM
|
|FROM
|
||||||
| tsg_galaxy_v3.radius_record_log
|
| tsg_galaxy_v3.radius_record_log
|
||||||
|WHERE
|
|WHERE
|
||||||
@@ -69,31 +69,28 @@ object BaseClickhouseData {
|
|||||||
initClickhouseData(sql)
|
initClickhouseData(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getDomain(url:String): String ={
|
|
||||||
TopDomainUtils.getDomainFromUrl(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
def getVertexFqdnDf: DataFrame ={
|
def getVertexFqdnDf: DataFrame ={
|
||||||
loadConnectionDataFromCk()
|
loadConnectionDataFromCk()
|
||||||
spark.udf.register("getDomain",TopDomainUtils.getDomainFromUrl _)
|
|
||||||
val sql =
|
val sql =
|
||||||
"""
|
"""
|
||||||
|SELECT
|
|SELECT
|
||||||
| FQDN,MAX(LAST_FOUND_TIME) AS LAST_FOUND_TIME,MIN(FIRST_FOUND_TIME) AS FIRST_FOUND_TIME
|
| FQDN,MAX( LAST_FOUND_TIME ) AS LAST_FOUND_TIME,MIN( FIRST_FOUND_TIME ) AS FIRST_FOUND_TIME
|
||||||
|FROM
|
|FROM
|
||||||
| (
|
| (
|
||||||
| (SELECT
|
| (SELECT
|
||||||
| s1_domain AS FQDN,MAX(recv_time) AS LAST_FOUND_TIME,MIN(recv_time) AS FIRST_FOUND_TIME
|
| ssl_sni AS FQDN,MAX( common_recv_time ) AS LAST_FOUND_TIME,MIN( common_recv_time ) AS FIRST_FOUND_TIME
|
||||||
| FROM
|
| FROM
|
||||||
| global_temp.dbtable
|
| global_temp.dbtable
|
||||||
| GROUP BY s1_domain
|
| WHERE
|
||||||
|
| common_schema_type = 'SSL' GROUP BY ssl_sni
|
||||||
| )
|
| )
|
||||||
| UNION ALL
|
| UNION ALL
|
||||||
| (SELECT
|
| (SELECT
|
||||||
| getDomain(s1_referer) AS FQDN,MAX(recv_time) AS LAST_FOUND_TIME,MIN(recv_time) AS FIRST_FOUND_TIME
|
| http_host AS FQDN,MAX( common_recv_time ) AS LAST_FOUND_TIME,MIN( common_recv_time ) AS FIRST_FOUND_TIME
|
||||||
| FROM
|
| FROM
|
||||||
| global_temp.dbtable
|
| global_temp.dbtable
|
||||||
| GROUP BY getDomain(s1_referer)
|
| WHERE
|
||||||
|
| common_schema_type = 'HTTP' GROUP BY http_host
|
||||||
| )
|
| )
|
||||||
| )
|
| )
|
||||||
|GROUP BY
|
|GROUP BY
|
||||||
@@ -107,11 +104,6 @@ object BaseClickhouseData {
|
|||||||
vertexFqdnDf
|
vertexFqdnDf
|
||||||
}
|
}
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
|
||||||
val df = getRelationFqdnLocateIpDf
|
|
||||||
df.show(10)
|
|
||||||
}
|
|
||||||
|
|
||||||
def getVertexIpDf: DataFrame ={
|
def getVertexIpDf: DataFrame ={
|
||||||
loadConnectionDataFromCk()
|
loadConnectionDataFromCk()
|
||||||
val sql =
|
val sql =
|
||||||
@@ -122,11 +114,11 @@ object BaseClickhouseData {
|
|||||||
| (
|
| (
|
||||||
| (
|
| (
|
||||||
| SELECT
|
| SELECT
|
||||||
| s1_s_ip AS IP,
|
| common_client_ip AS IP,
|
||||||
| MIN(recv_time) AS FIRST_FOUND_TIME,
|
| MIN(common_recv_time) AS FIRST_FOUND_TIME,
|
||||||
| MAX(recv_time) AS LAST_FOUND_TIME,
|
| MAX(common_recv_time) AS LAST_FOUND_TIME,
|
||||||
| count(*) as SESSION_COUNT,
|
| count(*) as SESSION_COUNT,
|
||||||
| sum(media_len) as BYTES_SUM,
|
| sum(common_c2s_byte_num) as BYTES_SUM,
|
||||||
| 'client' as ip_type
|
| 'client' as ip_type
|
||||||
| FROM
|
| FROM
|
||||||
| global_temp.dbtable
|
| global_temp.dbtable
|
||||||
@@ -136,11 +128,11 @@ object BaseClickhouseData {
|
|||||||
| UNION ALL
|
| UNION ALL
|
||||||
| (
|
| (
|
||||||
| SELECT
|
| SELECT
|
||||||
| s1_d_ip AS IP,
|
| common_server_ip AS IP,
|
||||||
| MIN(recv_time) AS FIRST_FOUND_TIME,
|
| MIN(common_recv_time) AS FIRST_FOUND_TIME,
|
||||||
| MAX(recv_time) AS LAST_FOUND_TIME,
|
| MAX(common_recv_time) AS LAST_FOUND_TIME,
|
||||||
| count(*) as SESSION_COUNT,
|
| count(*) as SESSION_COUNT,
|
||||||
| sum(media_len) as BYTES_SUM,
|
| sum(common_s2c_byte_num) as BYTES_SUM,
|
||||||
| 'server' as ip_type
|
| 'server' as ip_type
|
||||||
| FROM
|
| FROM
|
||||||
| global_temp.dbtable
|
| global_temp.dbtable
|
||||||
@@ -155,31 +147,75 @@ object BaseClickhouseData {
|
|||||||
vertexIpDf
|
vertexIpDf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getRelationFqdnLocateIpDf(): DataFrame ={
|
||||||
|
val where = "common_end_time >= " + timeLimit._2 + " AND common_end_time < " + timeLimit._1
|
||||||
|
val sql =
|
||||||
|
s"""
|
||||||
|
|(SELECT * FROM
|
||||||
|
|((SELECT ssl_sni AS FQDN,common_server_ip,MAX(common_end_time) AS LAST_FOUND_TIME,MIN(common_end_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,
|
||||||
|
|toString(groupUniqArray(${ApplicationConfig.DISTINCT_CLIENT_IP_NUM})(common_client_ip)) AS DIST_CIP_RECENT,'TLS' AS schema_type
|
||||||
|
|FROM tsg_galaxy_v3.connection_record_log
|
||||||
|
|WHERE $where and common_schema_type = 'SSL' GROUP BY ssl_sni,common_server_ip)
|
||||||
|
|UNION ALL
|
||||||
|
|(SELECT http_host AS FQDN,common_server_ip,MAX(common_end_time) AS LAST_FOUND_TIME,MIN(common_end_time) AS FIRST_FOUND_TIME,COUNT(*) AS COUNT_TOTAL,
|
||||||
|
|toString(groupUniqArray(${ApplicationConfig.DISTINCT_CLIENT_IP_NUM})(common_client_ip)) AS DIST_CIP_RECENT,'HTTP' AS schema_type
|
||||||
|
|FROM tsg_galaxy_v3.connection_record_log
|
||||||
|
|WHERE $where and common_schema_type = 'HTTP' GROUP BY http_host,common_server_ip))
|
||||||
|
|WHERE FQDN != '') as dbtable
|
||||||
|
""".stripMargin
|
||||||
|
LOG.warn(sql)
|
||||||
|
val frame = initClickhouseData(sql)
|
||||||
|
frame.printSchema()
|
||||||
|
frame
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
def getRelationFqdnLocateIpDf: DataFrame ={
|
def getRelationFqdnLocateIpDf: DataFrame ={
|
||||||
loadConnectionDataFromCk()
|
loadConnectionDataFromCk()
|
||||||
|
val sslSql =
|
||||||
val sql =
|
|
||||||
"""
|
"""
|
||||||
|SELECT
|
|SELECT
|
||||||
| s1_domain AS FQDN,
|
| ssl_sni AS FQDN,
|
||||||
| s1_d_ip AS common_server_ip,
|
| common_server_ip,
|
||||||
| MAX(recv_time) AS LAST_FOUND_TIME,
|
| MAX(common_recv_time) AS LAST_FOUND_TIME,
|
||||||
| MIN(recv_time) AS FIRST_FOUND_TIME,
|
| MIN(common_recv_time) AS FIRST_FOUND_TIME,
|
||||||
| COUNT(*) AS COUNT_TOTAL,
|
| COUNT(*) AS COUNT_TOTAL,
|
||||||
| collect_set(s1_s_ip) AS DIST_CIP_RECENT
|
| collect_set(common_client_ip) AS DIST_CIP_RECENT,
|
||||||
|
| 'TLS' AS schema_type
|
||||||
|FROM
|
|FROM
|
||||||
| global_temp.dbtable
|
| global_temp.dbtable
|
||||||
|WHERE
|
|WHERE
|
||||||
| s1_domain != ''
|
| common_schema_type = 'SSL'
|
||||||
|GROUP BY
|
|GROUP BY
|
||||||
| s1_domain,s1_d_ip
|
| ssl_sni,common_server_ip
|
||||||
""".stripMargin
|
""".stripMargin
|
||||||
|
|
||||||
|
val httpSql =
|
||||||
|
"""
|
||||||
|
|SELECT
|
||||||
|
| http_host AS FQDN,
|
||||||
|
| common_server_ip,
|
||||||
|
| MAX(common_recv_time) AS LAST_FOUND_TIME,
|
||||||
|
| MIN(common_recv_time) AS FIRST_FOUND_TIME,
|
||||||
|
| COUNT(*) AS COUNT_TOTAL,
|
||||||
|
| collect_set(common_client_ip) AS DIST_CIP_RECENT,
|
||||||
|
| 'HTTP' AS schema_type
|
||||||
|
|FROM
|
||||||
|
| global_temp.dbtable
|
||||||
|
|WHERE
|
||||||
|
| common_schema_type = 'HTTP'
|
||||||
|
|GROUP BY
|
||||||
|
| http_host,common_server_ip
|
||||||
|
""".stripMargin
|
||||||
|
val sql = s"SELECT * FROM (($sslSql) UNION ALL ($httpSql)) WHERE FQDN != ''"
|
||||||
|
|
||||||
LOG.warn(sql)
|
LOG.warn(sql)
|
||||||
val relationFqdnLocateIpDf = spark.sql(sql)
|
val relationFqdnLocateIpDf = spark.sql(sql)
|
||||||
relationFqdnLocateIpDf.printSchema()
|
relationFqdnLocateIpDf.printSchema()
|
||||||
relationFqdnLocateIpDf
|
relationFqdnLocateIpDf
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private def getTimeLimit: (Long,Long) ={
|
private def getTimeLimit: (Long,Long) ={
|
||||||
var maxTime = 0L
|
var maxTime = 0L
|
||||||
|
|||||||
@@ -6,14 +6,17 @@ import cn.ac.iie.config.ApplicationConfig
|
|||||||
import cn.ac.iie.dao.BaseClickhouseData
|
import cn.ac.iie.dao.BaseClickhouseData
|
||||||
import cn.ac.iie.spark.partition.CustomPartitioner
|
import cn.ac.iie.spark.partition.CustomPartitioner
|
||||||
import org.apache.spark.rdd.RDD
|
import org.apache.spark.rdd.RDD
|
||||||
import org.apache.spark.sql.Row
|
import org.apache.spark.sql.{DataFrame, Row}
|
||||||
import org.apache.spark.sql.functions._
|
import org.apache.spark.sql.functions._
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
|
||||||
object MergeDataFrame {
|
object MergeDataFrame {
|
||||||
private val LOG = LoggerFactory.getLogger(MergeDataFrame.getClass)
|
private val LOG = LoggerFactory.getLogger(MergeDataFrame.getClass)
|
||||||
private val pattern = Pattern.compile("^[\\d]*$")
|
private val pattern = Pattern.compile("^[\\d]*$")
|
||||||
|
|
||||||
|
private val currentHour: Long = System.currentTimeMillis / (60 * 60 * 1000) * 60 * 60
|
||||||
|
|
||||||
def mergeVertexFqdn(): RDD[Row] ={
|
def mergeVertexFqdn(): RDD[Row] ={
|
||||||
BaseClickhouseData.getVertexFqdnDf
|
BaseClickhouseData.getVertexFqdnDf
|
||||||
.rdd.filter(row => isDomain(row.getAs[String](0))).map(row => (row.get(0),row))
|
.rdd.filter(row => isDomain(row.getAs[String](0))).map(row => (row.get(0),row))
|
||||||
@@ -34,16 +37,17 @@ object MergeDataFrame {
|
|||||||
values
|
values
|
||||||
}
|
}
|
||||||
|
|
||||||
def mergeRelationFqdnLocateIp(): RDD[Row] ={
|
def mergeRelationFqdnLocateIp(): DataFrame ={
|
||||||
BaseClickhouseData.getRelationFqdnLocateIpDf
|
val frame = BaseClickhouseData.getRelationFqdnLocateIpDf.filter(row => isDomain(row.getAs[String]("FQDN")))
|
||||||
.filter(row => isDomain(row.getAs[String]("FQDN")))
|
.groupBy("FQDN", "common_server_ip")
|
||||||
.rdd.map(row => {
|
.agg(
|
||||||
val fqdn = row.getAs[String]("FQDN")
|
min("FIRST_FOUND_TIME").alias("FIRST_FOUND_TIME"),
|
||||||
val serverIp = row.getAs[String]("common_server_ip")
|
max("LAST_FOUND_TIME").alias("LAST_FOUND_TIME"),
|
||||||
val key = fqdn.concat("-"+serverIp)
|
collect_list("COUNT_TOTAL").alias("COUNT_TOTAL_LIST"),
|
||||||
(key,row)
|
collect_list("schema_type").alias("schema_type_list"),
|
||||||
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
collect_set("DIST_CIP_RECENT").alias("DIST_CIP_RECENT")
|
||||||
|
).repartition(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)
|
||||||
|
frame
|
||||||
}
|
}
|
||||||
|
|
||||||
private def isDomain(fqdn: String): Boolean = {
|
private def isDomain(fqdn: String): Boolean = {
|
||||||
@@ -51,13 +55,9 @@ object MergeDataFrame {
|
|||||||
if (fqdn == null || fqdn.length == 0) {
|
if (fqdn == null || fqdn.length == 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (fqdn.contains(":")) {
|
val domain = fqdn.split(":")(0)
|
||||||
val s = fqdn.split(":")(0)
|
|
||||||
if (s.contains(":")){
|
val fqdnArr = domain.split("\\.")
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val fqdnArr = fqdn.split("\\.")
|
|
||||||
if (fqdnArr.length < 4 || fqdnArr.length > 4){
|
if (fqdnArr.length < 4 || fqdnArr.length > 4){
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ package cn.ac.iie.service.update
|
|||||||
import java.lang
|
import java.lang
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig
|
import cn.ac.iie.config.ApplicationConfig
|
||||||
import cn.ac.iie.service.read.ReadHistoryArangoData
|
|
||||||
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
@@ -13,6 +12,8 @@ import scala.collection.mutable.WrappedArray.ofRef
|
|||||||
object UpdateDocHandler {
|
object UpdateDocHandler {
|
||||||
val PROTOCOL_SET: Set[String] = Set("HTTP","TLS","DNS")
|
val PROTOCOL_SET: Set[String] = Set("HTTP","TLS","DNS")
|
||||||
|
|
||||||
|
private val currentHour: Long = System.currentTimeMillis / (60 * 60 * 1000) * 60 * 60
|
||||||
|
|
||||||
def updateMaxAttribute(hisDoc: BaseDocument,newAttribute:Long,attributeName:String): Unit ={
|
def updateMaxAttribute(hisDoc: BaseDocument,newAttribute:Long,attributeName:String): Unit ={
|
||||||
var hisAttritube = hisDoc.getAttribute(attributeName).toString.toLong
|
var hisAttritube = hisDoc.getAttribute(attributeName).toString.toLong
|
||||||
if (newAttribute > hisAttritube){
|
if (newAttribute > hisAttritube){
|
||||||
@@ -93,13 +94,27 @@ object UpdateDocHandler {
|
|||||||
doc.addAttribute("PROTOCOL_TYPE",protocolTypeBuilder.toString().replaceFirst(",",""))
|
doc.addAttribute("PROTOCOL_TYPE",protocolTypeBuilder.toString().replaceFirst(",",""))
|
||||||
}
|
}
|
||||||
|
|
||||||
def mergeDistinctIp(distCipRecent:ofRef[String]): Array[String] ={
|
/*
|
||||||
distCipRecent.distinct.take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toArray
|
def mergeDistinctIp(distCipRecent:ofRef[ofRef[String]]): Array[String] ={
|
||||||
|
distCipRecent.flatten.distinct.take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toArray
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
def mergeDistinctIp(distCipRecent:ofRef[String]): Array[String] ={
|
||||||
|
distCipRecent.flatMap(str => {
|
||||||
|
str.replaceAll("\\[", "")
|
||||||
|
.replaceAll("\\]", "")
|
||||||
|
.replaceAll("'", "")
|
||||||
|
.split(",")
|
||||||
|
}).distinct.toArray
|
||||||
|
// distCipRecent.flatten.distinct.take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toArray
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def putDistinctIp(doc:BaseEdgeDocument,newDistinctIp:Array[String]): Unit ={
|
def putDistinctIp(doc:BaseEdgeDocument,newDistinctIp:Array[String]): Unit ={
|
||||||
val map = newDistinctIp.map(ip => {
|
val map = newDistinctIp.map(ip => {
|
||||||
(ip, ReadHistoryArangoData.currentHour)
|
(ip, currentHour)
|
||||||
}).toMap
|
}).toMap
|
||||||
doc.addAttribute("DIST_CIP",map.keys.toArray)
|
doc.addAttribute("DIST_CIP",map.keys.toArray)
|
||||||
doc.addAttribute("DIST_CIP_TS",map.values.toArray)
|
doc.addAttribute("DIST_CIP_TS",map.values.toArray)
|
||||||
@@ -112,7 +127,7 @@ object UpdateDocHandler {
|
|||||||
val distCipToTsMap: Map[String, Long] = hisDistCip.zip(hisDistCipTs).toMap
|
val distCipToTsMap: Map[String, Long] = hisDistCip.zip(hisDistCipTs).toMap
|
||||||
val muDistCipToTsMap: mutable.Map[String, Long] = mutable.Map(distCipToTsMap.toSeq:_*)
|
val muDistCipToTsMap: mutable.Map[String, Long] = mutable.Map(distCipToTsMap.toSeq:_*)
|
||||||
newDistinctIp.foreach(cip => {
|
newDistinctIp.foreach(cip => {
|
||||||
muDistCipToTsMap.put(cip,ReadHistoryArangoData.currentHour)
|
muDistCipToTsMap.put(cip,currentHour)
|
||||||
})
|
})
|
||||||
val resultMap = muDistCipToTsMap.toList.sortBy(-_._2).take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toMap
|
val resultMap = muDistCipToTsMap.toList.sortBy(-_._2).take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toMap
|
||||||
hisDoc.addAttribute("DIST_CIP",resultMap.keys.toArray)
|
hisDoc.addAttribute("DIST_CIP",resultMap.keys.toArray)
|
||||||
|
|||||||
@@ -1,83 +1,99 @@
|
|||||||
package cn.ac.iie.service.update
|
package cn.ac.iie.service.update
|
||||||
|
|
||||||
import java.util
|
import java.sql.PreparedStatement
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
import cn.ac.iie.config.ApplicationConfig
|
import cn.ac.iie.config.ApplicationConfig
|
||||||
import cn.ac.iie.dao.BaseArangoData
|
|
||||||
import cn.ac.iie.dao.BaseArangoData._
|
|
||||||
import cn.ac.iie.service.transform.MergeDataFrame._
|
|
||||||
import cn.ac.iie.service.update.UpdateDocHandler._
|
import cn.ac.iie.service.update.UpdateDocHandler._
|
||||||
import cn.ac.iie.utils.{ArangoDBConnect, ExecutorThreadPool, SparkSessionUtil}
|
import cn.ac.iie.utils.{ClickhouseConnect, SparkSessionUtil}
|
||||||
import cn.ac.iie.utils.SparkSessionUtil.spark
|
import cn.ac.iie.service.transform.MergeDataFrame._
|
||||||
|
import com.alibaba.druid.pool.DruidPooledConnection
|
||||||
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
||||||
import org.apache.spark.TaskContext
|
import org.apache.spark.sql.{DataFrame, Row}
|
||||||
import org.apache.spark.rdd.RDD
|
|
||||||
import org.apache.spark.sql.Row
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import ru.yandex.clickhouse.ClickHouseArray
|
||||||
|
|
||||||
import scala.collection.mutable.WrappedArray.ofRef
|
import scala.collection.mutable.WrappedArray.ofRef
|
||||||
|
|
||||||
object UpdateDocument {
|
object UpdateDocument {
|
||||||
private val pool = ExecutorThreadPool.getInstance
|
|
||||||
private val arangoManger: ArangoDBConnect = ArangoDBConnect.getInstance()
|
|
||||||
private val LOG = LoggerFactory.getLogger(UpdateDocument.getClass)
|
private val LOG = LoggerFactory.getLogger(UpdateDocument.getClass)
|
||||||
private val baseArangoData = new BaseArangoData()
|
|
||||||
|
private val manger: ClickhouseConnect = ClickhouseConnect.getInstance()
|
||||||
|
private val currentHour: Long = System.currentTimeMillis / (60 * 60 * 1000) * 60 * 60
|
||||||
|
|
||||||
def update(): Unit = {
|
def update(): Unit = {
|
||||||
try {
|
try {
|
||||||
updateDocument("FQDN", historyVertexFqdnMap, getVertexFqdnRow, classOf[BaseDocument], mergeVertexFqdn)
|
updateDocument("r_locate_fqdn2ip_local", getRelationFqdnLocIpPstm, mergeRelationFqdnLocateIp)
|
||||||
updateDocument("IP", historyVertexIpMap, getVertexIpRow, classOf[BaseDocument], mergeVertexIp)
|
|
||||||
updateDocument("R_LOCATE_FQDN2IP", historyRelationFqdnAddressIpMap, getRelationFqdnLocateIpRow, classOf[BaseEdgeDocument], mergeRelationFqdnLocateIp)
|
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception => e.printStackTrace()
|
case e: Exception => e.printStackTrace()
|
||||||
} finally {
|
} finally {
|
||||||
pool.shutdown()
|
|
||||||
arangoManger.clean()
|
|
||||||
SparkSessionUtil.closeSpark()
|
SparkSessionUtil.closeSpark()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def updateDocument[T <: BaseDocument](collName: String,
|
private def updateDocument[T <: BaseDocument](tableName: String,
|
||||||
historyMap: ConcurrentHashMap[Integer, ConcurrentHashMap[String, T]],
|
setPstm: (Row, PreparedStatement) => PreparedStatement,
|
||||||
getDocumentRow: (Row, ConcurrentHashMap[String, T]) => T,
|
getNewDataRdd: () => DataFrame): Unit = {
|
||||||
clazz: Class[T],
|
|
||||||
getNewDataRdd: () => RDD[Row]
|
|
||||||
): Unit = {
|
|
||||||
baseArangoData.readHistoryData(collName, historyMap, clazz)
|
|
||||||
val hisBc = spark.sparkContext.broadcast(historyMap)
|
|
||||||
try {
|
try {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
val newDataRdd = getNewDataRdd()
|
val newDataFrame = getNewDataRdd()
|
||||||
newDataRdd.foreachPartition(iter => {
|
|
||||||
val partitionId: Int = TaskContext.get.partitionId
|
newDataFrame.foreachPartition(iter => {
|
||||||
val dictionaryMap: ConcurrentHashMap[String, T] = hisBc.value.get(partitionId)
|
val connection: DruidPooledConnection = manger.getConnection
|
||||||
val resultDocumentList = new util.ArrayList[T]
|
val sql = s"INSERT INTO $tableName VALUES(?,?,?,?,?,?,?,?,?)"
|
||||||
|
var pstm: PreparedStatement = connection.prepareStatement(sql)
|
||||||
var i = 0
|
var i = 0
|
||||||
iter.foreach(row => {
|
iter.foreach(row => {
|
||||||
val document = getDocumentRow(row, dictionaryMap)
|
pstm = setPstm(row,pstm)
|
||||||
resultDocumentList.add(document)
|
|
||||||
i += 1
|
i += 1
|
||||||
|
pstm.addBatch()
|
||||||
if (i >= ApplicationConfig.UPDATE_ARANGO_BATCH) {
|
if (i >= ApplicationConfig.UPDATE_ARANGO_BATCH) {
|
||||||
arangoManger.overwrite(resultDocumentList, collName)
|
pstm.executeBatch()
|
||||||
LOG.warn(s"更新:$collName" + i)
|
connection.commit()
|
||||||
|
LOG.warn(s"写入$tableName 数据量:" + i)
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
arangoManger.overwrite(resultDocumentList, collName)
|
pstm.executeBatch
|
||||||
LOG.warn(s"更新$collName:" + i)
|
connection.commit()
|
||||||
|
LOG.warn(s"写入$tableName 数据量:" + i)
|
||||||
}
|
}
|
||||||
|
manger.clear(pstm,connection)
|
||||||
})
|
})
|
||||||
val last = System.currentTimeMillis()
|
val last = System.currentTimeMillis()
|
||||||
LOG.warn(s"更新$collName 时间:${last - start}")
|
LOG.warn(s"更新$tableName 时间:${last - start}")
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception => e.printStackTrace()
|
case e: Exception => e.printStackTrace()
|
||||||
} finally {
|
|
||||||
hisBc.destroy()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def getRelationFqdnLocIpPstm(row: Row,pstm: PreparedStatement): PreparedStatement ={
|
||||||
|
val fqdn = row.getAs[String]("FQDN")
|
||||||
|
val serverIp = row.getAs[String]("common_server_ip")
|
||||||
|
val firstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
||||||
|
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
||||||
|
val countTotalList = row.getAs[ofRef[AnyRef]]("COUNT_TOTAL_LIST")
|
||||||
|
val schemaTypeList = row.getAs[ofRef[AnyRef]]("schema_type_list")
|
||||||
|
|
||||||
|
val distCipRecent = row.getAs[ofRef[String]]("DIST_CIP_RECENT")
|
||||||
|
val disCips = mergeDistinctIp(distCipRecent)
|
||||||
|
|
||||||
|
val sepAttritubeMap: Map[String, Long] = separateAttributeByProtocol(schemaTypeList, countTotalList)
|
||||||
|
|
||||||
|
pstm.setString(1,fqdn)
|
||||||
|
pstm.setString(2,serverIp)
|
||||||
|
pstm.setLong(3,firstFoundTime)
|
||||||
|
pstm.setLong(4,lastFoundTime)
|
||||||
|
pstm.setLong(5,sepAttritubeMap.getOrElse("HTTP",0L))
|
||||||
|
pstm.setLong(6,sepAttritubeMap.getOrElse("TLS",0L))
|
||||||
|
pstm.setLong(7,sepAttritubeMap.getOrElse("DNS",0L))
|
||||||
|
pstm.setArray(8,new ClickHouseArray(1, disCips))
|
||||||
|
pstm.setLong(9,currentHour)
|
||||||
|
|
||||||
|
pstm
|
||||||
|
}
|
||||||
|
|
||||||
private def getVertexFqdnRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseDocument]): BaseDocument = {
|
private def getVertexFqdnRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseDocument]): BaseDocument = {
|
||||||
val fqdn = row.getAs[String]("FQDN")
|
val fqdn = row.getAs[String]("FQDN")
|
||||||
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
||||||
@@ -126,33 +142,4 @@ object UpdateDocument {
|
|||||||
document
|
document
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getRelationFqdnLocateIpRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseEdgeDocument]): BaseEdgeDocument = {
|
|
||||||
val fqdn = row.getAs[String]("FQDN")
|
|
||||||
val serverIp = row.getAs[String]("common_server_ip")
|
|
||||||
val firstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
|
||||||
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
|
||||||
val countTotal = row.getAs[Long]("COUNT_TOTAL")
|
|
||||||
val distCipRecent = row.getAs[ofRef[String]]("DIST_CIP_RECENT")
|
|
||||||
|
|
||||||
val distinctIp: Array[String] = mergeDistinctIp(distCipRecent)
|
|
||||||
|
|
||||||
val key = fqdn.concat("-" + serverIp)
|
|
||||||
var document = dictionaryMap.getOrDefault(key, null)
|
|
||||||
if (document != null) {
|
|
||||||
updateMaxAttribute(document, lastFoundTime, "LAST_FOUND_TIME")
|
|
||||||
updateSumAttribute(document,countTotal,"CNT_TOTAL")
|
|
||||||
updateDistinctIp(document, distinctIp)
|
|
||||||
} else {
|
|
||||||
document = new BaseEdgeDocument()
|
|
||||||
document.setKey(key)
|
|
||||||
document.setFrom("FQDN/" + fqdn)
|
|
||||||
document.setTo("IP/" + serverIp)
|
|
||||||
document.addAttribute("FIRST_FOUND_TIME", firstFoundTime)
|
|
||||||
document.addAttribute("LAST_FOUND_TIME", lastFoundTime)
|
|
||||||
document.addAttribute("CNT_TOTAL",countTotal)
|
|
||||||
putDistinctIp(document, distinctIp)
|
|
||||||
}
|
|
||||||
document
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package cn.ac.iie.service.update
|
|
||||||
|
|
||||||
import java.util
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
|
|
||||||
import cn.ac.iie.dao.BaseArangoData
|
|
||||||
import cn.ac.iie.dao.BaseArangoData._
|
|
||||||
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
|
||||||
|
|
||||||
import scala.collection.mutable.WrappedArray.ofRef
|
|
||||||
|
|
||||||
object UpdateDocumentTest {
|
|
||||||
def main(args: Array[String]): Unit = {
|
|
||||||
val baseArangoData = new BaseArangoData()
|
|
||||||
baseArangoData.readHistoryData("R_LOCATE_FQDN2IP", historyRelationFqdnAddressIpMap, classOf[BaseEdgeDocument])
|
|
||||||
|
|
||||||
val value = BaseArangoData.historyRelationFqdnAddressIpMap.keys()
|
|
||||||
while (value.hasMoreElements) {
|
|
||||||
val integer: Integer = value.nextElement()
|
|
||||||
val map: ConcurrentHashMap[String, BaseEdgeDocument] = historyRelationFqdnAddressIpMap.get(integer)
|
|
||||||
val unit = map.keys()
|
|
||||||
while (unit.hasMoreElements) {
|
|
||||||
val key = unit.nextElement()
|
|
||||||
val edgeDocument = map.get(key)
|
|
||||||
// val longs = edgeDocument.getAttribute("DNS_CNT_RECENT").asInstanceOf[util.ArrayList[Long]]
|
|
||||||
// val strings = edgeDocument.getAttribute("DIST_CIP").asInstanceOf[util.ArrayList[String]]
|
|
||||||
val strings = edgeDocument.getAttribute("DIST_CIP").asInstanceOf[Array[String]]
|
|
||||||
val longs = edgeDocument.getAttribute("DNS_CNT_RECENT").asInstanceOf[Array[java.lang.Long]]
|
|
||||||
println(longs.toString + "---" + strings.toString)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user