Compare commits
6 Commits
ip-learnin
...
ip-learnin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4d7737725 | ||
|
|
5cb7327f7b | ||
|
|
e0f5b20ab6 | ||
|
|
e7ff669d4c | ||
|
|
4ed79bfe79 | ||
|
|
0d5e4e9be2 |
@@ -14,7 +14,7 @@ public class ApplicationConfig {
|
|||||||
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 Long ARANGODB_READ_LIMIT = ConfigUtils.getLongProperty("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");
|
||||||
|
|||||||
@@ -78,41 +78,12 @@ public class BaseArangoData {
|
|||||||
private String getQuerySql(Long cnt,int threadNumber, String table){
|
private String getQuerySql(Long cnt,int threadNumber, String table){
|
||||||
long sepNum = cnt / ApplicationConfig.THREAD_POOL_NUMBER + 1;
|
long sepNum = cnt / ApplicationConfig.THREAD_POOL_NUMBER + 1;
|
||||||
long offsetNum = threadNumber * sepNum;
|
long offsetNum = threadNumber * sepNum;
|
||||||
|
if (sepNum >= ApplicationConfig.ARANGODB_READ_LIMIT * 10000){
|
||||||
|
sepNum = ApplicationConfig.ARANGODB_READ_LIMIT * 10000;
|
||||||
|
}
|
||||||
return "FOR doc IN " + table + " limit "+offsetNum+","+sepNum+" RETURN doc";
|
return "FOR doc IN " + table + " limit "+offsetNum+","+sepNum+" RETURN doc";
|
||||||
}
|
}
|
||||||
|
|
||||||
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)}";
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
long lastTime = System.currentTimeMillis();
|
|
||||||
LOG.info(sql+"\n查询最大最小时间用时:" + (lastTime - startTime));
|
|
||||||
}else {
|
|
||||||
LOG.warn("获取ArangoDb时间范围为空");
|
|
||||||
}
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ public class UpdateGraphData {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
updateDocument(newVertexFqdnMap, historyVertexFqdnMap, "FQDN", Fqdn.class,BaseDocument.class,
|
// updateDocument(newVertexFqdnMap, historyVertexFqdnMap, "FQDN", Fqdn.class,BaseDocument.class,
|
||||||
ReadClickhouseData::getVertexFqdnSql,ReadClickhouseData::getVertexFqdnDocument);
|
// ReadClickhouseData::getVertexFqdnSql,ReadClickhouseData::getVertexFqdnDocument);
|
||||||
|
|
||||||
updateDocument(newVertexIpMap,historyVertexIpMap,"IP", Ip.class,BaseDocument.class,
|
updateDocument(newVertexIpMap,historyVertexIpMap,"IP", Ip.class,BaseDocument.class,
|
||||||
ReadClickhouseData::getVertexIpSql,ReadClickhouseData::getVertexIpDocument);
|
ReadClickhouseData::getVertexIpSql,ReadClickhouseData::getVertexIpDocument);
|
||||||
|
|||||||
@@ -265,7 +265,8 @@ public class ReadClickhouseData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getVertexIpSql() {
|
public static String getVertexIpSql() {
|
||||||
String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime + " AND common_schema_type != 'BASE'";
|
// String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime + " AND common_schema_type != 'BASE'";
|
||||||
|
String where = " common_recv_time >= " + minTime + " AND common_recv_time < " + maxTime ;
|
||||||
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 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 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";
|
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 + "))";
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|||||||
switch (table) {
|
switch (table) {
|
||||||
case "R_LOCATE_FQDN2IP":
|
case "R_LOCATE_FQDN2IP":
|
||||||
updateProtocolDocument(doc);
|
updateProtocolDocument(doc);
|
||||||
deleteDistinctClientIpByTime(doc);
|
// deleteDistinctClientIpByTime(doc);
|
||||||
list.add(doc);
|
list.add(doc);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ public class LocateFqdn2Ip extends Relationship {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDistinctClientIp(BaseEdgeDocument newEdgeDocument,BaseEdgeDocument edgeDocument){
|
private void updateDistinctClientIp(BaseEdgeDocument newEdgeDocument,BaseEdgeDocument edgeDocument){
|
||||||
String[] distCip = (String[]) edgeDocument.getAttribute("DIST_CIP");
|
ArrayList<String> distCip = (ArrayList<String>) edgeDocument.getAttribute("DIST_CIP");
|
||||||
long[] distCipTs = (long[]) edgeDocument.getAttribute("DIST_CIP_TS");
|
ArrayList<Long> distCipTs = (ArrayList<Long>) edgeDocument.getAttribute("DIST_CIP_TS");
|
||||||
HashMap<String, Long> distCipToTs = new HashMap<>();
|
HashMap<String, Long> distCipToTs = new HashMap<>();
|
||||||
if (distCip.length == distCipTs.length){
|
if (distCip.size() == distCipTs.size()){
|
||||||
for (int i = 0;i < distCip.length;i++){
|
for (int i = 0;i < distCip.size();i++){
|
||||||
distCipToTs.put(distCip[i],distCipTs[i]);
|
distCipToTs.put(distCip.get(i),distCipTs.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object[] distCipRecent = (Object[])newEdgeDocument.getAttribute("DIST_CIP");
|
Object[] distCipRecent = (Object[])newEdgeDocument.getAttribute("DIST_CIP");
|
||||||
|
|||||||
@@ -3,23 +3,23 @@ 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=tsg_galaxy_v3
|
arangoDB.DB.name=tsg_galaxy_v3_test
|
||||||
arangoDB.batch=100000
|
arangoDB.batch=100000
|
||||||
arangoDB.ttl=3600
|
arangoDB.ttl=3600
|
||||||
|
|
||||||
arangoDB.read.limit=
|
arangoDB.read.limit=10
|
||||||
update.arango.batch=10000
|
update.arango.batch=10000
|
||||||
|
|
||||||
thread.pool.number=10
|
thread.pool.number=40
|
||||||
thread.await.termination.time=10
|
thread.await.termination.time=10
|
||||||
|
|
||||||
|
|
||||||
#读取clickhouse时间范围方式,0:读取过去一小时,1:指定时间范围
|
#读取clickhouse时间范围方式,0:读取过去一小时,1:指定时间范围
|
||||||
time.limit.type=0
|
time.limit.type=1
|
||||||
read.clickhouse.max.time=1598323368
|
read.clickhouse.max.time=1603421554
|
||||||
read.clickhouse.min.time=1597222501
|
read.clickhouse.min.time=1603354682
|
||||||
|
|
||||||
update.interval=3600
|
update.interval=3600
|
||||||
distinct.client.ip.num=10000
|
distinct.client.ip.num=100
|
||||||
recent.count.hour=24
|
recent.count.hour=24
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
drivers=ru.yandex.clickhouse.ClickHouseDriver
|
drivers=ru.yandex.clickhouse.ClickHouseDriver
|
||||||
mdb.user=default
|
mdb.user=default
|
||||||
#db.id=192.168.44.10:8124/tsg_galaxy_v3?socket_timeout=300000
|
db.id=192.168.44.10:8123/tsg_galaxy_v3?socket_timeout=3600000&compress=0
|
||||||
db.id=192.168.44.12:8123/tsg_galaxy_v3?socket_timeout=300000&compress=0
|
|
||||||
mdb.password=ceiec2019
|
mdb.password=ceiec2019
|
||||||
initialsize=1
|
initialsize=1
|
||||||
minidle=1
|
minidle=1
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ 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><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Ŀ<EFBFBD><C4BF>
|
#·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Ŀ<EFBFBD><C4BF>
|
||||||
#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=./logs/ip-learning-application.log
|
log4j.appender.file.file=./logs/ip-learning-application.log
|
||||||
log4j.appender.file.DatePattern='.'yyyy-MM-dd
|
log4j.appender.file.DatePattern='.'yyyy-MM-dd
|
||||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import cn.ac.iie.utils.ArangoDBConnect;
|
|||||||
import cn.ac.iie.utils.ExecutorThreadPool;
|
import cn.ac.iie.utils.ExecutorThreadPool;
|
||||||
import com.arangodb.ArangoCursor;
|
import com.arangodb.ArangoCursor;
|
||||||
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;
|
||||||
|
|
||||||
@@ -20,22 +19,12 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
*/
|
*/
|
||||||
public class BaseArangoData {
|
public class BaseArangoData {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BaseArangoData.class);
|
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 static ArangoDBConnect arangoDBConnect = ArangoDBConnect.getInstance();
|
||||||
|
|
||||||
private ExecutorThreadPool threadPool = ExecutorThreadPool.getInstance();
|
private ExecutorThreadPool threadPool = ExecutorThreadPool.getInstance();
|
||||||
|
|
||||||
public <T extends BaseDocument> void readHistoryData(String table,
|
public <T extends BaseDocument> ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> readHistoryData(String table, Class<T> type) {
|
||||||
ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> historyMap,
|
ConcurrentHashMap<Integer, ConcurrentHashMap<String, T>> historyMap = new ConcurrentHashMap<>();
|
||||||
Class<T> type) {
|
|
||||||
try {
|
try {
|
||||||
LOG.warn("开始更新" + table);
|
LOG.warn("开始更新" + table);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
@@ -43,10 +32,8 @@ public class BaseArangoData {
|
|||||||
historyMap.put(i, new ConcurrentHashMap<>());
|
historyMap.put(i, new ConcurrentHashMap<>());
|
||||||
}
|
}
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER());
|
CountDownLatch countDownLatch = new CountDownLatch(ApplicationConfig.THREAD_POOL_NUMBER());
|
||||||
// long[] timeRange = getTimeRange(table);
|
|
||||||
Long countTotal = getCountTotal(table);
|
Long countTotal = getCountTotal(table);
|
||||||
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER(); i++) {
|
for (int i = 0; i < ApplicationConfig.THREAD_POOL_NUMBER(); i++) {
|
||||||
// String sql = getQuerySql(timeRange, i, table);
|
|
||||||
String sql = getQuerySql(countTotal, i, table);
|
String sql = getQuerySql(countTotal, i, table);
|
||||||
ReadHistoryArangoData<T> readHistoryArangoData = new ReadHistoryArangoData<>(arangoDBConnect, sql, historyMap, type, table, countDownLatch);
|
ReadHistoryArangoData<T> readHistoryArangoData = new ReadHistoryArangoData<>(arangoDBConnect, sql, historyMap, type, table, countDownLatch);
|
||||||
threadPool.executor(readHistoryArangoData);
|
threadPool.executor(readHistoryArangoData);
|
||||||
@@ -57,6 +44,7 @@ public class BaseArangoData {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return historyMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Long getCountTotal(String table){
|
private Long getCountTotal(String table){
|
||||||
@@ -72,58 +60,18 @@ public class BaseArangoData {
|
|||||||
LOG.error(sql +"执行异常");
|
LOG.error(sql +"执行异常");
|
||||||
}
|
}
|
||||||
long last = System.currentTimeMillis();
|
long last = System.currentTimeMillis();
|
||||||
LOG.info(sql+" 结果:"+cnt+" 执行时间:"+(last-start));
|
LOG.warn(sql+" 结果:"+cnt+" 执行时间:"+(last-start));
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getQuerySql(Long cnt,int threadNumber, String table){
|
private String getQuerySql(Long cnt,int threadNumber, String table){
|
||||||
long sepNum = cnt / ApplicationConfig.THREAD_POOL_NUMBER() + 1;
|
long sepNum = cnt / ApplicationConfig.THREAD_POOL_NUMBER() + 1;
|
||||||
long offsetNum = threadNumber * sepNum;
|
long offsetNum = threadNumber * sepNum;
|
||||||
|
if (sepNum >= ApplicationConfig.ARANGODB_READ_LIMIT() * 10000){
|
||||||
|
sepNum = ApplicationConfig.ARANGODB_READ_LIMIT() * 10000;
|
||||||
|
}
|
||||||
return "FOR doc IN " + table + " limit "+offsetNum+","+sepNum+" RETURN doc";
|
return "FOR doc IN " + table + " limit "+offsetNum+","+sepNum+" RETURN doc";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
* @author wlh
|
* @author wlh
|
||||||
* 多线程全量读取arangoDb历史数据,封装到map
|
* 多线程全量读取arangoDb历史数据,封装到map
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
||||||
public static long currentHour = System.currentTimeMillis() / (60 * 60 * 1000) * 60 * 60;
|
public static long currentHour = System.currentTimeMillis() / (60 * 60 * 1000) * 60 * 60;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ReadHistoryArangoData.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ReadHistoryArangoData.class);
|
||||||
static final Integer RECENT_COUNT_HOUR = ApplicationConfig.RECENT_COUNT_HOUR();
|
private static final Integer RECENT_COUNT_HOUR = ApplicationConfig.RECENT_COUNT_HOUR();
|
||||||
|
|
||||||
public static final HashSet<String> PROTOCOL_SET;
|
private static final HashSet<String> PROTOCOL_SET;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PROTOCOL_SET = new HashSet<>();
|
PROTOCOL_SET = new HashSet<>();
|
||||||
@@ -69,9 +70,6 @@ public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|||||||
updateProtocolDocument(doc);
|
updateProtocolDocument(doc);
|
||||||
deleteDistinctClientIpByTime(doc);
|
deleteDistinctClientIpByTime(doc);
|
||||||
break;
|
break;
|
||||||
case "R_VISIT_IP2FQDN":
|
|
||||||
updateProtocolDocument(doc);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
int hashCode = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER();
|
int hashCode = Math.abs(key.hashCode()) % ApplicationConfig.THREAD_POOL_NUMBER();
|
||||||
@@ -95,7 +93,7 @@ public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|||||||
for (String protocol : PROTOCOL_SET) {
|
for (String protocol : PROTOCOL_SET) {
|
||||||
String protocolRecent = protocol + "_CNT_RECENT";
|
String protocolRecent = protocol + "_CNT_RECENT";
|
||||||
ArrayList<Long> cntRecent = (ArrayList<Long>) doc.getAttribute(protocolRecent);
|
ArrayList<Long> cntRecent = (ArrayList<Long>) doc.getAttribute(protocolRecent);
|
||||||
Long[] cntRecentsSrc = cntRecent.toArray(new Long[cntRecent.size()]);
|
Long[] cntRecentsSrc = cntRecent.toArray(new Long[0]);
|
||||||
Long[] cntRecentsDst = new Long[RECENT_COUNT_HOUR];
|
Long[] cntRecentsDst = new Long[RECENT_COUNT_HOUR];
|
||||||
System.arraycopy(cntRecentsSrc, 0, cntRecentsDst, 1, cntRecentsSrc.length - 1);
|
System.arraycopy(cntRecentsSrc, 0, cntRecentsDst, 1, cntRecentsSrc.length - 1);
|
||||||
cntRecentsDst[0] = 0L;
|
cntRecentsDst[0] = 0L;
|
||||||
@@ -107,6 +105,11 @@ public class ReadHistoryArangoData<T extends BaseDocument> extends Thread {
|
|||||||
private void deleteDistinctClientIpByTime(T doc) {
|
private void deleteDistinctClientIpByTime(T doc) {
|
||||||
ArrayList<String> distCip = (ArrayList<String>) doc.getAttribute("DIST_CIP");
|
ArrayList<String> distCip = (ArrayList<String>) doc.getAttribute("DIST_CIP");
|
||||||
ArrayList<Long> distCipTs = (ArrayList<Long>) doc.getAttribute("DIST_CIP_TS");
|
ArrayList<Long> distCipTs = (ArrayList<Long>) doc.getAttribute("DIST_CIP_TS");
|
||||||
|
if (distCip == null || distCip.isEmpty()){
|
||||||
|
doc.updateAttribute("DIST_CIP", new String[0]);
|
||||||
|
doc.updateAttribute("DIST_CIP_TS", new long[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
distCipTs.add(currentHour - RECENT_COUNT_HOUR * 3600);
|
distCipTs.add(currentHour - RECENT_COUNT_HOUR * 3600);
|
||||||
Collections.sort(distCipTs);
|
Collections.sort(distCipTs);
|
||||||
int index = distCipTs.indexOf(currentHour - RECENT_COUNT_HOUR * 3600);
|
int index = distCipTs.indexOf(currentHour - RECENT_COUNT_HOUR * 3600);
|
||||||
|
|||||||
@@ -27,14 +27,27 @@ public class ArangoDBConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void getArangoDatabase(){
|
private static void getArangoDatabase(){
|
||||||
arangoDB = new ArangoDB.Builder()
|
ArangoDB.Builder host = getArangoHost();
|
||||||
|
arangoDB = host
|
||||||
.maxConnections(ApplicationConfig.THREAD_POOL_NUMBER())
|
.maxConnections(ApplicationConfig.THREAD_POOL_NUMBER())
|
||||||
.host(ApplicationConfig.ARANGODB_HOST(), ApplicationConfig.ARANGODB_PORT())
|
.acquireHostList(true)
|
||||||
.user(ApplicationConfig.ARANGODB_USER())
|
.user(ApplicationConfig.ARANGODB_USER())
|
||||||
.password(ApplicationConfig.ARANGODB_PASSWORD())
|
.password(ApplicationConfig.ARANGODB_PASSWORD())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ArangoDB.Builder getArangoHost(){
|
||||||
|
String hostList = ApplicationConfig.ARANGODB_HOST();
|
||||||
|
String[] split = hostList.split(",");
|
||||||
|
ArangoDB.Builder host = new ArangoDB.Builder();
|
||||||
|
for (String hostStr : split) {
|
||||||
|
host.host(hostStr, ApplicationConfig.ARANGODB_PORT());
|
||||||
|
LOG.warn("arangoDB host {} 已添加",hostStr);
|
||||||
|
}
|
||||||
|
LOG.warn("获取arangoDB host成功");
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized ArangoDBConnect getInstance(){
|
public static synchronized ArangoDBConnect getInstance(){
|
||||||
if (null == conn){
|
if (null == conn){
|
||||||
conn = new ArangoDBConnect();
|
conn = new ArangoDBConnect();
|
||||||
@@ -70,26 +83,6 @@ public class ArangoDBConnect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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){
|
public <T> void overwrite(ArrayList<T> docOverwrite,String collectionName){
|
||||||
ArangoDatabase database = getDatabase();
|
ArangoDatabase database = getDatabase();
|
||||||
try {
|
try {
|
||||||
@@ -101,11 +94,11 @@ public class ArangoDBConnect {
|
|||||||
MultiDocumentEntity<DocumentCreateEntity<T>> documentCreateEntityMultiDocumentEntity = collection.insertDocuments(docOverwrite, documentCreateOptions);
|
MultiDocumentEntity<DocumentCreateEntity<T>> documentCreateEntityMultiDocumentEntity = collection.insertDocuments(docOverwrite, documentCreateOptions);
|
||||||
Collection<ErrorEntity> errors = documentCreateEntityMultiDocumentEntity.getErrors();
|
Collection<ErrorEntity> errors = documentCreateEntityMultiDocumentEntity.getErrors();
|
||||||
for (ErrorEntity errorEntity:errors){
|
for (ErrorEntity errorEntity:errors){
|
||||||
LOG.warn("写入arangoDB异常:"+errorEntity.getErrorMessage());
|
LOG.debug("写入arangoDB异常:"+errorEntity.getErrorMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
System.out.println("更新失败:"+e.toString());
|
LOG.error("更新arangoDB失败:"+e.toString());
|
||||||
}finally {
|
}finally {
|
||||||
docOverwrite.clear();
|
docOverwrite.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,40 @@
|
|||||||
#spark任务配置
|
#spark任务配置
|
||||||
spark.sql.shuffle.partitions=5
|
spark.sql.shuffle.partitions=10
|
||||||
spark.executor.memory=4g
|
spark.executor.memory=4g
|
||||||
spark.app.name=test
|
spark.app.name=test
|
||||||
spark.network.timeout=300s
|
spark.network.timeout=300s
|
||||||
repartitionNumber=36
|
|
||||||
spark.serializer=org.apache.spark.serializer.KryoSerializer
|
spark.serializer=org.apache.spark.serializer.KryoSerializer
|
||||||
|
#spark.serializer=org.apache.spark.serializer.JavaSerializer
|
||||||
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.44.10:8123/tsg_galaxy_v3
|
||||||
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=ceiec2019
|
||||||
spark.read.clickhouse.numPartitions=144
|
spark.read.clickhouse.numPartitions=5
|
||||||
spark.read.clickhouse.fetchsize=10000
|
spark.read.clickhouse.fetchsize=10000
|
||||||
spark.read.clickhouse.partitionColumn=common_recv_time
|
spark.read.clickhouse.partitionColumn=LAST_FOUND_TIME
|
||||||
clickhouse.socket.timeout=300000
|
clickhouse.socket.timeout=300000
|
||||||
#arangoDB配置
|
#arangoDB配置
|
||||||
arangoDB.host=192.168.40.182
|
arangoDB.host=192.168.40.123,192.168.40.223,192.168.40.222
|
||||||
|
#arangoDB.host=192.168.40.223
|
||||||
arangoDB.port=8529
|
arangoDB.port=8529
|
||||||
arangoDB.user=upsert
|
arangoDB.user=upsert
|
||||||
arangoDB.password=ceiec2018
|
arangoDB.password=ceiec2019
|
||||||
#arangoDB.DB.name=insert_iplearn_index
|
arangoDB.DB.name=tsg_galaxy_v3
|
||||||
arangoDB.DB.name=ip-learning-test-0
|
|
||||||
arangoDB.ttl=3600
|
arangoDB.ttl=3600
|
||||||
|
|
||||||
thread.pool.number=5
|
thread.pool.number=10
|
||||||
|
|
||||||
#读取clickhouse时间范围方式,0:读取过去一小时;1:指定时间范围
|
#读取clickhouse时间范围方式,0:读取过去一小时;1:指定时间范围
|
||||||
clickhouse.time.limit.type=0
|
clickhouse.time.limit.type=1
|
||||||
read.clickhouse.max.time=1571245220
|
read.clickhouse.max.time=1600916194
|
||||||
read.clickhouse.min.time=1571245210
|
read.clickhouse.min.time=1599197648
|
||||||
|
|
||||||
#读取arangoDB时间范围方式,0:正常读;1:指定时间范围
|
arangoDB.read.sepNum=10
|
||||||
arango.time.limit.type=0
|
|
||||||
read.arango.max.time=1571245320
|
|
||||||
read.arango.min.time=1571245200
|
|
||||||
|
|
||||||
arangoDB.read.limit=
|
|
||||||
update.arango.batch=10000
|
update.arango.batch=10000
|
||||||
|
|
||||||
distinct.client.ip.num=10000
|
distinct.client.ip.num=10000
|
||||||
recent.count.hour=24
|
recent.count.hour=24
|
||||||
|
|
||||||
update.interval=10800
|
update.interval=3600
|
||||||
|
|||||||
@@ -36,12 +36,7 @@ object ApplicationConfig {
|
|||||||
val READ_CLICKHOUSE_MAX_TIME: Long = config.getLong("read.clickhouse.max.time")
|
val READ_CLICKHOUSE_MAX_TIME: Long = config.getLong("read.clickhouse.max.time")
|
||||||
val READ_CLICKHOUSE_MIN_TIME: Long = config.getLong("read.clickhouse.min.time")
|
val READ_CLICKHOUSE_MIN_TIME: Long = config.getLong("read.clickhouse.min.time")
|
||||||
|
|
||||||
val ARANGO_TIME_LIMIT_TYPE: Int = config.getInt("arango.time.limit.type")
|
val ARANGODB_READ_LIMIT: Long = config.getLong("arangoDB.read.sepNum")
|
||||||
|
|
||||||
val READ_ARANGO_MAX_TIME: Long = config.getLong("read.arango.max.time")
|
|
||||||
val READ_ARANGO_MIN_TIME: Long = config.getLong("read.arango.min.time")
|
|
||||||
|
|
||||||
val ARANGODB_READ_LIMIT: String = config.getString("arangoDB.read.limit")
|
|
||||||
val UPDATE_ARANGO_BATCH: Int = config.getInt("update.arango.batch")
|
val UPDATE_ARANGO_BATCH: Int = config.getInt("update.arango.batch")
|
||||||
val RECENT_COUNT_HOUR: Int = config.getInt("recent.count.hour")
|
val RECENT_COUNT_HOUR: Int = config.getInt("recent.count.hour")
|
||||||
val DISTINCT_CLIENT_IP_NUM: Int = config.getInt("distinct.client.ip.num")
|
val DISTINCT_CLIENT_IP_NUM: Int = config.getInt("distinct.client.ip.num")
|
||||||
|
|||||||
@@ -11,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)
|
||||||
@@ -28,6 +28,8 @@ object BaseClickhouseData {
|
|||||||
.load()
|
.load()
|
||||||
dataFrame.printSchema()
|
dataFrame.printSchema()
|
||||||
dataFrame.createOrReplaceGlobalTempView("dbtable")
|
dataFrame.createOrReplaceGlobalTempView("dbtable")
|
||||||
|
|
||||||
|
dataFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
def loadConnectionDataFromCk(): Unit ={
|
def loadConnectionDataFromCk(): Unit ={
|
||||||
@@ -105,47 +107,38 @@ object BaseClickhouseData {
|
|||||||
|
|
||||||
def getVertexIpDf: DataFrame ={
|
def getVertexIpDf: DataFrame ={
|
||||||
loadConnectionDataFromCk()
|
loadConnectionDataFromCk()
|
||||||
|
val where = "common_recv_time >= " + timeLimit._2 + " AND common_recv_time < " + timeLimit._1
|
||||||
val sql =
|
val sql =
|
||||||
"""
|
s"""
|
||||||
|SELECT
|
|(SELECT * FROM
|
||||||
| *
|
|((SELECT common_client_ip AS IP,MIN(common_end_time) AS FIRST_FOUND_TIME,
|
||||||
|FROM
|
|MAX(common_end_time) AS LAST_FOUND_TIME,
|
||||||
| (
|
|
||||||
| (
|
|
||||||
| 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,
|
|count(*) as SESSION_COUNT,
|
||||||
| sum(common_c2s_byte_num) as BYTES_SUM,
|
|SUM(common_c2s_byte_num+common_s2c_byte_num) as BYTES_SUM,
|
||||||
|
|groupUniqArray(2)(common_link_info_c2s)[2] as common_link_info,
|
||||||
|'client' as ip_type
|
|'client' as ip_type
|
||||||
| FROM
|
|FROM tsg_galaxy_v3.connection_record_log
|
||||||
| global_temp.dbtable
|
|where $where
|
||||||
| GROUP BY
|
|group by common_client_ip)
|
||||||
| IP
|
|
||||||
| )
|
|
||||||
|UNION ALL
|
|UNION ALL
|
||||||
| (
|
|(SELECT common_server_ip AS IP,
|
||||||
| SELECT
|
|MIN(common_end_time) AS FIRST_FOUND_TIME,
|
||||||
| common_server_ip AS IP,
|
|MAX(common_end_time) AS LAST_FOUND_TIME,
|
||||||
| MIN(common_recv_time) AS FIRST_FOUND_TIME,
|
|
||||||
| MAX(common_recv_time) AS LAST_FOUND_TIME,
|
|
||||||
|count(*) as SESSION_COUNT,
|
|count(*) as SESSION_COUNT,
|
||||||
| sum(common_s2c_byte_num) as BYTES_SUM,
|
|SUM(common_c2s_byte_num+common_s2c_byte_num) as BYTES_SUM,
|
||||||
|
|groupUniqArray(2)(common_link_info_s2c)[2] as common_link_info,
|
||||||
|'server' as ip_type
|
|'server' as ip_type
|
||||||
| FROM
|
|FROM tsg_galaxy_v3.connection_record_log
|
||||||
| global_temp.dbtable
|
|where $where
|
||||||
| GROUP BY
|
|group by common_server_ip))) as dbtable
|
||||||
| IP
|
|
||||||
| )
|
|
||||||
| )
|
|
||||||
""".stripMargin
|
""".stripMargin
|
||||||
LOG.warn(sql)
|
LOG.warn(sql)
|
||||||
val vertexIpDf = spark.sql(sql)
|
val frame = initClickhouseData(sql)
|
||||||
vertexIpDf.printSchema()
|
frame.printSchema()
|
||||||
vertexIpDf
|
frame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
def getRelationFqdnLocateIpDf: DataFrame ={
|
def getRelationFqdnLocateIpDf: DataFrame ={
|
||||||
loadConnectionDataFromCk()
|
loadConnectionDataFromCk()
|
||||||
val sslSql =
|
val sslSql =
|
||||||
@@ -190,6 +183,92 @@ object BaseClickhouseData {
|
|||||||
relationFqdnLocateIpDf.printSchema()
|
relationFqdnLocateIpDf.printSchema()
|
||||||
relationFqdnLocateIpDf
|
relationFqdnLocateIpDf
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
def getRelationFqdnLocateIpDf: DataFrame ={
|
||||||
|
val where = "common_recv_time >= " + timeLimit._2 + " AND common_recv_time < " + timeLimit._1
|
||||||
|
val sql =
|
||||||
|
s"""
|
||||||
|
|(SELECT * FROM
|
||||||
|
|((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,
|
||||||
|
|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_recv_time) AS LAST_FOUND_TIME,MIN(common_recv_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 getRelationSubidLocateIpDf: DataFrame ={
|
||||||
|
val where =
|
||||||
|
s"""
|
||||||
|
| common_recv_time >= ${timeLimit._2}
|
||||||
|
| AND common_recv_time < ${timeLimit._1}
|
||||||
|
| AND common_subscriber_id != ''
|
||||||
|
| AND radius_framed_ip != ''
|
||||||
|
""".stripMargin
|
||||||
|
val sql =
|
||||||
|
s"""
|
||||||
|
|(
|
||||||
|
|SELECT common_subscriber_id,radius_framed_ip,MAX(common_recv_time) as LAST_FOUND_TIME,MIN(common_recv_time) as FIRST_FOUND_TIME
|
||||||
|
|FROM radius_record_log
|
||||||
|
|WHERE $where GROUP BY common_subscriber_id,radius_framed_ip
|
||||||
|
|) as dbtable
|
||||||
|
""".stripMargin
|
||||||
|
LOG.warn(sql)
|
||||||
|
val frame = initClickhouseData(sql)
|
||||||
|
frame.printSchema()
|
||||||
|
frame
|
||||||
|
}
|
||||||
|
|
||||||
|
def getVertexSubidDf: DataFrame ={
|
||||||
|
val where =
|
||||||
|
s"""
|
||||||
|
| common_recv_time >= ${timeLimit._2}
|
||||||
|
| AND common_recv_time < ${timeLimit._1}
|
||||||
|
| AND common_subscriber_id != ''
|
||||||
|
| AND radius_framed_ip != ''
|
||||||
|
""".stripMargin
|
||||||
|
val sql =
|
||||||
|
s"""
|
||||||
|
|(
|
||||||
|
|SELECT common_subscriber_id,MAX(common_recv_time) as LAST_FOUND_TIME,MIN(common_recv_time) as FIRST_FOUND_TIME FROM radius_record_log
|
||||||
|
|WHERE $where GROUP BY common_subscriber_id
|
||||||
|
|)as dbtable
|
||||||
|
""".stripMargin
|
||||||
|
LOG.warn(sql)
|
||||||
|
val frame = initClickhouseData(sql)
|
||||||
|
frame.printSchema()
|
||||||
|
frame
|
||||||
|
}
|
||||||
|
|
||||||
|
def getVertexFramedIpDf: DataFrame ={
|
||||||
|
val where =
|
||||||
|
s"""
|
||||||
|
| common_recv_time >= ${timeLimit._2}
|
||||||
|
| AND common_recv_time < ${timeLimit._1}
|
||||||
|
| AND common_subscriber_id != ''
|
||||||
|
| AND radius_framed_ip != ''
|
||||||
|
""".stripMargin
|
||||||
|
val sql =
|
||||||
|
s"""
|
||||||
|
|(
|
||||||
|
|SELECT DISTINCT radius_framed_ip,common_recv_time as LAST_FOUND_TIME FROM radius_record_log WHERE $where
|
||||||
|
|)as dbtable
|
||||||
|
""".stripMargin
|
||||||
|
LOG.warn(sql)
|
||||||
|
val frame = initClickhouseData(sql)
|
||||||
|
frame.printSchema()
|
||||||
|
frame
|
||||||
|
}
|
||||||
|
|
||||||
private def getTimeLimit: (Long,Long) ={
|
private def getTimeLimit: (Long,Long) ={
|
||||||
var maxTime = 0L
|
var maxTime = 0L
|
||||||
|
|||||||
@@ -20,6 +20,17 @@ object MergeDataFrame {
|
|||||||
.partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
.partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def mergeVertexFrameIp: RDD[Row] ={
|
||||||
|
val values = BaseClickhouseData.getVertexFramedIpDf
|
||||||
|
.repartition(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)
|
||||||
|
.rdd.map(row => {
|
||||||
|
val ip = row.getAs[String]("radius_framed_ip")
|
||||||
|
(ip, row)
|
||||||
|
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
|
LOG.warn(s"读取R_LOCATE_SUBSCRIBER2IP clickhouse成功,共:${values.count()} 条")
|
||||||
|
values
|
||||||
|
}
|
||||||
|
|
||||||
def mergeVertexIp(): RDD[Row]={
|
def mergeVertexIp(): RDD[Row]={
|
||||||
val vertexIpDf = BaseClickhouseData.getVertexIpDf
|
val vertexIpDf = BaseClickhouseData.getVertexIpDf
|
||||||
val frame = vertexIpDf.groupBy("IP").agg(
|
val frame = vertexIpDf.groupBy("IP").agg(
|
||||||
@@ -27,7 +38,8 @@ object MergeDataFrame {
|
|||||||
max("LAST_FOUND_TIME").alias("LAST_FOUND_TIME"),
|
max("LAST_FOUND_TIME").alias("LAST_FOUND_TIME"),
|
||||||
collect_list("SESSION_COUNT").alias("SESSION_COUNT_LIST"),
|
collect_list("SESSION_COUNT").alias("SESSION_COUNT_LIST"),
|
||||||
collect_list("BYTES_SUM").alias("BYTES_SUM_LIST"),
|
collect_list("BYTES_SUM").alias("BYTES_SUM_LIST"),
|
||||||
collect_list("ip_type").alias("ip_type_list")
|
collect_list("ip_type").alias("ip_type_list"),
|
||||||
|
last("common_link_info").alias("common_link_info")
|
||||||
)
|
)
|
||||||
val values = frame.rdd.map(row => (row.get(0), row))
|
val values = frame.rdd.map(row => (row.get(0), row))
|
||||||
.partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
.partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
@@ -35,7 +47,9 @@ object MergeDataFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def mergeRelationFqdnLocateIp(): RDD[Row] ={
|
def mergeRelationFqdnLocateIp(): RDD[Row] ={
|
||||||
val frame = BaseClickhouseData.getRelationFqdnLocateIpDf.filter(row => isDomain(row.getAs[String]("FQDN")))
|
val frame = BaseClickhouseData.getRelationFqdnLocateIpDf
|
||||||
|
.repartition(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)
|
||||||
|
.filter(row => isDomain(row.getAs[String]("FQDN")))
|
||||||
.groupBy("FQDN", "common_server_ip")
|
.groupBy("FQDN", "common_server_ip")
|
||||||
.agg(
|
.agg(
|
||||||
min("FIRST_FOUND_TIME").alias("FIRST_FOUND_TIME"),
|
min("FIRST_FOUND_TIME").alias("FIRST_FOUND_TIME"),
|
||||||
@@ -44,28 +58,50 @@ object MergeDataFrame {
|
|||||||
collect_list("schema_type").alias("schema_type_list"),
|
collect_list("schema_type").alias("schema_type_list"),
|
||||||
collect_set("DIST_CIP_RECENT").alias("DIST_CIP_RECENT")
|
collect_set("DIST_CIP_RECENT").alias("DIST_CIP_RECENT")
|
||||||
)
|
)
|
||||||
frame.rdd.map(row => {
|
val values = frame.rdd.map(row => {
|
||||||
val fqdn = row.getAs[String]("FQDN")
|
val fqdn = row.getAs[String]("FQDN")
|
||||||
val serverIp = row.getAs[String]("common_server_ip")
|
val serverIp = row.getAs[String]("common_server_ip")
|
||||||
val key = fqdn.concat("-" + serverIp)
|
val key = fqdn.concat("-" + serverIp)
|
||||||
(key, row)
|
(key, row)
|
||||||
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
|
LOG.warn(s"读取R_LOCATE_FQDN2IP clickhouse成功,共:${values.count()} 条")
|
||||||
|
values
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def mergeRelationSubidLocateIp(): RDD[Row] ={
|
||||||
|
val values = BaseClickhouseData.getRelationSubidLocateIpDf
|
||||||
|
.repartition(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)
|
||||||
|
.rdd.map(row => {
|
||||||
|
val commonSubscriberId = row.getAs[String]("common_subscriber_id")
|
||||||
|
val ip = row.getAs[String]("radius_framed_ip")
|
||||||
|
val key = commonSubscriberId.concat("-" + ip)
|
||||||
|
(key, row)
|
||||||
|
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
|
LOG.warn(s"读取R_LOCATE_SUBSCRIBER2IP clickhouse成功,共:${values.count()} 条")
|
||||||
|
values
|
||||||
|
}
|
||||||
|
|
||||||
|
def mergeVertexSubid(): RDD[Row] ={
|
||||||
|
val values = BaseClickhouseData.getVertexSubidDf
|
||||||
|
.repartition(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)
|
||||||
|
.rdd.map(row => {
|
||||||
|
val commonSubscriberId = row.getAs[String]("common_subscriber_id")
|
||||||
|
(commonSubscriberId, row)
|
||||||
|
}).partitionBy(new CustomPartitioner(ApplicationConfig.SPARK_SQL_SHUFFLE_PARTITIONS)).values
|
||||||
|
LOG.warn(s"读取SUBSCRIBER clickhouse成功,共:${values.count()} 条")
|
||||||
|
values
|
||||||
|
}
|
||||||
|
|
||||||
private def isDomain(fqdn: String): Boolean = {
|
private def isDomain(fqdn: String): Boolean = {
|
||||||
try {
|
try {
|
||||||
if (fqdn == null || fqdn.length == 0) {
|
if (fqdn == null || fqdn.length == 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (fqdn.contains(":")) {
|
|
||||||
val s = fqdn.split(":")(0)
|
val fqdnArr = fqdn.split(":")(0).split("\\.")
|
||||||
if (s.contains(":")){
|
|
||||||
return false
|
if (fqdnArr.length != 4){
|
||||||
}
|
|
||||||
}
|
|
||||||
val fqdnArr = fqdn.split("\\.")
|
|
||||||
if (fqdnArr.length < 4 || fqdnArr.length > 4){
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for (f <- fqdnArr) {
|
for (f <- fqdnArr) {
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ object UpdateDocHandler {
|
|||||||
hisDoc.addAttribute(attributeName,newAttribute+hisAttritube)
|
hisDoc.addAttribute(attributeName,newAttribute+hisAttritube)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def replaceAttribute(hisDoc: BaseDocument,newAttribute:String,attributeName:String): Unit ={
|
||||||
|
hisDoc.addAttribute(attributeName,newAttribute)
|
||||||
|
}
|
||||||
|
|
||||||
def separateAttributeByIpType(ipTypeList:ofRef[String],
|
def separateAttributeByIpType(ipTypeList:ofRef[String],
|
||||||
sessionCountList:ofRef[AnyRef],
|
sessionCountList:ofRef[AnyRef],
|
||||||
bytesSumList:ofRef[AnyRef]): (Long,Long,Long,Long) ={
|
bytesSumList:ofRef[AnyRef]): (Long,Long,Long,Long) ={
|
||||||
@@ -93,8 +97,13 @@ object UpdateDocHandler {
|
|||||||
doc.addAttribute("PROTOCOL_TYPE",protocolTypeBuilder.toString().replaceFirst(",",""))
|
doc.addAttribute("PROTOCOL_TYPE",protocolTypeBuilder.toString().replaceFirst(",",""))
|
||||||
}
|
}
|
||||||
|
|
||||||
def mergeDistinctIp(distCipRecent:ofRef[ofRef[String]]): Array[String] ={
|
def mergeDistinctIp(distCipRecent:ofRef[String]): Array[String] ={
|
||||||
distCipRecent.flatten.distinct.take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toArray
|
distCipRecent.flatMap(str => {
|
||||||
|
str.replaceAll("\\[","")
|
||||||
|
.replaceAll("\\]","")
|
||||||
|
.replaceAll("\\'","")
|
||||||
|
.split(",")
|
||||||
|
}).distinct.take(ApplicationConfig.DISTINCT_CLIENT_IP_NUM).toArray
|
||||||
}
|
}
|
||||||
|
|
||||||
def putDistinctIp(doc:BaseEdgeDocument,newDistinctIp:Array[String]): Unit ={
|
def putDistinctIp(doc:BaseEdgeDocument,newDistinctIp:Array[String]): Unit ={
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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.dao.BaseArangoData._
|
|
||||||
import cn.ac.iie.service.transform.MergeDataFrame._
|
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.{ArangoDBConnect, ExecutorThreadPool, SparkSessionUtil}
|
||||||
@@ -26,9 +25,12 @@ object UpdateDocument {
|
|||||||
|
|
||||||
def update(): Unit = {
|
def update(): Unit = {
|
||||||
try {
|
try {
|
||||||
updateDocument("FQDN", historyVertexFqdnMap, getVertexFqdnRow, classOf[BaseDocument], mergeVertexFqdn)
|
// updateDocument("FQDN", getVertexFqdnRow, classOf[BaseDocument], mergeVertexFqdn)
|
||||||
updateDocument("IP", historyVertexIpMap, getVertexIpRow, classOf[BaseDocument], mergeVertexIp)
|
// updateDocument("IP", getVertexIpRow, classOf[BaseDocument], mergeVertexIp)
|
||||||
updateDocument("R_LOCATE_FQDN2IP", historyRelationFqdnAddressIpMap, getRelationFqdnLocateIpRow, classOf[BaseEdgeDocument], mergeRelationFqdnLocateIp)
|
updateDocument("R_LOCATE_FQDN2IP", getRelationFqdnLocateIpRow, classOf[BaseEdgeDocument], mergeRelationFqdnLocateIp)
|
||||||
|
updateDocument("SUBSCRIBER",getVertexSubidRow,classOf[BaseDocument],mergeVertexSubid)
|
||||||
|
insertFrameIp()
|
||||||
|
updateDocument("R_LOCATE_SUBSCRIBER2IP",getRelationSubidLocateIpRow,classOf[BaseEdgeDocument],mergeRelationSubidLocateIp)
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception => e.printStackTrace()
|
case e: Exception => e.printStackTrace()
|
||||||
} finally {
|
} finally {
|
||||||
@@ -38,13 +40,33 @@ object UpdateDocument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def insertFrameIp(): Unit ={
|
||||||
|
mergeVertexFrameIp.foreachPartition(iter => {
|
||||||
|
val resultDocumentList = new util.ArrayList[BaseDocument]
|
||||||
|
var i = 0
|
||||||
|
iter.foreach(row => {
|
||||||
|
val document = getVertexFrameipRow(row)
|
||||||
|
resultDocumentList.add(document)
|
||||||
|
i += 1
|
||||||
|
if (i >= ApplicationConfig.UPDATE_ARANGO_BATCH) {
|
||||||
|
arangoManger.overwrite(resultDocumentList, "IP")
|
||||||
|
LOG.warn(s"更新:IP" + i)
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (i != 0) {
|
||||||
|
arangoManger.overwrite(resultDocumentList, "IP")
|
||||||
|
LOG.warn(s"更新IP:" + i)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private def updateDocument[T <: BaseDocument](collName: String,
|
private def updateDocument[T <: BaseDocument](collName: String,
|
||||||
historyMap: ConcurrentHashMap[Integer, ConcurrentHashMap[String, T]],
|
|
||||||
getDocumentRow: (Row, ConcurrentHashMap[String, T]) => T,
|
getDocumentRow: (Row, ConcurrentHashMap[String, T]) => T,
|
||||||
clazz: Class[T],
|
clazz: Class[T],
|
||||||
getNewDataRdd: () => RDD[Row]
|
getNewDataRdd: () => RDD[Row]
|
||||||
): Unit = {
|
): Unit = {
|
||||||
baseArangoData.readHistoryData(collName, historyMap, clazz)
|
val historyMap = baseArangoData.readHistoryData(collName, clazz)
|
||||||
val hisBc = spark.sparkContext.broadcast(historyMap)
|
val hisBc = spark.sparkContext.broadcast(historyMap)
|
||||||
try {
|
try {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
@@ -95,6 +117,56 @@ object UpdateDocument {
|
|||||||
document
|
document
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def getRelationSubidLocateIpRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseEdgeDocument]): BaseEdgeDocument ={
|
||||||
|
val subId = row.getAs[String]("common_subscriber_id")
|
||||||
|
val ip = row.getAs[String]("radius_framed_ip")
|
||||||
|
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
||||||
|
val firstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
||||||
|
|
||||||
|
val key = subId.concat("-"+ip)
|
||||||
|
var document = dictionaryMap.getOrDefault(key,null)
|
||||||
|
if (document != null){
|
||||||
|
updateMaxAttribute(document,lastFoundTime,"LAST_FOUND_TIME")
|
||||||
|
} else {
|
||||||
|
document = new BaseEdgeDocument()
|
||||||
|
document.setKey(key)
|
||||||
|
document.setFrom("SUBSCRIBER/" + subId)
|
||||||
|
document.setTo("IP/" + ip)
|
||||||
|
document.addAttribute("SUBSCRIBER",subId)
|
||||||
|
document.addAttribute("IP",ip)
|
||||||
|
document.addAttribute("FIRST_FOUND_TIME",firstFoundTime)
|
||||||
|
document.addAttribute("LAST_FOUND_TIME",lastFoundTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
document
|
||||||
|
}
|
||||||
|
|
||||||
|
private def getVertexFrameipRow(row: Row): BaseDocument ={
|
||||||
|
val ip = row.getAs[String]("radius_framed_ip")
|
||||||
|
val document = new BaseDocument()
|
||||||
|
document.setKey(ip)
|
||||||
|
document.addAttribute("IP",ip)
|
||||||
|
document
|
||||||
|
}
|
||||||
|
|
||||||
|
private def getVertexSubidRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseDocument]): BaseDocument ={
|
||||||
|
val subId = row.getAs[String]("common_subscriber_id")
|
||||||
|
val subLastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
||||||
|
val subFirstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
||||||
|
var document = dictionaryMap.getOrDefault(subId,null)
|
||||||
|
if (document != null){
|
||||||
|
updateMaxAttribute(document,subLastFoundTime,"LAST_FOUND_TIME")
|
||||||
|
} else {
|
||||||
|
document = new BaseDocument()
|
||||||
|
document.setKey(subId)
|
||||||
|
document.addAttribute("SUBSCRIBER",subId)
|
||||||
|
document.addAttribute("FIRST_FOUND_TIME",subFirstFoundTime)
|
||||||
|
document.addAttribute("LAST_FOUND_TIME",subLastFoundTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
document
|
||||||
|
}
|
||||||
|
|
||||||
private def getVertexIpRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseDocument]): BaseDocument = {
|
private def getVertexIpRow(row: Row, dictionaryMap: ConcurrentHashMap[String, BaseDocument]): BaseDocument = {
|
||||||
val ip = row.getAs[String]("IP")
|
val ip = row.getAs[String]("IP")
|
||||||
val firstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
val firstFoundTime = row.getAs[Long]("FIRST_FOUND_TIME")
|
||||||
@@ -102,6 +174,7 @@ object UpdateDocument {
|
|||||||
val sessionCountList = row.getAs[ofRef[AnyRef]]("SESSION_COUNT_LIST")
|
val sessionCountList = row.getAs[ofRef[AnyRef]]("SESSION_COUNT_LIST")
|
||||||
val bytesSumList = row.getAs[ofRef[AnyRef]]("BYTES_SUM_LIST")
|
val bytesSumList = row.getAs[ofRef[AnyRef]]("BYTES_SUM_LIST")
|
||||||
val ipTypeList = row.getAs[ofRef[String]]("ip_type_list")
|
val ipTypeList = row.getAs[ofRef[String]]("ip_type_list")
|
||||||
|
val linkInfo = row.getAs[String]("common_link_info")
|
||||||
val sepAttributeTuple = separateAttributeByIpType(ipTypeList, sessionCountList, bytesSumList)
|
val sepAttributeTuple = separateAttributeByIpType(ipTypeList, sessionCountList, bytesSumList)
|
||||||
|
|
||||||
var document = dictionaryMap.getOrDefault(ip, null)
|
var document = dictionaryMap.getOrDefault(ip, null)
|
||||||
@@ -111,6 +184,7 @@ object UpdateDocument {
|
|||||||
updateSumAttribute(document, sepAttributeTuple._2, "SERVER_BYTES_SUM")
|
updateSumAttribute(document, sepAttributeTuple._2, "SERVER_BYTES_SUM")
|
||||||
updateSumAttribute(document, sepAttributeTuple._3, "CLIENT_SESSION_COUNT")
|
updateSumAttribute(document, sepAttributeTuple._3, "CLIENT_SESSION_COUNT")
|
||||||
updateSumAttribute(document, sepAttributeTuple._4, "CLIENT_BYTES_SUM")
|
updateSumAttribute(document, sepAttributeTuple._4, "CLIENT_BYTES_SUM")
|
||||||
|
replaceAttribute(document,linkInfo,"COMMON_LINK_INFO")
|
||||||
} else {
|
} else {
|
||||||
document = new BaseDocument
|
document = new BaseDocument
|
||||||
document.setKey(ip)
|
document.setKey(ip)
|
||||||
@@ -121,7 +195,7 @@ object UpdateDocument {
|
|||||||
document.addAttribute("SERVER_BYTES_SUM", sepAttributeTuple._2)
|
document.addAttribute("SERVER_BYTES_SUM", sepAttributeTuple._2)
|
||||||
document.addAttribute("CLIENT_SESSION_COUNT", sepAttributeTuple._3)
|
document.addAttribute("CLIENT_SESSION_COUNT", sepAttributeTuple._3)
|
||||||
document.addAttribute("CLIENT_BYTES_SUM", sepAttributeTuple._4)
|
document.addAttribute("CLIENT_BYTES_SUM", sepAttributeTuple._4)
|
||||||
document.addAttribute("COMMON_LINK_INFO", "")
|
document.addAttribute("COMMON_LINK_INFO", linkInfo)
|
||||||
}
|
}
|
||||||
document
|
document
|
||||||
}
|
}
|
||||||
@@ -133,7 +207,7 @@ object UpdateDocument {
|
|||||||
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
val lastFoundTime = row.getAs[Long]("LAST_FOUND_TIME")
|
||||||
val countTotalList = row.getAs[ofRef[AnyRef]]("COUNT_TOTAL_LIST")
|
val countTotalList = row.getAs[ofRef[AnyRef]]("COUNT_TOTAL_LIST")
|
||||||
val schemaTypeList = row.getAs[ofRef[AnyRef]]("schema_type_list")
|
val schemaTypeList = row.getAs[ofRef[AnyRef]]("schema_type_list")
|
||||||
val distCipRecent = row.getAs[ofRef[ofRef[String]]]("DIST_CIP_RECENT")
|
val distCipRecent = row.getAs[ofRef[String]]("DIST_CIP_RECENT")
|
||||||
|
|
||||||
val sepAttritubeMap: Map[String, Long] = separateAttributeByProtocol(schemaTypeList, countTotalList)
|
val sepAttritubeMap: Map[String, Long] = separateAttributeByProtocol(schemaTypeList, countTotalList)
|
||||||
val distinctIp: Array[String] = mergeDistinctIp(distCipRecent)
|
val distinctIp: Array[String] = mergeDistinctIp(distCipRecent)
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
package cn.ac.iie.service.update
|
//package cn.ac.iie.service.update
|
||||||
|
//
|
||||||
import java.util
|
//import java.util
|
||||||
import java.util.ArrayList
|
//import java.util.ArrayList
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
//import java.util.concurrent.ConcurrentHashMap
|
||||||
|
//
|
||||||
import cn.ac.iie.dao.BaseArangoData
|
//import cn.ac.iie.dao.BaseArangoData
|
||||||
import cn.ac.iie.dao.BaseArangoData._
|
//import cn.ac.iie.dao.BaseArangoData._
|
||||||
import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
//import com.arangodb.entity.{BaseDocument, BaseEdgeDocument}
|
||||||
|
//
|
||||||
import scala.collection.mutable.WrappedArray.ofRef
|
//import scala.collection.mutable.WrappedArray.ofRef
|
||||||
|
//
|
||||||
object UpdateDocumentTest {
|
//object UpdateDocumentTest {
|
||||||
def main(args: Array[String]): Unit = {
|
// def main(args: Array[String]): Unit = {
|
||||||
val baseArangoData = new BaseArangoData()
|
// val baseArangoData = new BaseArangoData()
|
||||||
baseArangoData.readHistoryData("R_LOCATE_FQDN2IP", historyRelationFqdnAddressIpMap, classOf[BaseEdgeDocument])
|
// baseArangoData.readHistoryData("R_LOCATE_FQDN2IP", historyRelationFqdnAddressIpMap, classOf[BaseEdgeDocument])
|
||||||
|
//
|
||||||
val value = BaseArangoData.historyRelationFqdnAddressIpMap.keys()
|
// val value = BaseArangoData.historyRelationFqdnAddressIpMap.keys()
|
||||||
while (value.hasMoreElements) {
|
// while (value.hasMoreElements) {
|
||||||
val integer: Integer = value.nextElement()
|
// val integer: Integer = value.nextElement()
|
||||||
val map: ConcurrentHashMap[String, BaseEdgeDocument] = historyRelationFqdnAddressIpMap.get(integer)
|
// val map: ConcurrentHashMap[String, BaseEdgeDocument] = historyRelationFqdnAddressIpMap.get(integer)
|
||||||
val unit = map.keys()
|
// val unit = map.keys()
|
||||||
while (unit.hasMoreElements) {
|
// while (unit.hasMoreElements) {
|
||||||
val key = unit.nextElement()
|
// val key = unit.nextElement()
|
||||||
val edgeDocument = map.get(key)
|
// val edgeDocument = map.get(key)
|
||||||
// val longs = edgeDocument.getAttribute("DNS_CNT_RECENT").asInstanceOf[util.ArrayList[Long]]
|
// // 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[util.ArrayList[String]]
|
||||||
val strings = edgeDocument.getAttribute("DIST_CIP").asInstanceOf[Array[String]]
|
// val strings = edgeDocument.getAttribute("DIST_CIP").asInstanceOf[Array[String]]
|
||||||
val longs = edgeDocument.getAttribute("DNS_CNT_RECENT").asInstanceOf[Array[java.lang.Long]]
|
// val longs = edgeDocument.getAttribute("DNS_CNT_RECENT").asInstanceOf[Array[java.lang.Long]]
|
||||||
println(longs.toString + "---" + strings.toString)
|
// println(longs.toString + "---" + strings.toString)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user