Skip to content

Commit

Permalink
Merge pull request #29 from xaecbd/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TrumanDu authored Aug 2, 2019
2 parents 262d6c2 + 4a115e0 commit 218b6dc
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 23 deletions.
4 changes: 2 additions & 2 deletions RCT-Analyze/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>RCT</artifactId>
<groupId>org.nesc.ecbd</groupId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>

<artifactId>RCT-Analyze</artifactId>
Expand All @@ -33,7 +33,7 @@
<dependency>
<groupId>org.nesc.ecbd</groupId>
<artifactId>RCT-Base</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</dependency>
</dependencies>

Expand Down
3 changes: 3 additions & 0 deletions RCT-Analyze/src/main/java/org/nesc/ecbd/cache/AppCache.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.nesc.ecbd.cache;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -13,5 +15,6 @@
public class AppCache {

public static Map<String, Set<String>> reportCacheMap = new ConcurrentHashMap<String, Set<String>>();
public static List<Long> redisUsedMems = new ArrayList<Long>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.nesc.ecbd.entity.AnalyzeStatus;
import org.nesc.ecbd.entity.ScheduleInfo;
import org.nesc.ecbd.service.RDBAnalyzeService;
import org.nesc.ecbd.service.ReportService;
import org.nesc.ecbd.worker.AnalyzerWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -27,6 +28,8 @@ public class RDBAnalyzeController {

@Autowired
RDBAnalyzeService rdbAnalyzeService;
@Autowired
ReportService reportService;

/**
* 初始化配置信息并进行检查
Expand Down Expand Up @@ -138,7 +141,7 @@ public String cancel() {

@RequestMapping(value="/report",method = RequestMethod.GET)
public String report() {
String report = JSONObject.toJSONString(AppCache.reportCacheMap);
String report = reportService.fixReportData();
return report;
}

Expand Down
77 changes: 77 additions & 0 deletions RCT-Analyze/src/main/java/org/nesc/ecbd/service/ReportService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.nesc.ecbd.service;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.nesc.ecbd.cache.AppCache;
import org.nesc.ecbd.entity.AnalyzerConstant;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

/**
* @author Truman.P.Du
* @date Aug 1, 2019 3:12:05 PM
* @version 1.0
*/
@Service
public class ReportService {

public String fixReportData() {
Map<String, Set<String>> reportCacheMap = AppCache.reportCacheMap;
long usedMem = 0l;
for (Long mem : AppCache.redisUsedMems) {
usedMem = mem + usedMem;
}
if (usedMem == 0) {
String report = JSONObject.toJSONString(reportCacheMap);
return report;
}
Set<String> dataTypeAnalyzeResult = AppCache.reportCacheMap.get(AnalyzerConstant.DATA_TYPE_ANALYZER + "");
Set<String> newDataTypeAnalyzeResult = new HashSet<>();
long estimateMem = 0l;
for (String str : dataTypeAnalyzeResult) {
JSONObject jsonObject = JSONObject.parseObject(str);
estimateMem = estimateMem + jsonObject.getLong("bytes");
}

BigDecimal precisionRate = new BigDecimal(usedMem).divide(new BigDecimal(estimateMem),4, BigDecimal.ROUND_HALF_UP);

for (String str : dataTypeAnalyzeResult) {
JSONObject jsonObject = JSONObject.parseObject(str);
long bytes = jsonObject.getLong("bytes");
long fixBytes = new BigDecimal(bytes).multiply(precisionRate).longValue();
jsonObject.put("bytes", fixBytes);
newDataTypeAnalyzeResult.add(jsonObject.toJSONString());
}
reportCacheMap.put(AnalyzerConstant.DATA_TYPE_ANALYZER + "", newDataTypeAnalyzeResult);


Set<String> prefixAnalyzeResult = AppCache.reportCacheMap.get(AnalyzerConstant.PREFIX_ANALYZER + "");
Set<String> newPrefixAnalyzeResult = new HashSet<>();
for (String str : prefixAnalyzeResult) {
JSONObject jsonObject = JSONObject.parseObject(str);
long bytes = jsonObject.getLong("bytes");
long fixBytes = new BigDecimal(bytes).multiply(precisionRate).longValue();
jsonObject.put("bytes", fixBytes);
newPrefixAnalyzeResult.add(jsonObject.toJSONString());
}
reportCacheMap.put(AnalyzerConstant.PREFIX_ANALYZER + "", newPrefixAnalyzeResult);

Set<String> topAnalyzeResult = AppCache.reportCacheMap.get(AnalyzerConstant.TOP_KEY_ANALYZER + "");
Set<String> newTopAnalyzeResult = new HashSet<>();
for (String str : topAnalyzeResult) {
JSONObject jsonObject = JSONObject.parseObject(str);
long bytes = jsonObject.getLong("bytes");
long fixBytes = new BigDecimal(bytes).multiply(precisionRate).longValue();
jsonObject.put("bytes", fixBytes);
newTopAnalyzeResult.add(jsonObject.toJSONString());
}
reportCacheMap.put(AnalyzerConstant.TOP_KEY_ANALYZER + "", newTopAnalyzeResult);

String report = JSONObject.toJSONString(reportCacheMap);
return report;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;

import org.nesc.ecbd.Analyzer;
import org.nesc.ecbd.cache.AppCache;
import org.nesc.ecbd.entity.AnalyzeStatus;
import org.nesc.ecbd.entity.RDBAnalyzeInfo;
import org.nesc.ecbd.service.rdbanalyze.AbstractAnalyzer;
Expand All @@ -23,7 +24,9 @@
import com.alibaba.fastjson.JSONObject;
import com.moilioncircle.redis.replicator.RedisReplicator;
import com.moilioncircle.redis.replicator.Replicator;
import com.moilioncircle.redis.replicator.rdb.AuxFieldListener;
import com.moilioncircle.redis.replicator.rdb.RdbListener;
import com.moilioncircle.redis.replicator.rdb.datatype.AuxField;
import com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair;

/**
Expand Down Expand Up @@ -103,6 +106,21 @@ public void execute(String rdbPath) {
analyzers.forEach(analyzer -> analyzer.init(params));

replicator = new RedisReplicator("redis://" + realRDBPath);

String used_mem_flag = "used-mem";
AppCache.redisUsedMems.clear();
replicator.addAuxFieldListener(new AuxFieldListener() {
@Override
public void handle(Replicator replicator, AuxField auxField) {
String auxKey = auxField.getAuxKey();
if (used_mem_flag.equalsIgnoreCase(auxKey)) {
Long used_mem = Long.parseLong(auxField.getAuxValue());
AppCache.redisUsedMems.add(used_mem);
}

}
});

replicator.addRdbListener(new RdbListener.Adaptor() {

@SuppressWarnings("unchecked")
Expand All @@ -118,7 +136,7 @@ public void handle(Replicator rep, KeyValuePair<?> kv) {
lasActive = System.currentTimeMillis();
Long bytesSizeEstimate = RedisObjectEstimate.getRedisObjectSize(kv, Analyzer.USE_Custom_Algo);
@SuppressWarnings("rawtypes")
RDBAnalyzeInfo rbdAnalyzeInfo = new RDBAnalyzeInfo(kv,bytesSizeEstimate);
RDBAnalyzeInfo rbdAnalyzeInfo = new RDBAnalyzeInfo(kv, bytesSizeEstimate);
for (AbstractAnalyzer analyzer : analyzers) {
analyzer.execute(rbdAnalyzeInfo);
}
Expand All @@ -131,6 +149,7 @@ public void handle(Replicator rep, KeyValuePair<?> kv) {
}

});

replicator.open();
String ending = AnalyzeStatus.CANCELED.equals(status) ? " Canceled" : " Done";

Expand Down
2 changes: 1 addition & 1 deletion RCT-Base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>RCT</artifactId>
<groupId>org.nesc.ecbd</groupId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>

<artifactId>RCT-Base</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions RCT-Dashboard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>RCT</artifactId>
<groupId>org.nesc.ecbd</groupId>
<version>2.1.1</version>
<version>2.1.2</version>
</parent>

<artifactId>RCT-Dashboard</artifactId>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>org.nesc.ecbd</groupId>
<artifactId>RCT-Base</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,24 @@ export default class PrefixTTLTable extends Component {
}
onSort(value, order) {
let dataSource = [];
if ((typeof value) !== 'number') {
dataSource = this.state.totalData.sort((a, b) => {
if (order === 'asc') {
return a[value].localeCompare(b[value]);
} else if (order === 'desc') {
return b[value].localeCompare(a[value]);
}
});
} else {
dataSource = this.state.totalData.sort((a, b) => {
if (order === 'asc') {
return a[value] - b[value];
} else if (order === 'desc') {
return b[value] - a[value];
}
});
if(value === 'TTL' || value==='noTTL'){
dataSource = this.state.totalData.sort((a, b) => {
if (order === 'asc') {
return a[value] - b[value];
} else if (order === 'desc') {
return b[value] - a[value];
}
});
}else{
dataSource = this.state.totalData.sort((a, b) => {
if (order === 'asc') {
return a[value].localeCompare(b[value]);
} else if (order === 'desc') {
return b[value].localeCompare(a[value]);
}
});
}

this.setState({ dataSource });
this.getPageData(dataSource);
}
Expand Down

0 comments on commit 218b6dc

Please sign in to comment.