提交 a52815cb 编写于 作者: Y youyong205

Merge pull request #407 from youyong205/master

fix bug
......@@ -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;
}
}
......@@ -270,7 +270,7 @@ public class MetricGraphCreator extends AbstractGraphCreator {
if (containMetric(alertKeys, metricId)) {
chart.setHtmlTitle("<span style='color:red'>" + title + "<br><small>" + contactInfo + "</small></span>");
} else {
chart.setHtmlTitle(title + "<br><small>" + contactInfo + "</small>");
chart.setHtmlTitle(title);
}
}
}
......
......@@ -60,31 +60,31 @@ public class NetGraphBuilder {
String group = inter.getGroup();
MetricReport report = reports.get(group);
String domain = inter.getDomain();
String key = inter.getKey();
String prefix = inter.getKey();
updateInterface(inter, report, minute);
if (containsAlert(alertKeys, group, domain, key, "-flow-in")) {
if (containsAlert(alertKeys, group, domain, prefix, "-flow-in")) {
inter.setInstate(ERROR);
inState = ERROR;
}
if (containsAlert(alertKeys, group, domain, key, "-discard/error-indiscards")) {
if (containsAlert(alertKeys, group, domain, prefix, "-discard/error-indiscards")) {
inter.setInDiscardsState(ERROR);
inDiscardsState = ERROR;
}
if (containsAlert(alertKeys, group, domain, key, "-discard/error-inerrors")) {
if (containsAlert(alertKeys, group, domain, prefix, "-discard/error-inerrors")) {
inter.setInErrorsState(ERROR);
inErrorsState = ERROR;
}
if (containsAlert(alertKeys, group, domain, key, "-flow-out")) {
if (containsAlert(alertKeys, group, domain, prefix, "-flow-out")) {
inter.setOutstate(ERROR);
outState = ERROR;
}
if (containsAlert(alertKeys, group, domain, key, "-discard/error-outdiscards")) {
if (containsAlert(alertKeys, group, domain, prefix, "-discard/error-outdiscards")) {
inter.setOutDiscardsState(ERROR);
outDiscardsState = ERROR;
}
if (containsAlert(alertKeys, group, domain, key, "-discard/error-outerrors")) {
if (containsAlert(alertKeys, group, domain, prefix, "-discard/error-outerrors")) {
inter.setOutErrorsState(ERROR);
outErrorsState = ERROR;
}
......@@ -115,15 +115,14 @@ public class NetGraphBuilder {
}
}
private boolean containsAlert(List<AlertMetric> alertKeys, String group, String domain, String key, String suffix) {
String actualKey = domain + ":Metric:" + key + suffix;
private boolean containsAlert(List<AlertMetric> alertKeys, String group, String domain, String prefix, String suffix) {
String actualKey = domain + ":Metric:" + prefix + suffix;
for (AlertMetric metric : alertKeys) {
if (metric.getGroup().equals(group) && metric.getMetricId().equals(actualKey)) {
return true;
}
}
return false;
}
......
......@@ -49,8 +49,8 @@ public class AlertInfo implements Initializable {
private String m_metricId;
public AlertMetric(String group, String metricId) {
this.m_group = group;
this.m_metricId = metricId;
m_group = group;
m_metricId = metricId;
}
public String getGroup() {
......@@ -61,6 +61,25 @@ public class AlertInfo implements Initializable {
return m_metricId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((m_group == null) ? 0 : m_group.hashCode());
result = prime * result + ((m_metricId == null) ? 0 : m_metricId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
AlertMetric other = (AlertMetric) obj;
if (m_group.equals(other.getGroup()) && m_metricId.equals(other.getMetricId())) {
return true;
} else {
return false;
}
}
}
}
......@@ -5,7 +5,7 @@ import java.util.List;
import com.dianping.cat.Cat;
public class SmsSender extends BaseSender {
@Override
protected void sendLog(String title, String content, List<String> receivers) {
StringBuilder builder = new StringBuilder();
......
......@@ -34,7 +34,7 @@ public class AlertSummaryGenerator {
alert.setAlertTime(date);
alert.setContext(edge.getDes());
alert.setMetric(edge.getKey());
alert.setType("long call");
alert.setType("slow "+edge.getType());
alert.setDomain(edge.getSelf());
return alert;
......
......@@ -21,7 +21,7 @@ public class AlertSummaryVisitor extends BaseVisitor {
private List<Map<Object, Object>> m_alertList;
private DateFormat m_fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
private DateFormat m_fmt = new SimpleDateFormat("HH:mm:ss");
public Map<Object, Object> getResult() {
return m_result;
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册