Authored by zhengyouwei

u

... ... @@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper;
import com.monitor.influxdb.model.ZkInfo;
import com.monitor.model.domain.JavaProjectStatus;
import com.monitor.model.domain.PageBean;
import org.influxdb.dto.QueryResult;
import java.util.List;
... ... @@ -13,4 +14,6 @@ public interface JavaProjectMapper {
void insert(JavaProjectStatus javaProjectStatus);
List<JavaProjectStatus> getByProject(String project);
}
... ...
... ... @@ -4,14 +4,16 @@ import com.monitor.influxdb.InfluxDBQuery;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.JavaProjectMapper;
import com.monitor.influxdb.util.QueryResultUtil;
import com.monitor.model.domain.JavaProjectStatus;
import org.influxdb.dto.Point;
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;
import java.util.Random;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
... ... @@ -34,10 +36,36 @@ public class JavaProjectMapperImpl extends InfluxDBQuery implements JavaProjectM
.tag("ip", javaProjectStatus.getIp())
.tag("cloud", javaProjectStatus.getCloud())
.tag("status", javaProjectStatus.getStatus())
.addField("lastStart",javaProjectStatus.getLastStart() == null? "1":javaProjectStatus.getLastStart())
.addField("lastStart", javaProjectStatus.getLastStart() == null ? "1" : javaProjectStatus.getLastStart())
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
.write(InfluxDBContants.MONITOR_SYSTEM, "default", point);
}
@Override
public List<JavaProjectStatus> getByProject(String project) {
String cpmmond = "select cloud,ip,lastStart,status from java_project_status where time > now() - 4m and \"name\" = '" + project + "' order by time desc";
QueryResult result = query(InfluxDBContants.AWS, cpmmond, InfluxDBContants.MONITOR_SYSTEM);
List<List<Object>> lists = QueryResultUtil.getValues(result);
List<JavaProjectStatus> javaProjectStatusList = new ArrayList<>();
Set<String> stringSet = new HashSet<>();
if (lists != null){
JavaProjectStatus javaProjectStatus;
for (List<Object> objects : lists){
String ip = objects.get(2).toString();
if (stringSet.contains(ip)){
continue;
}
stringSet.add(ip);
javaProjectStatus = new JavaProjectStatus();
javaProjectStatus.setCloud(objects.get(1).toString());
javaProjectStatus.setIp(objects.get(2).toString().split("@")[1]);
javaProjectStatus.setLastStart(objects.get(3).toString());
javaProjectStatus.setStatus(objects.get(4).toString());
javaProjectStatusList.add(javaProjectStatus);
}
}
return javaProjectStatusList;
}
}
... ...
... ... @@ -9,6 +9,7 @@ public class ProjectOnline {
static{
JAVA_LIST.add(new Project("1","yoho-gateway","126","yoho30"));
JAVA_LIST.add(new Project("1","yoho-sns","125","yoho30"));
JAVA_LIST.add(new Project("1","yoho-message","123","yoho30"));
JAVA_LIST.add(new Project("1","uic","439","yoho30"));
... ... @@ -18,8 +19,6 @@ public class ProjectOnline {
JAVA_LIST.add(new Project("1","yohobuy-product","143","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-order","124","yoho30"));
JAVA_LIST.add(new Project("1","yoho-push","137","yoho30"));
JAVA_LIST.add(new Project("1","cms_push","514","yoho30"));
JAVA_LIST.add(new Project("1","mars_push","494","yoho30"));
JAVA_LIST.add(new Project("1","yoho-social","353","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-union","133","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-activity","129","yoho30"));
... ... @@ -28,15 +27,14 @@ public class ProjectOnline {
JAVA_LIST.add(new Project("1","yohobuy-wechat","248","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-brower","131","yoho30"));
JAVA_LIST.add(new Project("1","yohobuy-bigdata","144","yoho30"));
JAVA_LIST.add(new Project("1","yoho-gateway","126","yoho30"));
JAVA_LIST.add(new Project("2","yoho-search-service","12","yoho-search"));
JAVA_LIST.add(new Project("2","yoho-search-consumer","8","yoho-search"));
JAVA_LIST.add(new Project("2","yoho-search-producer","7","yoho-search"));
JAVA_LIST.add(new Project("2","yohomars-search-service","554","yoho-search"));
JAVA_LIST.add(new Project("2","yoho-search-adaptor","13","yoho-search"));
JAVA_LIST.add(new Project("3","yohobuy-platform","110","platform"));
JAVA_LIST.add(new Project("1","cms_push","514","yoho30"));
JAVA_LIST.add(new Project("1","mars_push","494","yoho30"));
}
... ...
package com.monitor.other.projectRestart.ctrl;
import com.model.JavaApiInfo;
import com.monitor.influxdb.mapper.JavaProjectMapper;
import com.monitor.model.domain.JavaProjectStatus;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageRequest;
import com.monitor.model.request.JavaApiInfoReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.model.response.PageResponse;
import com.monitor.other.projectRestart.common.Project;
import com.monitor.other.projectRestart.common.ProjectOnline;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by zhengyouwei on 2016/10/18.
*/
@RestController
@RequestMapping(value = "/javaRestart")
public class JavaRestartCtrl {
Logger log = LoggerFactory.getLogger(JavaRestartCtrl.class);
@Autowired
private JavaProjectMapper javaProjectMapper;
@RequestMapping("/query")
@ResponseBody
public BaseResponse<PageResponse<Project>> getProjectInfos(@RequestBody PageRequest req) throws Exception {
PageResponse<Project> response = new PageResponse<Project>();
try {
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
req.getPageSize(), req);
// 先查询符合条件的总数量
int total = ProjectOnline.getJavaList().size();
response.setCurrentPage(req.getCurrentPage());
int end = page.getStartIndex() + page.getPageSize();
if (end >= total) {
end = total;
}
response.setRows(ProjectOnline.getJavaList().subList(page.getStartIndex(), end));
response.setPageSize(req.getPageSize());
response.setTotal(total);
} catch (Exception e) {
log.error("getProjectInfos~", e);
}
return new BaseResponse<>(response);
}
@RequestMapping("/getProjectStatus")
@ResponseBody
public BaseResponse<List<JavaProjectStatus>> getStatusInfos(String project) {
try {
List<JavaProjectStatus> list = javaProjectMapper.getByProject(project);
return new BaseResponse<>(list);
} catch (Exception e) {
log.error("getStatusInfos ~", e);
return null;
}
}
}
... ...
... ... @@ -32,7 +32,7 @@ public class ProjectStatusTask {
for (Project project :ProjectOnline.getJavaList()){
try {
String name = project.getName();
String commond = "ssh master@10.66.4.25 /home/master/.java_pm/java_restart.sh checkstatus mix " + name;
String commond = "ssh master@10.66.4.25 sh /home/master/.java_pm/java_restart.sh checkstatus mix " + name;
List<String> list = exe(commond);
for (String string : list){
String[] array = string.split("@@");
... ... @@ -44,6 +44,7 @@ public class ProjectStatusTask {
javaProjectStatus.setCloud(array[0]);
javaProjectStatus.setIp(array[1]);
javaProjectStatus.setStatus(array[2]);
javaProjectStatus.setLastStart(array[3]);
javaProjectMapper.insert(javaProjectStatus);
}
}catch (Exception e){
... ...
... ... @@ -12,6 +12,6 @@ cron_task_rabbit_scan=0 0/1 * * * ?
cron_task_dns_monit=0 1/5 * * * ?
cron_task_project_status=0 0/2 * * * ?
cron_task_project_status=0 0/3 * * * ?
... ...