Authored by zhengyouwei

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

package com.monitor.common.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by fruwei on 2016/7/26.
*/
public class DateTimeUtil {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
;
public static String unix2time(long unixtime) {
return sdf.format(new Date(unixtime));
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.model.MObjectInfo;
import com.monitor.javaserver.common.JavaApiStatics;
import com.monitor.javaserver.handle.IJavaApiHadnler;
import com.monitor.mysql.mapper.JavaApiInfoStaticsMapper;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -25,15 +26,17 @@ public class StaticsJavaApi2MysqlHandler extends IJavaApiHadnler {
MObjectDetails mObjectInfo = javaApiStatics.getMObjectDetails();
javaApiInfoStatics.setApiId(javaApiInfo.getServiceId());
javaApiInfoStatics.setMobjId(mObjectInfo.getMoId());
javaApiInfoStatics.setStartTime(javaApiStatics.getStartTime());
javaApiInfoStatics.setEndTime(javaApiStatics.getEndTime());
if (javaApiStatics.isHasException() == true) {
javaApiInfoStatics.setIsException((byte) 1);
if (javaApiStatics.getException() != null) {
javaApiInfoStatics.setException(javaApiStatics.getException().toString());
javaApiInfoStatics.setException(ExceptionUtils.getStackTrace(javaApiStatics.getException()));
}
} else {
// javaApiInfoStatics.setIsException((byte) 0);
return; //目前只记录错误的
javaApiInfoStatics.setIsException((byte) 0);
javaApiInfoStatics.setException("");
}
mapper.insert(javaApiInfoStatics);
... ...
package com.monitor.javaserver.service.impl;
import com.model.JavaApiInfoStatics;
import com.monitor.common.util.DateTimeUtil;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.common.JavaApiStatus;
import com.monitor.javaserver.service.IJavaApiStatusService;
... ... @@ -8,6 +10,7 @@ import com.monitor.model.request.JavaApiHisReq;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStaticsRep;
import com.monitor.model.response.JavaApiStatusRep;
import com.monitor.mysql.mapper.JavaApiInfoStaticsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -27,6 +30,8 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
@Autowired
JavaApiStatus javaApiStatus;
@Autowired
JavaApiInfoStaticsMapper mysqlJavaApiStaticsMapper;
@Override
public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) {
... ... @@ -49,20 +54,21 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, reqList);
// List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, reqList);
for (JavaApiStaticsModel req : modelList) {
JavaApiStatusRep rep = new JavaApiStatusRep();
rep.setServiceId(req.getServiceId());
rep.setMObjectId(req.getMObjectId());
rep.setStatus(req.getStatus());
List<JavaApiInfoStatics> modelList = mysqlJavaApiStaticsMapper.selectJavaApiStaticsByIds(reqList);
rep.setEndTime(req.getEndTime());
rep.setStartTime(req.getStartTime());
rep.setCostTime(req.getCostTime());
rep.setException(req.getException());
for (JavaApiInfoStatics req : modelList) {
JavaApiStatusRep rep = new JavaApiStatusRep();
rep.setServiceId(req.getApiId());
rep.setMObjectId(req.getMobjId());
rep.setStatus(req.getIsException() == 1 ? 0 : 1);
rep.setEndTime(DateTimeUtil.unix2time(req.getEndTime()));
rep.setStartTime(DateTimeUtil.unix2time(req.getStartTime()));
rep.setCostTime((int) (req.getEndTime() - req.getStartTime()));
rep.setException(req.getException());
repList.add(rep);
}
... ... @@ -138,7 +144,7 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
@Override
public List<JavaApiStaticsRep> getAllJavaApiStatus() {
return javaApiStatus.getStatusList();
return javaApiStatus.getStatusList();
}
... ...
... ... @@ -9,6 +9,11 @@ public class JavaApiInfoStatics {
private String exception;
private long startTime;
private long endTime;
public Integer getApiId() {
return apiId;
}
... ... @@ -40,4 +45,20 @@ public class JavaApiInfoStatics {
public void setException(String exception) {
this.exception = exception == null ? null : exception.trim();
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,9 @@ package com.monitor.mysql.mapper;
import com.model.JavaApiInfoStatics;
import com.monitor.model.request.JavaApiStatusReq;
import java.util.List;
public interface JavaApiInfoStaticsMapper {
int insert(JavaApiInfoStatics record);
... ... @@ -9,4 +12,7 @@ public interface JavaApiInfoStaticsMapper {
int insertSelective(JavaApiInfoStatics record);
void deleteAll();
List<JavaApiInfoStatics> selectJavaApiStaticsByIds(List<JavaApiStatusReq> list);
}
\ No newline at end of file
... ...
... ... @@ -6,12 +6,13 @@
<result column="mobj_id" property="mobjId" jdbcType="INTEGER"/>
<result column="is_exception" property="isException" jdbcType="TINYINT"/>
<result column="exception" property="exception" jdbcType="VARCHAR"/>
<result column="start_time" property="startTime" jdbcType="BIGINT"/>
<result column="end_time" property="endTime" jdbcType="BIGINT"/>
</resultMap>
<insert id="insert" parameterType="com.model.JavaApiInfoStatics">
insert into java_api_info_statics (api_id, mobj_id, is_exception,
exception)
insert into java_api_info_statics (api_id, mobj_id, is_exception, exception,start_time,end_time)
values (#{apiId,jdbcType=INTEGER}, #{mobjId,jdbcType=INTEGER}, #{isException,jdbcType=TINYINT},
#{exception,jdbcType=VARCHAR})
#{exception,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.model.JavaApiInfoStatics">
insert into java_api_info_statics
... ... @@ -47,4 +48,14 @@
<delete id="deleteAll">
delete from java_api_info_statics
</delete>
<select id="selectJavaApiStaticsByIds" resultMap="BaseResultMap">
select api_id, mobj_id, is_exception, exception,start_time,end_time from java_api_info_statics
where
<foreach collection="list" item="item" index="index" separator="or" open="(" close=")">
(api_id = #{item.serviceId} and mobj_id= #{item.mObjectId} )
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...