监控系统服务修改

parent dc0463be
...@@ -3,11 +3,13 @@ package com.cc; ...@@ -3,11 +3,13 @@ package com.cc;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
@MapperScan(value = "com.cc.mapper") @MapperScan(value = "com.cc.mapper")
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@EnableAsync
public class XzxtControlApplication { public class XzxtControlApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.cc.common; package com.cc.common;
import com.cc.bean.Services;
import com.cc.bean.ServicesRest;
import com.cc.service.ServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List;
/** /**
* Created by changc on 2018/9/11. * Created by changc on 2018/9/11.
*/ */
@Slf4j
@Component @Component
public class ServiceReport { public class ServiceReport {
@Scheduled(cron = "0/2 * * * * *") /* @Autowired
public void work() { private ServiceService serviceService;
//获取当前时间 //心跳机制
LocalDateTime localDateTime = LocalDateTime.now(); @Scheduled(cron = "0/5 * * * * *")
System.out.println("当前时间为:" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); @Async("taskExecutor")
} public void ServiceReport(){
System.out.print("心跳开始------------------------------------》");
List<Services> ServiceList= (List<Services>) serviceService.SelectServiceList().getData();
for(Services services:ServiceList){
log.info("=====>>>>>使用cron {}",services.getId());
}
}*/
} }
package com.cc.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
/**
* Created by changc on 2018/9/12.
*/
@Configuration
@EnableAsync
public class AsyncConfig {
/*
此处成员变量应该使用@Value从配置中读取
*/
@Value("${ThreadPool.corePoolSize}")
private int corePoolSize;
@Value("${ThreadPool.maxPoolSize}")
private int maxPoolSize;
@Value("${ThreadPool.queueCapacity}")
private int queueCapacity;
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.initialize();
return executor;
}
}
...@@ -5,6 +5,7 @@ import java.util.List; ...@@ -5,6 +5,7 @@ import java.util.List;
public interface ServiceMapper { public interface ServiceMapper {
List<Services> selectPageList(Services service); List<Services> selectPageList(Services service);
List<Services> selectServiceList();
int selectPageCount(Services service); int selectPageCount(Services service);
Services selectServices(int id); Services selectServices(int id);
int saveService(Services service); int saveService(Services service);
......
...@@ -19,11 +19,11 @@ public interface ServiceService { ...@@ -19,11 +19,11 @@ public interface ServiceService {
* @return * @return
*/ */
ResultMap ServiceAll(Services service); ResultMap ServiceAll(Services service);
XzxtRestResult SelectServiceList();
XzxtRestResult SelectServices(int id); XzxtRestResult SelectServices(int id);
XzxtRestResult SaveService(Services service); XzxtRestResult SaveService(Services service);
XzxtRestResult updateService(Services service); XzxtRestResult updateService(Services service);
XzxtRestResult updateServiceByid(int id,int status); XzxtRestResult updateServiceByid(int id,int status);
XzxtRestResult deleteService(int id); XzxtRestResult deleteService(int id);
XzxtRestResult reportSerives();
} }
...@@ -37,6 +37,15 @@ public class ServiceIServiceImpl implements ServiceService { ...@@ -37,6 +37,15 @@ public class ServiceIServiceImpl implements ServiceService {
} }
@Override @Override
public XzxtRestResult SelectServiceList() {
List<Services> serviceslist=serviceMapper.selectServiceList();
if(!StringUtils.isEmpty(serviceslist)){
return XzxtRestResult.build(201,"读取成功",serviceslist);
}else{
return XzxtRestResult.build(202,"读取失败","");
}
}
@Override
public XzxtRestResult SaveService(Services service) { public XzxtRestResult SaveService(Services service) {
int num=serviceMapper.saveService(service); int num=serviceMapper.saveService(service);
if(num==1){ if(num==1){
...@@ -86,13 +95,6 @@ public class ServiceIServiceImpl implements ServiceService { ...@@ -86,13 +95,6 @@ public class ServiceIServiceImpl implements ServiceService {
} }
} }
@Override
public XzxtRestResult reportSerives() {
//获取当前时间
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println("当前时间为:" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
return null;
}
} }
...@@ -43,5 +43,11 @@ service-rest: ...@@ -43,5 +43,11 @@ service-rest:
startTomcatName: "startTomcat.sh" startTomcatName: "startTomcat.sh"
stopTomcatName: "shutTomcat.sh" stopTomcatName: "shutTomcat.sh"
reportTomcatName: "reportTomcat.sh" reportTomcatName: "reportTomcat.sh"
ThreadPool:
#核心线程数
corePoolSize: 20
#最大线程数
maxPoolSize: 200
#任务队列容量(阻塞队列)
queueCapacity: 10
...@@ -26,6 +26,13 @@ ...@@ -26,6 +26,13 @@
</if> </if>
</where> </where>
</sql> </sql>
<!-- 查询所有的服务-->
<select id="selectServiceList" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from service
</select>
<!-- 通过条件分页查询,返回数据集 --> <!-- 通过条件分页查询,返回数据集 -->
<select id="selectPageList" parameterType="com.cc.bean.Services" resultMap="BaseResultMap"> <select id="selectPageList" parameterType="com.cc.bean.Services" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> select <include refid="Base_Column_List"/>
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
</div> </div>
</div> </div>
<%--<table class="layui-hide" id="test" lay-filter="test"></table>--%>
<script type="text/html" id="toolbarDemo"> <script type="text/html" id="toolbarDemo">
<div class="layui-btn-container"> <div class="layui-btn-container">
...@@ -46,17 +45,18 @@ ...@@ -46,17 +45,18 @@
</script> </script>
<script type="text/html" id="barDemo"> <script type="text/html" id="barDemo">
{{# if (d.status=== 0) { }} {{# if (d.status=== 1) { }}
<a class="layui-btn layui-btn-xs" lay-event="start">启动</a> <a class="layui-btn layui-btn-xs" lay-event="start">启动</a>
{{# } else { }} {{# } else { }}
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="stop">停止</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="stop">停止</a>
{{# } }} {{# } }}
</script> </script>
<script type="text/html" id="barDemo1"> <script type="text/html" id="barDemo1">
{{# if (d.status=== 0) { }}
<i class="fa fa-circle fa-color2"></i> {{# if (d.status=== 0) {}}
{{# } else { }}
<i class="fa fa-circle fa-color1"></i> <i class="fa fa-circle fa-color1"></i>
{{# } else { }}
<i class="fa fa-circle fa-color2"></i>
{{# } }} {{# } }}
</script> </script>
<script type="text/html" id="barDemo2"> <script type="text/html" id="barDemo2">
...@@ -121,7 +121,10 @@ ...@@ -121,7 +121,10 @@
shadeClose: true, shadeClose: true,
shade: 0.8, shade: 0.8,
area: ['500px', '90%'], area: ['500px', '90%'],
content: '/serviceform' content: '/serviceform',
end:function(){
$('.layui-laypage-btn').click();//模拟点击
}
}); });
break; break;
//更新 //更新
...@@ -137,7 +140,10 @@ ...@@ -137,7 +140,10 @@
shadeClose: true, shadeClose: true,
shade: 0.8, shade: 0.8,
area: ['500px', '90%'], area: ['500px', '90%'],
content: '/services/'+data[0].id content: '/services/'+data[0].id,
end:function(){
$('.layui-laypage-btn').click();//模拟点击
}
}); });
} }
else else
...@@ -162,7 +168,7 @@ ...@@ -162,7 +168,7 @@
if (data.status == "201") { if (data.status == "201") {
layer.msg("删除成功"); layer.msg("删除成功");
layer.close(index); layer.close(index);
window.parent.location.reload(); //刷新父页面 $('.layui-laypage-btn').click();//模拟点击
} else { } else {
layer.close(index); layer.close(index);
layer.msg("删除失败"); layer.msg("删除失败");
...@@ -209,25 +215,26 @@ ...@@ -209,25 +215,26 @@
if(data.serviceName="tomcat"){ if(data.serviceName="tomcat"){
var shellname="${startTomcatName}"; var shellname="${startTomcatName}";
} }
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "${startRest}", url: "${startRest}",
data: {ip:data.serviceIp, ipUsername:data.ipUsername,ipPassword:data.ipPassword, data: {ip:data.serviceIp, ipUsername:data.ipUsername,ipPassword:data.ipPassword,
shellPaht:"${shellPaht}",shellname:shellname,servletPath:data.servletPath}, shellPaht:"${shellPaht}",shellname:shellname,servletPath:data.servletPath},
dataType: "json", dataType: "json",
success: function(data){ success: function(data){
console.log(data); console.log(data);
if(data.data=="0"){ if(data.data=="success"){
layer.close(index); debugger;
layer.msg("启动成功"); layer.close(index);
updateStatus(id,1); layer.msg("启动成功");
window.location.reload(); updateStatus(id,0);
}else{ $(".layui-laypage-btn").click();
layer.close(index); }else{
layer.msg("启动失败"); layer.close(index);
layer.msg("启动失败");
}
} }
} });
});
}}) }})
}else if(obj.event === 'stop'){ }else if(obj.event === 'stop'){
debugger debugger
...@@ -244,11 +251,12 @@ ...@@ -244,11 +251,12 @@
dataType: "json", dataType: "json",
success: function(data){ success: function(data){
console.log(data); console.log(data);
if(data.data=="0"){ if(data.data=="success"){
debugger;
layer.close(index); layer.close(index);
layer.msg("关闭成功"); layer.msg("关闭成功");
updateStatus(id,0); updateStatus(id,1);
window.location.reload(); $(".layui-laypage-btn").click();
}else{ }else{
layer.close(index); layer.close(index);
layer.msg("关闭失败"); layer.msg("关闭失败");
...@@ -258,14 +266,9 @@ ...@@ -258,14 +266,9 @@
}}) }})
} }
}); });
/*$(document).on("click",".layui-form-checkbox",function () {
if($(this).hasClass("layui-form-checked")){
$(this).removeClass("layui-form-checked");
}else{
$(this).addClass("layui-form-checked");
}
})*/
}); });
//更新服务状态 //更新服务状态
function updateStatus (id,status) { function updateStatus (id,status) {
$.ajax({ $.ajax({
...@@ -273,7 +276,8 @@ ...@@ -273,7 +276,8 @@
url: "/updateservices/"+id+"/"+status, url: "/updateservices/"+id+"/"+status,
dataType: "json", dataType: "json",
success: function(data){ success: function(data){
if(data.data=="0"){ debugger;
if(data.status==201){
layer.msg("状态修改成功"); layer.msg("状态修改成功");
}else{ }else{
layer.msg("状态修改失败"); layer.msg("状态修改失败");
...@@ -281,6 +285,14 @@ ...@@ -281,6 +285,14 @@
} }
}); });
} }
$(function(){
// 开启定时任务,时间间隔为3000 ms。
setInterval(function(){
//window.location.reload();
//当前页的刷新
$(".layui-laypage-btn").click();
}, 3000);
});
</script> </script>
......
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
<div class="layui-form-item" style="display: none"> <div class="layui-form-item" style="display: none">
<label class="layui-form-label">状态:</label> <label class="layui-form-label">状态:</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="status" value="0" placeholder="请输入应用服务器端口" autocomplete="off" class="layui-input"> <input type="text" name="status" value="1" placeholder="请输入应用服务器端口" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
<%-- <div class="layui-form-item"> <%-- <div class="layui-form-item">
...@@ -163,7 +163,7 @@ ...@@ -163,7 +163,7 @@
layer.msg("保存成功"); layer.msg("保存成功");
var index = parent.layer.getFrameIndex(window.name); var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);//关闭当前页 parent.layer.close(index);//关闭当前页
window.parent.location.reload(); //刷新父页面 //window.parent.location.reload(); //刷新父页面
}else{ }else{
//layer.close(index); //layer.close(index);
layer.msg("保存失败"); layer.msg("保存失败");
......
...@@ -168,7 +168,6 @@ ...@@ -168,7 +168,6 @@
layer.msg("修改成功"); layer.msg("修改成功");
var index = parent.layer.getFrameIndex(window.name); var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);//关闭当前页 parent.layer.close(index);//关闭当前页
window.parent.location.reload(); //刷新父页面
}else{ }else{
//layer.close(index); //layer.close(index);
layer.msg("修改失败"); layer.msg("修改失败");
......
...@@ -2,6 +2,8 @@ package com.cc; ...@@ -2,6 +2,8 @@ package com.cc;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
...@@ -11,6 +13,18 @@ public class XzxtControlApplicationTests { ...@@ -11,6 +13,18 @@ public class XzxtControlApplicationTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
//记录器
Logger logger = LoggerFactory.getLogger(getClass());
//System.out.println();
//日志的级别;
//由低到高 trace<debug<info<warn<error
//可以调整输出的日志级别;日志就只会在这个级别以以后的高级别生效
logger.trace("这是trace日志...");
logger.debug("这是debug日志...");
//SpringBoot默认给我们使用的是info级别的,没有指定级别的就用SpringBoot默认规定的级别;root级别
logger.info("这是info日志...");
logger.warn("这是warn日志...");
logger.error("这是error日志...");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment