提交 1f3f3579 编写于 作者: Y youyong205

review code

上级 6993a972
......@@ -40,6 +40,7 @@ public class BucketHandler implements Task {
int minute = (int) (m_startTime % ONE_DAY / ONE_MINUTE);
Date period = new Date(m_startTime - minute * ONE_MINUTE);
List<AppDataCommand> appDataCommands = new ArrayList<AppDataCommand>();
int batchSize = 100;
for (Entry<Integer, HashMap<String, AppData>> outerEntry : m_mergedData.entrySet()) {
for (Entry<String, AppData> entry : outerEntry.getValue().entrySet()) {
......@@ -62,9 +63,17 @@ public class BucketHandler implements Task {
proto.setResponsePackage(appData.getResponseByte());
proto.setCreationDate(new Date());
appDataCommands.add(proto);
if (appDataCommands.size() >= batchSize) {
batchInsert(appDataCommands);
appDataCommands = new ArrayList<AppDataCommand>();
}
}
}
batchInsert(appDataCommands);
}
private void batchInsert(List<AppDataCommand> appDataCommands) {
try {
m_appDataService.insert((AppDataCommand[]) appDataCommands.toArray());
} catch (Exception e) {
......
......@@ -65,76 +65,72 @@ public class Handler implements PageHandler<Context>, LogEnabled {
String userIp = m_util.getRemoteIp(request);
String version = payload.getVersion();
if (version.equals("1")) {
processVersion1(payload, request, userIp);
} else if (version.equals("2")) {
processVersion2(payload, request, userIp);
if (userIp != null) {
if (version.equals("1")) {
processVersion1(payload, request, userIp);
} else if (version.equals("2")) {
processVersion2(payload, request, userIp);
}
} else {
m_logger.info("unknown http request, x-forwarded-for:" + request.getHeader("x-forwarded-for"));
}
response.getWriter().write("OK");
}
private void processVersion1(Payload payload, HttpServletRequest request, String userIp) {
if (userIp != null) {
try {
String content = payload.getContent();
String[] lines = content.split("\n");
for (String line : lines) {
String[] tabs = line.split("\t");
// timstampTABtargetUrlTABdurationTABhttpCodeTABerrorCodeENTER
if (tabs.length == 5 && validate(tabs[3], tabs[4])) {
MonitorEntity entity = new MonitorEntity();
String httpStatus = tabs[3];
String errorCode = tabs[4];
if (StringUtils.isEmpty(errorCode)) {
errorCode = Constrants.NOT_SET;
}
if (StringUtils.isEmpty(httpStatus)) {
httpStatus = Constrants.NOT_SET;
}
entity.setTimestamp(Long.parseLong(tabs[0]));
entity.setTargetUrl(tabs[1]);
entity.setDuration(Double.parseDouble(tabs[2]));
entity.setHttpStatus(httpStatus);
entity.setErrorCode(errorCode);
entity.setIp(userIp);
if (payload.getVersion().equals("1")) {
entity.setCount(10);
}
m_manager.offer(entity);
try {
String content = payload.getContent();
String[] lines = content.split("\n");
for (String line : lines) {
String[] tabs = line.split("\t");
// timstampTABtargetUrlTABdurationTABhttpCodeTABerrorCodeENTER
if (tabs.length == 5 && validate(tabs[3], tabs[4])) {
MonitorEntity entity = new MonitorEntity();
String httpStatus = tabs[3];
String errorCode = tabs[4];
if (StringUtils.isEmpty(errorCode)) {
errorCode = Constrants.NOT_SET;
}
if (StringUtils.isEmpty(httpStatus)) {
httpStatus = Constrants.NOT_SET;
}
entity.setTimestamp(Long.parseLong(tabs[0]));
entity.setTargetUrl(tabs[1]);
entity.setDuration(Double.parseDouble(tabs[2]));
entity.setHttpStatus(httpStatus);
entity.setErrorCode(errorCode);
entity.setIp(userIp);
if (payload.getVersion().equals("1")) {
entity.setCount(10);
}
m_manager.offer(entity);
}
} catch (Exception e) {
m_logger.error(e.getMessage(), e);
}
} else {
m_logger.info("unknown http request, x-forwarded-for:" + request.getHeader("x-forwarded-for"));
} catch (Exception e) {
m_logger.error(e.getMessage(), e);
}
}
private void processVersion2(Payload payload, HttpServletRequest request, String userIp) {
if (userIp != null) {
String content = payload.getContent();
String records[] = content.split("\n");
IpInfo ipInfo = m_ipService.findIpInfoByString(userIp);
if (ipInfo != null) {
String province = ipInfo.getProvince();
String operatorStr = ipInfo.getChannel();
Integer cityId = m_appConfigManager.getCities().get(province);
Integer operatorId = m_appConfigManager.getOperators().get(operatorStr);
if (cityId != null && operatorId != null) {
for (String record : records) {
processOneRecord(cityId, operatorId, record);
}
String content = payload.getContent();
String records[] = content.split("\n");
IpInfo ipInfo = m_ipService.findIpInfoByString(userIp);
if (ipInfo != null) {
String province = ipInfo.getProvince();
String operatorStr = ipInfo.getChannel();
Integer cityId = m_appConfigManager.getCities().get(province);
Integer operatorId = m_appConfigManager.getOperators().get(operatorStr);
if (cityId != null && operatorId != null) {
for (String record : records) {
processOneRecord(cityId, operatorId, record);
}
}
} else {
m_logger.info("unknown http request, x-forwarded-for:" + request.getHeader("x-forwarded-for"));
}
}
......
......@@ -26,20 +26,16 @@ public class AppDataService {
@Inject
private AppConfigManager m_appConfigManager;
public static final String SUCCESS= "success";
public static final String SUCCESS = "success";
public static final String REQUEST = "request";
public static final String DELAY = "delay";
public void insert(AppDataCommand proto) throws DalException {
m_dao.insert(proto);
}
public void insert(AppDataCommand[] proto) throws DalException {
m_dao.insert(proto);
}
public double[] queryValue(QueryEntity entity, String type) {
int commandId = entity.getCommand();
Date period = entity.getDate();
......@@ -71,11 +67,11 @@ public class AppDataService {
Pair<Integer, Map<Integer, List<AppDataCommand>>> dataPair = convert2AppDataCommandMap(datas);
return queryDelayAvg(dataPair);
} else {
throw new RuntimeException("unexpected query type, type:" + type);
}
} catch (Exception e) {
Cat.logError(e);
e.printStackTrace();
}
return null;
}
......@@ -170,4 +166,5 @@ public class AppDataService {
}
return value;
}
}
......@@ -30,7 +30,6 @@ public class AppGraphCreator extends AbstractGraphCreator {
double[] values2 = prepareQueryData(queryEntity2, type);
dataList.add(values2);
}
return buildChartData(dataList, type);
}
......@@ -48,18 +47,18 @@ public class AppGraphCreator extends AbstractGraphCreator {
} else if (AppDataService.DELAY.equals(type)) {
return "成功延时(ms)";
} else {
return "";
throw new RuntimeException("unexpected query type, type:" + type);
}
}
public LineChart buildChartData(final LinkedList<double[]> dataList, String type) {
LineChart lineChart = new LineChart();
lineChart.setId("app");
lineChart.setHtmlTitle(queryType(type));
int i = 1;
int length = dataList.size();
for (double[] data : dataList) {
for (int i = 0; i < length; i++) {
double[] data = dataList.get(i);
lineChart.add("查询" + i++, data);
}
return lineChart;
......@@ -76,7 +75,6 @@ public class AppGraphCreator extends AbstractGraphCreator {
time += step * TimeUtil.ONE_MINUTE;
map.put(time, data[i]);
}
return map;
}
}
......@@ -21,8 +21,6 @@ public class NavigationBar {
public Page[] getVisiblePages() {
return new Page[] {
ReportPage.HOME,
ReportPage.METRIC,
ReportPage.USERMONITOR,
......
......@@ -77,7 +77,7 @@ function TabManager() {
};
this.headersWillBeSent = function(tabId, headers) {
headers.push({name: "X-CAT-TRACE-MODE", value: "1"});
headers.push({name: "X-CAT-TRACE-MODE", value: "true"});
return {requestHeaders: headers};
};
......@@ -110,7 +110,6 @@ function TabManager() {
console.debug("show pageAction for " + tabId);
chrome.pageAction.show(tabId);
};
}
var tabMgr = new TabManager();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册