Authored by FengRuwei

根据javaapi id查询详细信息

... ... @@ -6,6 +6,7 @@ import com.monitor.cmdb.service.IJavaApiInfoService;
import com.monitor.cmdb.service.impl.JavaApiInfoService;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiDetails;
import com.monitor.model.response.PageResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -65,4 +66,22 @@ public class JavaApiInfoCtrl {
}
@RequestMapping("/apiDetails")
@ResponseBody
public BaseResponse<JavaApiDetails> getJavaApiInfoDetails(@RequestParam(value = "id", required = true) Integer id) throws Exception {
log.info("delMechineInfo with param is {}", id);
BaseResponse baseResponse = new BaseResponse();
try {
JavaApiDetails javaApiDetails = javaApiInfoService.getJavaApiDetails(id);
baseResponse.setData(javaApiDetails);
} catch (Exception e) {
baseResponse.setCode(400);
baseResponse.setMessage(e.getMessage());
}
return baseResponse;
}
}
... ...
... ... @@ -429,20 +429,14 @@ public class MObjectInfoCtrl {
@RequestMapping(value = "/javaapi")
@ResponseBody
public BaseResponse queryJavaApiMobject() {
List<TypeInfo> allTypeInfo = null;
BaseResponse response = new BaseResponse();
try {
TypeInfo typeInfo = typeInfoService.queryTypeInfoByName(TypeInfoCtrl.TYPE_JAVA_APP);
if (typeInfo == null) {
return response;
}
allTypeInfo = typeInfoService.queryChildTypesInfo(typeInfo.getTypeId());
if (null == allTypeInfo) {
return response;
}
... ... @@ -450,7 +444,6 @@ public class MObjectInfoCtrl {
for (TypeInfo type : allTypeInfo) {
ids.add(type.getTypeId());
}
List<MObjectInfo> javaApps = mobjectService.queryMObjectsInfoByTypes(ids);
response.setData(javaApps);
... ... @@ -459,10 +452,30 @@ public class MObjectInfoCtrl {
response.setCode(400);
response.setMessage(e.getMessage());
}
return response;
}
/**
* 获取服务对象 根据类型
*
* @return
*/
@RequestMapping(value = "/mobjById")
@ResponseBody
public BaseResponse queryMobjectById(@RequestParam int typeId) {
List<TypeInfo> allTypeInfo = null;
BaseResponse response = new BaseResponse();
try {
List<MObjectInfo> javaApps = mobjectService.queryMObjectsInfoByType(typeId);
response.setData(javaApps);
} catch (Exception e) {
DEBUG.error("Failed to query all typeInfo, error: {}", e);
response.setCode(400);
response.setMessage(e.getMessage());
}
return response;
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.cmdb.service;
import com.model.JavaApiInfo;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiDetails;
import com.monitor.model.response.PageResponse;
import java.util.List;
... ... @@ -22,4 +23,7 @@ public interface IJavaApiInfoService {
public BaseResponse<Integer> delJavaApiInfo(int id);
PageResponse<JavaApiInfo> getJavaApiInfos(JavaApiInfoReq req);
JavaApiDetails getJavaApiDetails(int apiId);
}
... ...
package com.monitor.cmdb.service.impl;
import com.model.JavaApiInfo;
import com.model.MObjectInfo;
import com.monitor.cmdb.service.IJavaApiInfoService;
import com.monitor.model.domain.MObjectModel;
import com.monitor.model.domain.PageBean;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiDetails;
import com.monitor.model.response.PageResponse;
import com.monitor.mysql.mapper.JavaApiInfoMapper;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
... ... @@ -21,9 +26,13 @@ import java.util.List;
*/
@Service
public class JavaApiInfoService implements IJavaApiInfoService {
Logger log= LoggerFactory.getLogger(JavaApiInfoService.class);
Logger log = LoggerFactory.getLogger(JavaApiInfoService.class);
@Autowired
private JavaApiInfoMapper javaApiInfoMapper;
private JavaApiInfoMapper javaApiInfoMapper;
@Autowired
private MObjectInfoMapper mObjectInfoMapper;
@Override
public List<JavaApiInfo> queryJavaApiInfo() {
return javaApiInfoMapper.selectAllApi();
... ... @@ -36,18 +45,18 @@ public class JavaApiInfoService implements IJavaApiInfoService {
@Override
public BaseResponse<Integer> saveJavaApiInfo(JavaApiInfo javaApiInfo) {
int result=0;
if(javaApiInfo.getServiceId()!=null&&javaApiInfo.getServiceId()>0){
result=javaApiInfoMapper.updateByPrimaryKey(javaApiInfo);
}else{
result=javaApiInfoMapper.insert(javaApiInfo);
int result = 0;
if (javaApiInfo.getServiceId() != null && javaApiInfo.getServiceId() > 0) {
result = javaApiInfoMapper.updateByPrimaryKey(javaApiInfo);
} else {
result = javaApiInfoMapper.insert(javaApiInfo);
}
return new BaseResponse<Integer>(result);
}
@Override
public BaseResponse<Integer> delJavaApiInfo(int id) {
int result=javaApiInfoMapper.deleteByPrimaryKey(id);
int result = javaApiInfoMapper.deleteByPrimaryKey(id);
return new BaseResponse<Integer>(result);
}
... ... @@ -80,4 +89,33 @@ public class JavaApiInfoService implements IJavaApiInfoService {
return response;
}
public JavaApiDetails getJavaApiDetails(int apiId) {
if (apiId <= 0)
return null;
JavaApiInfo javaApiInfo = javaApiInfoMapper.selectByPrimaryKey(apiId);
if (javaApiInfo == null)
return null;
JavaApiDetails javaApiDetails = new JavaApiDetails();
BeanUtils.copyProperties(javaApiInfo, javaApiDetails);
int serviceType = javaApiDetails.getServiceType();
List<Integer> ids = new ArrayList<>(1);
ids.add(serviceType);
List<MObjectInfo> mObjectInfos = mObjectInfoMapper.selectMObjectsInfoByTypes(ids);
List<MObjectModel> mObjectModels = new ArrayList<>();
for (MObjectInfo mObjectInfo : mObjectInfos) {
MObjectModel mObjectModel = new MObjectModel();
BeanUtils.copyProperties(mObjectInfo, mObjectModel);
mObjectModels.add(mObjectModel);
}
javaApiDetails.setMObjectModels(mObjectModels);
return javaApiDetails;
}
}
... ...
... ... @@ -19,7 +19,9 @@ public interface IJavaApiStaticsMapper {
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query);
public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id,int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount);
public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd, int limitCount, int offsetCount);
public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd);
}
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper.impl;
import com.alibaba.fastjson.JSONObject;
import com.monitor.common.contants.InfluxDBContants;
import com.monitor.common.util.DateFormatUtil;
import com.monitor.common.util.QueryResultUtil;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
import com.monitor.model.domain.JavaApiStaticsModel;
... ... @@ -11,6 +12,8 @@ import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -26,6 +29,7 @@ import java.util.concurrent.TimeUnit;
@Component
public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
Logger log = LoggerFactory.getLogger(JavaApiStaticsMapper.class);
@Autowired
private InluxDBSingle inluxDBSingle;
... ... @@ -141,6 +145,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
if (mobj_id > 0)
sql += " and mobj_id= " + mobj_id;
sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount;
log.info("sql:{}", sql);
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query);
... ... @@ -150,13 +155,16 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
QueryResult.Result rel = result.getResults().get(0);
if (rel.getSeries() == null) {
return list;
}
QueryResult.Series series = rel.getSeries().get(0);
int size = series.getValues().size();
for (int i = 0; i < size; i++) {
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start")));
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end")));
Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception"));
long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start")));
long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end")));
long costTime = (endTime - startTime);
... ... @@ -166,31 +174,31 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
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();
int a_id = ((Double) series.getValues().get(i).get(series.getColumns().indexOf("api_id"))).intValue();
int m_id = ((Double) series.getValues().get(i).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"));
String m_ip = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_ip"));
String m_port = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_port"));
String m_name = (String) series.getValues().get(i).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"));
String time = (String) series.getValues().get(i).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"));
String exception = (String) series.getValues().get(i).get(series.getColumns().indexOf("exception"));
javaApiStaticsModel.setException(exception);
} else {
javaApiStaticsModel.setStatus(1);
String response = (String) series.getValues().get(0).get(series.getColumns().indexOf("response"));
String response = (String) series.getValues().get(i).get(series.getColumns().indexOf("response"));
javaApiStaticsModel.setResponse(response);
}
list.add(javaApiStaticsModel);
... ... @@ -198,5 +206,21 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
return list;
}
public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd) {
String sql = "select count(api_id) from " + InfluxDBContants.YOMO_TB_JAVAAPI;
sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' ";
if (api_id > 0)
sql += " and api_id= " + api_id;
if (mobj_id > 0)
sql += " and mobj_id= " + mobj_id;
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query);
return QueryResultUtil.getCount(result);
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.javaserver.ctrl;
import com.monitor.javaserver.client.JavaApiClient;
import com.monitor.javaserver.service.IJavaApiStatusService;
import com.monitor.model.page.PageResponse;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiStatusRep;
... ... @@ -91,6 +92,8 @@ public class JavaAppInfoCtrl {
rep.setMessage(e.getMessage());
}
return rep;
}
@RequestMapping("/queryhis")
... ... @@ -99,8 +102,8 @@ public class JavaAppInfoCtrl {
@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();
@RequestParam(required = false, defaultValue = "0") int page,
@RequestParam(required = false, defaultValue = "10") int pageSize) {
if (start_time == 0) {
return getJavaApiStatusHisLatest(api_id, mobj_id);
}
... ... @@ -108,16 +111,27 @@ public class JavaAppInfoCtrl {
if (end_time == 0)
end_time = System.currentTimeMillis();
BaseResponse baseResponse = new BaseResponse();
PageResponse<JavaApiStatusRep> pageResponse = new PageResponse<JavaApiStatusRep>();
try {
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page);
rep.setData(javaApiStatusRepList);
int count = javaApiStatusService.countJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time);
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page, pageSize);
pageResponse.setRows(javaApiStatusRepList);
pageResponse.setCurrentPage(page);
pageResponse.setPageSize(pageSize);
pageResponse.setTotal(count);
baseResponse.setData(pageResponse);
} 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());
baseResponse.setCode(400);
baseResponse.setMessage(e.getMessage());
}
return rep;
return baseResponse;
}
}
... ...
... ... @@ -17,6 +17,9 @@ public interface IJavaApiStatusService {
public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id);
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page);
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page,int pageSize);
public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end);
}
... ...
... ... @@ -81,18 +81,18 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
long start = System.currentTimeMillis();
long end = start;
start = start - 1000 * 60 * 60; //一小时之内
return this.getJavaApiStatusHisByTime(api_id, mobj_id, start, end, 0);
return this.getJavaApiStatusHisByTime(api_id, mobj_id, start, end, 0, 10);
}
@Override
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page) {
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end, int page, int pageSize) {
String startTime = DateFormatUtil.influxDBTimeFormat(start);
String endTime = DateFormatUtil.influxDBTimeFormat(end);
List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, api_id, mobj_id,
startTime, endTime, PaginationContants.PAGE_COMMON_OFFSET_PERIOD,
page * PaginationContants.PAGE_COMMON_OFFSET_PERIOD);
startTime, endTime, pageSize,
page * pageSize);
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
for (JavaApiStaticsModel model : modelList) {
... ... @@ -120,5 +120,15 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
}
@Override
public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end) {
String startTime = DateFormatUtil.influxDBTimeFormat(start);
String endTime = DateFormatUtil.influxDBTimeFormat(end);
int count = javaApiStaticsMapper.countJavaApiStaticHis(null, api_id, mobj_id, startTime, endTime);
return count;
}
}
... ...
package com.monitor.model.response;
import com.monitor.model.domain.MObjectModel;
import lombok.Data;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import java.util.List;
/**
* Created by fruwei on 2016/6/23.
*/
@Data
public class JavaApiDetails {
private Integer serviceId;
private Integer serviceType;
private String apiName;
private String apiUrl;
private String apiData;
private Integer apiToggle;
private Integer apiReqMethod;
private Integer apiWarnTrigger;
private List<MObjectModel> mObjectModels;
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
}
... ...
# ******************** influxdb common configs ********************
influxdb.num=2
influxdb.name=aws;qcloud
influxdb.ip=http://123.206.79.151:8086;http://10.66.4.25:8086
influxdb.ip=http://192.168.102.162:8086;http://10.66.4.25:8086
influxdb.user=root;root
influxdb.pwd=root;root
influxdb.connect.timeout=15;15
... ...