Authored by jack.xue

Merge branch 'master' of http://git.yoho.cn/ops/monitor-service

... ... @@ -159,18 +159,40 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end")));
long costTime = (endTime - startTime);
String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
javaApiStaticsModel.setStartTime(DateFormatUtil.parseLongToTimeStr(startTime));
javaApiStaticsModel.setEndTime(DateFormatUtil.parseLongToTimeStr(endTime));
javaApiStaticsModel.setCostTime((int) costTime);
int a_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue();
int m_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("mobj_id"))).intValue();
javaApiStaticsModel.setServiceId(a_id);
javaApiStaticsModel.setMObjectId(m_id);
String m_ip = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_ip"));
String m_port = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_port"));
String m_name = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_name"));
javaApiStaticsModel.setMIp(m_ip);
javaApiStaticsModel.setMPort(m_port);
javaApiStaticsModel.setMName(m_name);
String time = (String) series.getValues().get(0).get(series.getColumns().indexOf("time"));
javaApiStaticsModel.setTime(DateFormatUtil.displayFormat(time));
if (is_exception == true) {
javaApiStaticsModel.setStatus(0);
String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
javaApiStaticsModel.setException(exception);
} else
} else {
javaApiStaticsModel.setStatus(1);
String response = (String) series.getValues().get(0).get(series.getColumns().indexOf("response"));
javaApiStaticsModel.setResponse(response);
}
list.add(javaApiStaticsModel);
}
return list;
... ...
... ... @@ -54,7 +54,7 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
command.append("where hostIp='"+hostIp+"'");
}
String time=(String)page.getParams().get("time");
if(StringUtils.isNotBlank(hostIp)){
if(StringUtils.isNotBlank(time)){
if(flag==1){
command.append(" and time>'"+time+"'");
}else{
... ... @@ -62,11 +62,11 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
}
}
String isLive=(String)page.getParams().get("isLive");
if(StringUtils.isNotBlank(hostIp)){
if(StringUtils.isNotBlank(isLive)){
if(flag==1){
command.append(" and time="+isLive);
command.append(" and isLive="+isLive);
}else{
command.append("where and time="+isLive);
command.append("where and isLive="+isLive);
}
}
InfluxDBModel influxDBModel= inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM);
... ... @@ -77,7 +77,7 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
@Override
public List<List<Object>> selectZkInfosByCodition(PageBean page) {
StringBuffer command=new StringBuffer();
command.append("SELECT hostIp,isLive,time FROM "+InfluxDBContants.ZOOKEEPER_ALARM) ;
command.append("SELECT hostIp,isLive,time FROM " + InfluxDBContants.ZOOKEEPER_ALARM) ;
String hostIp=(String)page.getParams().get("hostIP");
int flag=0;
if(StringUtils.isNotBlank(hostIp)){
... ... @@ -85,7 +85,7 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
command.append("where hostIp='"+hostIp+"'");
}
String time=(String)page.getParams().get("time");
if(StringUtils.isNotBlank(hostIp)){
if(StringUtils.isNotBlank(time)){
if(flag==1){
command.append(" and time>'"+time+"'");
}else{
... ... @@ -93,11 +93,11 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
}
}
String isLive=(String)page.getParams().get("isLive");
if(StringUtils.isNotBlank(hostIp)){
if(StringUtils.isNotBlank(isLive)){
if(flag==1){
command.append(" and time="+isLive);
command.append(" and isLive="+isLive);
}else{
command.append("where and time="+isLive);
command.append("where and isLive="+isLive);
}
}
command.append(" ORDER BY time DESC LIMIT " + page.getPageSize() + " OFFSET " + page.getStartIndex());
... ...
... ... @@ -5,6 +5,8 @@ import com.monitor.javaserver.service.IJavaApiStatusService;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiStatusRep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -22,6 +24,7 @@ import java.util.List;
@RequestMapping("javaApiStatus")
public class JavaAppInfoCtrl {
Logger log = LoggerFactory.getLogger(JavaAppInfoCtrl.class);
@Autowired
IJavaApiStatusService javaApiStatusService;
... ... @@ -34,6 +37,7 @@ public class JavaAppInfoCtrl {
JavaApiStatusRep javaApiStatusRep = javaApiStatusService.getJavaApiStatus(req);
rep.setData(javaApiStatusRep);
} catch (Exception e) {
log.warn("queryOne failed req :{} ", req, e);
rep.setCode(400);
rep.setMessage(e.getMessage());
}
... ... @@ -51,6 +55,7 @@ public class JavaAppInfoCtrl {
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusList(list);
rep.setData(javaApiStatusRepList);
} catch (Exception e) {
log.warn("query failed req :{} ", req, e);
rep.setCode(400);
rep.setMessage(e.getMessage());
}
... ... @@ -81,6 +86,7 @@ public class JavaAppInfoCtrl {
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisLatest(api_id, mobj_id);
rep.setData(javaApiStatusRepList);
} catch (Exception e) {
log.warn("querylatesthis failed apiId :{} mobjId:{}", api_id, mobj_id, e);
rep.setCode(400);
rep.setMessage(e.getMessage());
}
... ... @@ -89,8 +95,27 @@ public class JavaAppInfoCtrl {
@RequestMapping("/queryhis")
@ResponseBody
public BaseResponse getJavaApiStatusHis() {
public BaseResponse getJavaApiStatusHis(@RequestParam(required = false, defaultValue = "0") int api_id,
@RequestParam(required = false, defaultValue = "0") int mobj_id,
@RequestParam(required = false, defaultValue = "0") long start_time,
@RequestParam(required = false, defaultValue = "0") long end_time,
@RequestParam(required = false, defaultValue = "0") int page) {
BaseResponse rep = new BaseResponse();
if (start_time == 0) {
return getJavaApiStatusHisLatest(api_id, mobj_id);
}
if (end_time == 0)
end_time = System.currentTimeMillis();
try {
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page);
rep.setData(javaApiStatusRepList);
} catch (Exception e) {
log.warn("queryhis failed apiId :{} mobjId:{} start_time:{} endTime:{} ,page:{} ", api_id, mobj_id, start_time, end_time, page, e);
rep.setCode(400);
rep.setMessage(e.getMessage());
}
return rep;
}
... ...
... ... @@ -95,18 +95,23 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
page * PaginationContants.PAGE_COMMON_OFFSET_PERIOD);
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
for (JavaApiStaticsModel req : modelList) {
for (JavaApiStaticsModel model : modelList) {
JavaApiStatusRep rep = new JavaApiStatusRep();
rep.setServiceId(req.getServiceId());
rep.setMObjectId(req.getMObjectId());
rep.setStatus(req.getStatus());
rep.setServiceId(model.getServiceId());
rep.setMObjectId(model.getMObjectId());
rep.setStatus(model.getStatus());
rep.setEndTime(req.getEndTime());
rep.setStartTime(req.getStartTime());
rep.setCostTime(req.getCostTime());
rep.setException(req.getException());
rep.setEndTime(model.getEndTime());
rep.setStartTime(model.getStartTime());
rep.setCostTime(model.getCostTime());
rep.setException(model.getException());
rep.setResponse(model.getResponse());
rep.setMPort(model.getMPort());
rep.setMIp(model.getMIp());
rep.setMName(model.getMName());
rep.setTime(model.getTime());
repList.add(rep);
}
... ...
... ... @@ -13,10 +13,18 @@ public class JavaApiStaticsModel {
private Integer mObjectId;
private Integer status;
private String exception;
private String response;
private String startTime;
private String endTime;
private int costTime;
private String mIp;
private String mPort;
private String mName;
private String time;
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
... ...
... ... @@ -13,4 +13,6 @@ public class ZkInfoReq extends PageRequest {
private String recordTime;
private int isLive;
}
... ...
... ... @@ -13,8 +13,13 @@ public class JavaApiStatusRep {
private Integer mObjectId;
private Integer status;
private String exception;
private String response;
private String startTime;
private String endTime;
private int costTime;
private String mIp;
private String mPort;
private String mName;
private String time;
}
... ...
... ... @@ -8,3 +8,7 @@ influxdb.pwd=Yoho_9646;root
influxdb.connect.timeout=15;15
influxdb.read.timeout=40;40
influxdb.write.timeout=20;20
aws.influxdb.url=http://123.206.79.151:8086
aws.influxdb.user=root
aws.influxdb.pwd=root
\ No newline at end of file
... ...