监控日志服务

parent db85ce52
...@@ -34,6 +34,7 @@ public class ServiceIServiceImpl implements ServiceService { ...@@ -34,6 +34,7 @@ public class ServiceIServiceImpl implements ServiceService {
///usr/local/startTomcat.sh ///usr/local/startTomcat.sh
String shell=shellPaht+shellname; String shell=shellPaht+shellname;
System.out.println("调用shell文件地址:====="+shell+" \""+servletPath+"\""); System.out.println("调用shell文件地址:====="+shell+" \""+servletPath+"\"");
//System.out.println("实时返回的日志:====="+executor.exec(shell+" \""+servletPath+"\" \"" + kssj + "\" \"" + jssj + "\""));
return XzxtRestResult.build(201,"调用成功",executor.exec(shell+" \""+servletPath+"\" \"" + kssj + "\" \"" + jssj + "\"")); return XzxtRestResult.build(201,"调用成功",executor.exec(shell+" \""+servletPath+"\" \"" + kssj + "\" \"" + jssj + "\""));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -51,29 +51,25 @@ public class LogsReport { ...@@ -51,29 +51,25 @@ public class LogsReport {
String kssj = readValue("logs.properties", "kssj"); String kssj = readValue("logs.properties", "kssj");
String jssj = readValue("logs.properties", "jssj"); String jssj = readValue("logs.properties", "jssj");
//初始化 //初始化
if(StringUtils.isEmpty(kssj)){ if(StringUtils.isEmpty(kssj)) {
Date day=new Date(); Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(day).toString()); System.out.println(df.format(day).toString());
kssj = df.format(day).toString(); kssj = df.format(day).toString();
jssj = ""; jssj = "";
} }
System.out.println("=====>>>>>日志推送开启========kssj===="+kssj+"====jssj==="+jssj); if(StringUtils.isEmpty(ip)){
String json=serviceService.RemoteShellLogExecutor(ip,ipUsername,ipPassword,servicesRest.getShellPaht(),servicesRest.getLogsTomcatName(),servletPath,kssj,jssj).getData().toString(); System.out.println("=====>>>>>日志推送未开启============");
String value = new String(json.getBytes("ISO-8859-1"),"utf-8"); }else{
//格式化 System.out.println("=====>>>>>日志推送开启========kssj===="+kssj+"====jssj==="+jssj);
/* String reg = "\\d+\\-\\d+\\-\\d+"; String json=serviceService.RemoteShellLogExecutor(ip,ipUsername,ipPassword,servicesRest.getShellPaht(),servicesRest.getLogsTomcatName(),servletPath,kssj,jssj).getData().toString();
Pattern pattern = Pattern.compile(reg); String value = new String(json.getBytes("ISO-8859-1"),"utf-8");
Matcher matcher = pattern.matcher(json); json = json.replaceAll("\\[信息\\]","\\[信息\\]:<br>");
while (matcher.find()) { json = json.replaceAll("2018","<br>2018");
System.out.println(matcher.group()); Services services = new Services();
json.replaceAll(matcher.group(), "<br>"+matcher.group()); services.setServiceName("<h2 id=\"json\">"+json+"</h2>");
}*/ this.template.convertAndSend("/topic/getResponse", services);
//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 [信息] "; }
json = json.replaceAll("\\[信息\\]","\\[信息\\]:<br>");
json = json.replaceAll("2018","<br>2018");
Services services = new Services();
services.setServiceName("<h2 id=\"json\">"+json+"</h2>");
this.template.convertAndSend("/topic/getResponse", services);
} }
} }
...@@ -121,12 +121,12 @@ public class RemoteShellExecutor { ...@@ -121,12 +121,12 @@ public class RemoteShellExecutor {
return sb.toString(); return sb.toString();
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
//RemoteShellExecutor executor = new RemoteShellExecutor("192.168.193.133", "root", "18234077206"); RemoteShellExecutor executor = new RemoteShellExecutor("192.168.2.120", "root", "123456");
// 执行myTest.sh 参数为java Know dummy // 执行myTest.sh 参数为java Know dummy
// ./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\""));
//System.out.println(executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"\" \"\" ")); //System.out.println(executor.exec("/usr/local/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"\" \"\" "));
//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-control1\""));
// 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 str = "2018-09-20 00:06:47.958 [信息] [org.apache.catalina.core.AprLifecycleListener] org.apache.catalina.core.A"; String str = "2018-09-20 00:06:47.958 [信息] [org.apache.catalina.core.AprLifecycleListener] org.apache.catalina.core.A";
......
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