监控日志服务

parent bff0f961
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<groupId>com.cc</groupId> <groupId>com.cc</groupId>
<artifactId>service-rest</artifactId> <artifactId>service-rest</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.ty.1.1-SNAPSHOT_${maven.build.timestamp}</version>
<packaging>jar</packaging> <packaging>war</packaging>
<name>service-rest</name> <name>service-rest</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
...@@ -68,6 +68,11 @@ ...@@ -68,6 +68,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
...@@ -86,13 +91,32 @@ ...@@ -86,13 +91,32 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.4</version> <version>2.4</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>service-rest</finalName> <finalName>service-rest</finalName>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>static/**</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>static/**</include>
</includes>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
package com.cc;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServiceRestApplication.class);
}
}
...@@ -32,6 +32,7 @@ public class ServiceRestController { ...@@ -32,6 +32,7 @@ public class ServiceRestController {
初始化 初始化
*/ */
@GetMapping("/") @GetMapping("/")
@ResponseBody
public String hello(Model model){ public String hello(Model model){
model.addAttribute("hello","你好"); model.addAttribute("hello","你好");
return "hello"; return "hello";
......
...@@ -15,6 +15,7 @@ import org.springframework.web.context.request.RequestContextHolder; ...@@ -15,6 +15,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
...@@ -40,8 +41,8 @@ public class LogsReport { ...@@ -40,8 +41,8 @@ public class LogsReport {
//日志 //日志
@Scheduled(cron = "*/15 * * * * ?") //30秒 @Scheduled(cron = "*/15 * * * * ?") //30秒
@Async("taskExecutor") @Async("taskExecutor")
public void sendTopicMessage() { public void sendTopicMessage() throws UnsupportedEncodingException {
log.info("=====>>>>>日志推送开启========"); System.out.println("=====>>>>>日志推送开启========");
//调用日志服务 //调用日志服务
String ip = readValue("logs.properties", "ip"); String ip = readValue("logs.properties", "ip");
String ipUsername = readValue("logs.properties", "ipUsername"); String ipUsername = readValue("logs.properties", "ipUsername");
...@@ -57,8 +58,9 @@ public class LogsReport { ...@@ -57,8 +58,9 @@ public class LogsReport {
kssj = df.format(day).toString(); kssj = df.format(day).toString();
jssj = ""; jssj = "";
} }
log.info("=====>>>>>日志推送开启========kssj===="+kssj+"jssj==="+jssj); System.out.println("=====>>>>>日志推送开启========kssj===="+kssj+"====jssj==="+jssj);
String json=serviceService.RemoteShellLogExecutor(ip,ipUsername,ipPassword,servicesRest.getShellPaht(),servicesRest.getLogsTomcatName(),servletPath,kssj,jssj).getData().toString(); String json=serviceService.RemoteShellLogExecutor(ip,ipUsername,ipPassword,servicesRest.getShellPaht(),servicesRest.getLogsTomcatName(),servletPath,kssj,jssj).getData().toString();
String value = new String(json.getBytes("ISO-8859-1"),"utf-8");
//格式化 //格式化
/* String reg = "\\d+\\-\\d+\\-\\d+"; /* String reg = "\\d+\\-\\d+\\-\\d+";
Pattern pattern = Pattern.compile(reg); Pattern pattern = Pattern.compile(reg);
......
...@@ -128,7 +128,7 @@ public class RemoteShellLogExecutor { ...@@ -128,7 +128,7 @@ public class RemoteShellLogExecutor {
// ./startTomcat.sh "/usr/local/tomcat-portal" // ./startTomcat.sh "/usr/local/tomcat-portal"
//System.out.println(executor.exec("/usr/local/reportTomcat.sh \"/usr/local/tomcat-portal\"")); //System.out.println(executor.exec("/usr/local/reportTomcat.sh \"/usr/local/tomcat-portal\""));
// executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"2018-09-20 00:06:57\" \"2018-09-20 00:07:02\" "); // executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"2018-09-20 00:06:57\" \"2018-09-20 00:07:02\" ");
// System.out.println(executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"2018-09-20 00:07:02\" \"2018-09-20 00:07:02\" ")); System.out.println(executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"2018-10-11\" \"2018-10-11\" "));
//System.out.println(executor.exec("/usr/local/startTomcat.sh \"/usr/local/tomcat-portal11\"")); //System.out.println(executor.exec("/usr/local/startTomcat.sh \"/usr/local/tomcat-portal11\""));
// System.out.println(executor.exec("/usr/local/shutTomcat.sh \"/usr/local/tomcat-portal\"")); // System.out.println(executor.exec("/usr/local/shutTomcat.sh \"/usr/local/tomcat-portal\""));
String json="2018-09-20 00:06:47.958 [信息] [org.apache.catalina.core.AprLifecycleListener] org.apache.catalina.core.AprLifecycleListener init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-09-20 00:06:48.978 [信息] [org.apache.coyote.http11.Http11Protocol] org.apache.coyote.AbstractProtocol init Initializing ProtocolHandler [\"http-bio-8080\"] 2018-09-20 00:06:48.996 [信息] [org.apache.coyote.ajp.AjpProtocol] org.apache.coyote.AbstractProtocol init Initializing ProtocolHandler [\"ajp-bio-8009\"] 2018-09-20 00:06:49.000 [信息] [org.apache.catalina.startup.Catalina] org.apache.catalina.startup.Catalina load Initialization processed in 1818 ms 2018-09-20 00:06:49.040 [信息] [org.apache.catalina.core.StandardService] org.apache.catalina.core.StandardService startInternal Starting service Catalina 2018-09-20 00:06:49.044 [信息] "; String json="2018-09-20 00:06:47.958 [信息] [org.apache.catalina.core.AprLifecycleListener] org.apache.catalina.core.AprLifecycleListener init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-09-20 00:06:48.978 [信息] [org.apache.coyote.http11.Http11Protocol] org.apache.coyote.AbstractProtocol init Initializing ProtocolHandler [\"http-bio-8080\"] 2018-09-20 00:06:48.996 [信息] [org.apache.coyote.ajp.AjpProtocol] org.apache.coyote.AbstractProtocol init Initializing ProtocolHandler [\"ajp-bio-8009\"] 2018-09-20 00:06:49.000 [信息] [org.apache.catalina.startup.Catalina] org.apache.catalina.startup.Catalina load Initialization processed in 1818 ms 2018-09-20 00:06:49.040 [信息] [org.apache.catalina.core.StandardService] org.apache.catalina.core.StandardService startInternal Starting service Catalina 2018-09-20 00:06:49.044 [信息] ";
......
...@@ -53,7 +53,7 @@ public class ServiceReport { ...@@ -53,7 +53,7 @@ public class ServiceReport {
} }
//心跳正常 //心跳正常
if(xzxtRestResult.getData()=="success"){ if(xzxtRestResult.getData()=="success"){
log.info("=====>>>>>服务======"+services.getApplyName()+"========心跳正常========"); System.out.println("=====>>>>>服务======"+services.getApplyName()+"========心跳正常========");
//判断状态,不相等就更新 //判断状态,不相等就更新
falg=0; falg=0;
if(falg!=services.getStatus()) { if(falg!=services.getStatus()) {
...@@ -61,15 +61,15 @@ public class ServiceReport { ...@@ -61,15 +61,15 @@ public class ServiceReport {
updatservice.setStatus(falg); updatservice.setStatus(falg);
crudService.updateService(updatservice); crudService.updateService(updatservice);
servicename+="《"+services.getApplyName()+"》:心跳正常,状态由停到启——"; servicename+="《"+services.getApplyName()+"》:心跳正常,状态由停到启——";
log.info("=====>>>>>服务======"+services.getApplyName()+"========心跳正常,状态由停到启========"); System.out.println("=====>>>>>服务======"+services.getApplyName()+"========心跳正常,状态由停到启========");
}else { }else {
servicename+="《"+services.getApplyName()+"》:心跳正常,状态未变化——"; servicename+="《"+services.getApplyName()+"》:心跳正常,状态未变化——";
log.info("=====>>>>服务======"+services.getApplyName()+"========心跳正常,状态未变化========"); System.out.println("=====>>>>服务======"+services.getApplyName()+"========心跳正常,状态未变化========");
} }
} }
//心跳停止 //心跳停止
else if(xzxtRestResult.getData()=="failed"){ else if(xzxtRestResult.getData()=="failed"){
log.info("=====>>>>>服务======"+services.getApplyName()+"========心跳已停止========"); System.out.println("=====>>>>>服务======"+services.getApplyName()+"========心跳已停止========");
//判断状态,不相等就更新 //判断状态,不相等就更新
falg=1; falg=1;
if(falg!=services.getStatus()) { if(falg!=services.getStatus()) {
...@@ -77,21 +77,21 @@ public class ServiceReport { ...@@ -77,21 +77,21 @@ public class ServiceReport {
updatservice.setStatus(falg); updatservice.setStatus(falg);
crudService.updateService(updatservice); crudService.updateService(updatservice);
servicename+="《"+services.getApplyName()+"》:心跳已停止,状态由启到停——"; servicename+="《"+services.getApplyName()+"》:心跳已停止,状态由启到停——";
log.info("=====>>>>>服务======"+services.getApplyName()+"========心跳已停止,状态由启到停========"); System.out.println("=====>>>>>服务======"+services.getApplyName()+"========心跳已停止,状态由启到停========");
}else { }else {
servicename+="《"+services.getApplyName()+"》:心跳正常,状态未变化——"; servicename+="《"+services.getApplyName()+"》:心跳正常,状态未变化——";
log.info("=====>>>>服务======"+services.getApplyName()+"========心跳已停止,状态未变化========"); System.out.println("=====>>>>服务======"+services.getApplyName()+"========心跳已停止,状态未变化========");
} }
} }
//心跳异常 //心跳异常
else{ else{
servicename+="《"+services.getApplyName()+"》:心跳异常——"; servicename+="《"+services.getApplyName()+"》:心跳异常——";
log.info("=====>>>>服务======"+services.getApplyName()+"========心跳异常========"); System.out.println("=====>>>>服务======"+services.getApplyName()+"========心跳异常========");
} }
} }
return XzxtRestResult.build(falg,"",servicename); return XzxtRestResult.build(falg,"",servicename);
}else { }else {
log.info("=====>>>>暂无服务========================================="); System.out.println("=====>>>>暂无服务=========================================");
return XzxtRestResult.build(falg, "", servicename); return XzxtRestResult.build(falg, "", servicename);
} }
} }
......
version=@project.version@
describe=
1.修改页面;
2.新增查询功能;
3.本次打包更新以上1.2功能;
4.新增消息功能
\ No newline at end of file
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