Authored by FengRuwei

javapp 搜索

... ... @@ -2,6 +2,7 @@ package com.monitor.influxdb.mapper;
import com.alibaba.fastjson.JSONObject;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import java.util.List;
... ... @@ -19,9 +20,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, JavaApiHisReq req );
public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd);
public int countJavaApiStaticHis(String influxDBName, JavaApiHisReq req );
}
... ...
... ... @@ -7,6 +7,7 @@ import com.monitor.common.util.QueryResultUtil;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
... ... @@ -137,13 +138,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
}
@Override
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,JavaApiHisReq req ) {
int api_id=req.getApiId();
int mobj_id=req.getMobjId();
String timeStart=DateFormatUtil.influxDBTimeFormat(req.getStartTime());
String timeEnd=DateFormatUtil.influxDBTimeFormat(req.getEndTime());
int limitCount=req.getPageSize();
int offsetCount=req.getCurrentPage()*req.getPageSize();
String mIp=req.getMIp();
int status=req.getStatus();
String sql = "select * 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)
//有mid 直接使用mid检索 不考虑ip
if (mobj_id > 0) {
sql += " and mobj_id= " + mobj_id;
}else if(mIp!=null&&!mIp.equals("")){
sql += " and mobj_ip= '" + mIp+"' ";
}
//仅exception
if(status==0){
sql += " and is_exception= true ";
}else if(status==1){
sql += " and is_exception= false ";
}
sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount;
log.info("sql:{}", sql);
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
... ... @@ -206,13 +228,34 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
return list;
}
public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd) {
public int countJavaApiStaticHis(String influxDBName, JavaApiHisReq req) {
int api_id=req.getApiId();
int mobj_id=req.getMobjId();
String timeStart=DateFormatUtil.influxDBTimeFormat(req.getStartTime());
String timeEnd=DateFormatUtil.influxDBTimeFormat(req.getEndTime());
int limitCount=req.getPageSize();
int offsetCount=req.getCurrentPage()*req.getPageSize();
String mIp=req.getMIp();
int status=req.getStatus();
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)
//有mid 直接使用mid检索 不考虑ip
if (mobj_id > 0) {
sql += " and mobj_id= " + mobj_id;
}else if(mIp!=null&&!mIp.equals("")){
sql += " and mobj_ip= '" + mIp+"' ";
}
//仅exception
if(status==0){
sql += " and is_exception= true ";
}else if(status==1){
sql += " and is_exception= false ";
}
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
... ...
... ... @@ -3,6 +3,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.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.JavaApiStatusRep;
... ... @@ -23,9 +24,9 @@ import java.util.List;
*/
@Controller
@RequestMapping("javaApiStatus")
public class JavaAppInfoCtrl {
public class JavaAppInfoStaticsCtrl {
Logger log = LoggerFactory.getLogger(JavaAppInfoCtrl.class);
Logger log = LoggerFactory.getLogger(JavaAppInfoStaticsCtrl.class);
@Autowired
IJavaApiStatusService javaApiStatusService;
... ... @@ -98,34 +99,29 @@ public class JavaAppInfoCtrl {
@RequestMapping("/queryhis")
@ResponseBody
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,
@RequestParam(required = false, defaultValue = "10") int pageSize) {
if (start_time == 0) {
return getJavaApiStatusHisLatest(api_id, mobj_id);
public BaseResponse getJavaApiStatusHis(@RequestBody JavaApiHisReq req) {
if (req.getStartTime() == 0) {
return getJavaApiStatusHisLatest(req.getApiId(), req.getMobjId());
}
if (end_time == 0)
end_time = System.currentTimeMillis();
if (req.getEndTime() == 0)
req.setEndTime( System.currentTimeMillis());
BaseResponse baseResponse = new BaseResponse();
PageResponse<JavaApiStatusRep> pageResponse = new PageResponse<JavaApiStatusRep>();
try {
int count = javaApiStatusService.countJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time);
int count = javaApiStatusService.countJavaApiStatusHisByTime(req);
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(api_id, mobj_id, start_time, end_time, page, pageSize);
List<JavaApiStatusRep> javaApiStatusRepList = javaApiStatusService.getJavaApiStatusHisByTime(req);
pageResponse.setRows(javaApiStatusRepList);
pageResponse.setCurrentPage(page);
pageResponse.setPageSize(pageSize);
pageResponse.setCurrentPage(req.getCurrentPage());
pageResponse.setPageSize(req.getPageSize());
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);
log.warn("queryhis failed req {}", req, e);
baseResponse.setCode(400);
baseResponse.setMessage(e.getMessage());
}
... ...
package com.monitor.javaserver.service;
import com.monitor.model.request.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
... ... @@ -17,9 +18,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,int pageSize);
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req);
public int countJavaApiStatusHisByTime(int api_id, int mobj_id, long start, long end);
public int countJavaApiStatusHisByTime(JavaApiHisReq req);
}
... ...
... ... @@ -5,6 +5,7 @@ import com.monitor.common.util.DateFormatUtil;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.service.IJavaApiStatusService;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -81,18 +82,21 @@ 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, 10);
JavaApiHisReq req=new JavaApiHisReq();
req.setPageSize(10);
req.setApiId(api_id);
req.setMobjId(mobj_id);
req.setStartTime(start);
req.setEndTime(end);
req.setCurrentPage(0);
return this.getJavaApiStatusHisByTime(req);
}
@Override
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);
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req) {
List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, api_id, mobj_id,
startTime, endTime, pageSize,
page * pageSize);
List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectJavaApiStaticHis(null, req);
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
for (JavaApiStaticsModel model : modelList) {
... ... @@ -121,12 +125,9 @@ 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);
public int countJavaApiStatusHisByTime(JavaApiHisReq req) {
int count = javaApiStaticsMapper.countJavaApiStaticHis(null, api_id, mobj_id, startTime, endTime);
int count = javaApiStaticsMapper.countJavaApiStaticHis(null, req);
return count;
}
... ...
package com.monitor.model.request;
import com.monitor.model.page.PageRequest;
import lombok.Data;
/**
* Created by fruwei on 2016/6/23.
*/
@Data
public class JavaApiHisReq extends PageRequest {
int apiId = 0;
int mobjId = 0;
long startTime = 0;
long endTime = 0;
String mIp = "";
int status = 2;
}
... ...
... ... @@ -139,22 +139,22 @@
from java_api_info
where
1=1
<if test="params.serviceType != null">
<if test="params.serviceType != null and params.serviceType != 0">
and service_type = #{params.serviceType,jdbcType=INTEGER}
</if>
<if test="params.apiName != null">
and api_name = #{params.apiName,jdbcType=VARCHAR}
<if test="params.apiName != null and params.apiName != ''">
and api_name like CONCAT('%',#{params.apiName,jdbcType=VARCHAR},'%' )
</if>
<if test="params.apiUrl != null">
and api_url = #{params.apiUrl,jdbcType=VARCHAR}
<if test="params.apiUrl != null and params.apiUrl != ''">
and api_url like CONCAT('%',#{params.apiUrl,jdbcType=VARCHAR},'%' )
</if>
<if test="params.apiData != null">
and api_data = #{params.apiData,jdbcType=VARCHAR}
</if>
<if test="params.apiToggle != null">
<if test="params.apiToggle != null ">
and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
</if>
<if test="params.apiReqMethod != null">
<if test="params.apiReqMethod != null and params.apiReqMethod !=2 ">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
<if test="params.apiWarnTrigger != null">
... ... @@ -168,14 +168,14 @@
from java_api_info
where
1=1
<if test="params.serviceType != null">
<if test="params.serviceType != null and params.serviceType != 0">
and service_type = #{params.serviceType,jdbcType=INTEGER}
</if>
<if test="params.apiName != null">
and api_name = #{params.apiName,jdbcType=VARCHAR}
<if test="params.apiName != null and params.apiName != ''">
and api_name like CONCAT('%',#{params.apiName,jdbcType=VARCHAR},'%' )
</if>
<if test="params.apiUrl != null">
and api_url = #{params.apiUrl,jdbcType=VARCHAR}
<if test="params.apiUrl != null and params.apiUrl != ''">
and api_url like CONCAT('%',#{params.apiUrl,jdbcType=VARCHAR},'%' )
</if>
<if test="params.apiData != null">
and api_data = #{params.apiData,jdbcType=VARCHAR}
... ... @@ -183,7 +183,7 @@
<if test="params.apiToggle != null">
and api_toggle = #{params.apiToggle,jdbcType=INTEGER}
</if>
<if test="params.apiReqMethod != null">
<if test="params.apiReqMethod != null and params.apiReqMethod !=2 ">
and api_req_method = #{params.apiReqMethod,jdbcType=INTEGER}
</if>
<if test="params.apiWarnTrigger != null">
... ...