Authored by jack.xue

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

... ... @@ -8,6 +8,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* javaApi 定时任务
* Created by fruwei on 2016/6/19.
*/
@Component
... ...
... ... @@ -70,7 +70,7 @@ public class JavaApiClient {
private int JavaApiExecutorPoolMaxSize;
//TODO 需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
//TODO 需不需要 线程安全 处理 不过一般不会出现并发,任务周期比较长,一般周期内任务能够完成
private Map<String, JavaApiInfo> javaApimap;
private MultiValueMap<Integer, MObjectDetails> mObjInfoMap;
... ... @@ -80,6 +80,9 @@ public class JavaApiClient {
private CompletionService<JavaApiStatics> completionService;
/**
* 初始化任务执行客户端
*/
public void initClient() {
executorService = new ThreadPoolExecutor(JavaApiExecutorPoolCoreSize, JavaApiExecutorPoolMaxSize,
60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
... ... @@ -94,6 +97,9 @@ public class JavaApiClient {
javaApiStatus.clear();
}
/**
* 初始化监控的任务列表
*/
public void initApiMonitor() {
//获取JAVA服务信息
List<JavaApiInfo> apiInfos = javaApiInfoService.queryJavaApiInfo();
... ... @@ -135,6 +141,9 @@ public class JavaApiClient {
}
/**
* 任务执行函数
*/
public void run() {
long startTime = System.currentTimeMillis();
int tastNum = 0;
... ... @@ -169,6 +178,11 @@ public class JavaApiClient {
}
/**
* 结果处理函数
*
* @param rep
*/
public void handleResult(JavaApiStatics rep) {
... ...
... ... @@ -59,6 +59,11 @@ public class JavaApiStatus {
}
/**
* 获取各个模块的状态
*
* @return
*/
public List<JavaApiStaticsRep> getStatusList() {
List<JavaApiStaticsRep> rel = new ArrayList<JavaApiStaticsRep>();
... ...
... ... @@ -12,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
import java.util.concurrent.Callable;
/**
* java api 任务单元
* Created by fruwei on 2016/6/19.
*/
public class JavaApiTask implements Callable<JavaApiStatics> {
... ...
... ... @@ -4,6 +4,8 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 自定义java api线程池内工作线程工厂
* 指定生成线程名称:pool-javaApi-thread-[num]
* Created by fruwei on 2016/6/20.
*/
public class JavaApiThreadFactory implements ThreadFactory {
... ...
... ... @@ -31,6 +31,15 @@ public class JavaAppInfoStaticsCtrl {
@Autowired
IJavaApiStatusService javaApiStatusService;
@Autowired
JavaApiClient client; //留给测试函数使用
/**
* 查询单个api的状态
*
* @param req
* @return
*/
@RequestMapping("/queryOne")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq req) {
... ... @@ -49,6 +58,12 @@ public class JavaAppInfoStaticsCtrl {
return rep;
}
/**
* 批量查询api的状态
*
* @param req
* @return
*/
@RequestMapping("/query")
@ResponseBody
public BaseResponse getJavaApiStatus(@RequestBody JavaApiStatusReq[] req) {
... ... @@ -67,9 +82,11 @@ public class JavaAppInfoStaticsCtrl {
}
@Autowired
JavaApiClient client;
/**
* 手动任务执行入口
*
* @return
*/
@RequestMapping("/tasktest")
@ResponseBody
public String getJavaApiStatus() {
... ... @@ -81,6 +98,11 @@ public class JavaAppInfoStaticsCtrl {
return "cost : " + (end - start) / 1000 + "s";
}
/**
* 最近的api日志
*
* @return
*/
@RequestMapping("/querylatesthis")
@ResponseBody
public BaseResponse getJavaApiStatusHisLatest(@RequestParam(required = false, defaultValue = "0") int api_id,
... ... @@ -99,6 +121,11 @@ public class JavaAppInfoStaticsCtrl {
}
/**
* 条件查询api日志
*
* @return
*/
@RequestMapping("/queryhis")
@ResponseBody
public BaseResponse getJavaApiStatusHis(@RequestBody JavaApiHisReq req) {
... ... @@ -132,6 +159,11 @@ public class JavaAppInfoStaticsCtrl {
}
/**
* 查询api各个模块的统计信息
*
* @return
*/
@RequestMapping("/queryAll")
@ResponseBody
public BaseResponse getAllJavaApiStatus() {
... ...
... ... @@ -8,6 +8,11 @@ import com.monitor.javaserver.common.JavaApiStatics;
*/
public interface IJavaApiHadnler {
public void handler(JavaApiStatics javaApiStatics) ;
/**
* 请求处理函数
*
* @param javaApiStatics
*/
public void handler(JavaApiStatics javaApiStatics);
}
... ...
... ... @@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* influxdb api访问日志记录
* Created by fruwei on 2016/6/20.
*/
@Component("influxDBJavaApiHandler")
... ... @@ -27,7 +28,6 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
public void handler(JavaApiStatics javaApiStatics) {
// log.info("handle result: {}", javaApiStatics);
JSONObject jsonObject = new JSONObject();
JavaApiInfo javaApiInfo = javaApiStatics.getJavaApiInfo();
jsonObject.put("api_id", javaApiInfo.getServiceId());
... ... @@ -51,14 +51,11 @@ public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
jsonObject.put("is_exception", javaApiStatics.isHasException());
if (javaApiStatics.isHasException()) {
jsonObject.put("exception", ExceptionUtils.getStackTrace(javaApiStatics.getException()));
} else {
// JSONObject rep = javaApiStatics.getResponse();
// jsonObject.put("response", javaApiStatics.getResponse());
}
javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject);
}
}
... ...
... ... @@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 短信告警处理
* Created by fruwei on 2016/6/22.
*/
@Component("msgJavaApiHandler")
... ... @@ -36,8 +37,10 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
@Override
public void handler(JavaApiStatics javaApiStatics) {
String key = buildKey(javaApiStatics);
//无错
if (javaApiStatics.isHasException() == false) {
//开关关闭、告警次数未设置、无错
if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0 ||
javaApiStatics.getJavaApiInfo().getApiWarnTrigger() <= 0 ||
javaApiStatics.isHasException() == false) {
if (mapStatics.containsKey(key)) {
mapStatics.remove(key);
}
... ... @@ -76,10 +79,9 @@ public class MsgJavaApiHandler implements IJavaApiHadnler {
msgBuilder.append("Java API Error ")
.append("最近出错次数:" + num).append(" , ")
.append("NAME:" + javaApiInfo.getApiName()).append(" , ")
.append("URL:" + javaApiInfo.getApiUrl()).append(" , ")
// .append("URL:" + javaApiInfo.getApiUrl()).append(" , ")
.append("IP:" + mObjectInfo.getMoHostIp()).append(" , ")
.append("TYPE:" + javaApiInfo.getServiceType()).append(" , ")
.append(".");
.append("TYPE:" + javaApiInfo.getServiceType()).append(" , ");
return msgBuilder.toString();
}
... ...
... ... @@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* 统计信息处理
* 统计每个模块的(gateway,order...)的整体状态(出错、成功数量)
* Created by fruwei on 2016/6/27.
*/
@Component
... ... @@ -23,7 +24,7 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler {
@Override
public void handler(JavaApiStatics javaApiStatics) {
if(javaApiStatics.getJavaApiInfo().getApiToggle()==0){
if (javaApiStatics.getJavaApiInfo().getApiToggle() == 0) {
return;
}
if (javaApiStatics.isHasException()) {
... ... @@ -31,8 +32,5 @@ public class StaticsJavaApiHandler implements IJavaApiHadnler {
} else {
javaApiStatus.addSuccess(javaApiStatics);
}
}
}
... ...
... ... @@ -13,16 +13,52 @@ import java.util.List;
public interface IJavaApiStatusService {
/**
* 查询api的状态
*
* @param req
* @return
*/
public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req);
/**
* 批量查询api的状态
*
* @param reqList
* @return
*/
public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList);
/**
* 查询最近的java api的历史信息
*
* @param api_id
* @param mobj_id
* @return
*/
public List<JavaApiStatusRep> getJavaApiStatusHisLatest(int api_id, int mobj_id);
/**
* 根据时间段、查询条件查询java api的历史信息
*
* @param req
* @return
*/
public List<JavaApiStatusRep> getJavaApiStatusHisByTime(JavaApiHisReq req);
/**
* 根据时间段、查询条件统计数量
*
* @param req
* @return
*/
public int countJavaApiStatusHisByTime(JavaApiHisReq req);
/**
* 获取各个模块的状态信息
*
* @return
*/
public List<JavaApiStaticsRep> getAllJavaApiStatus();
... ...
... ... @@ -18,7 +18,7 @@ public class ZookeeperMonitorTask {
IZkMonitorService zkMonitorService;
//@Scheduled(fixedRate=20000)
//@Scheduled(cron="0 */5 * * * ?")
//@Scheduled(cron="0 */15 * * * ?")
public void zookeeperMonitor() {
zkMonitorService.zookeeperMonitor();
}
... ...
... ... @@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18
#-----------------------------Logs告警模块--------------------------
#-----------------------------监控系统开发人员--------------------------
sendsms.alarm.mobile.ops_manager.developer=13914772123,15150551036
sendsms.alarm.mobile.ops_manager.developer=13914772123
#-----------------------------监控系统开发人员--------------------------
dnspod.mobile=15905144483,18652008443,18751986615
... ...
... ... @@ -46,7 +46,7 @@ sendsms.alarm.mobile.logs.sns_send_failed=15905144483,18751986615,18652008443,18
#-----------------------------Logs告警模块--------------------------
#-----------------------------监控系统开发人员--------------------------
sendsms.alarm.mobile.ops_manager.developer=13914772123,15150551036
sendsms.alarm.mobile.ops_manager.developer=13914772123
#-----------------------------监控系统开发人员--------------------------
dnspod.mobile=15905144483,18652008443,18751986615
... ...