Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service-rest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
常超
service-rest
Commits
550e39f9
Commit
550e39f9
authored
Nov 16, 2018
by
chang_chao@founder.com.cn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
监控日志服务
parent
db85ce52
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
23 deletions
+20
-23
src/main/java/com/cc/service/serviceimpl/ServiceIServiceImpl.java
+1
-0
src/main/java/com/cc/serviceutil/LogsReport.java
+17
-21
src/main/java/com/cc/serviceutil/RemoteShellExecutor.java
+2
-2
No files found.
src/main/java/com/cc/service/serviceimpl/ServiceIServiceImpl.java
View file @
550e39f9
...
...
@@ -34,6 +34,7 @@ public class ServiceIServiceImpl implements ServiceService {
///usr/local/startTomcat.sh
String
shell
=
shellPaht
+
shellname
;
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
+
"\""
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
src/main/java/com/cc/serviceutil/LogsReport.java
View file @
550e39f9
...
...
@@ -51,29 +51,25 @@ public class LogsReport {
String
kssj
=
readValue
(
"logs.properties"
,
"kssj"
);
String
jssj
=
readValue
(
"logs.properties"
,
"jssj"
);
//初始化
if
(
StringUtils
.
isEmpty
(
kssj
)){
Date
day
=
new
Date
();
if
(
StringUtils
.
isEmpty
(
kssj
))
{
Date
day
=
new
Date
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
System
.
out
.
println
(
df
.
format
(
day
).
toString
());
kssj
=
df
.
format
(
day
).
toString
();
jssj
=
""
;
kssj
=
df
.
format
(
day
).
toString
();
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
value
=
new
String
(
json
.
getBytes
(
"ISO-8859-1"
),
"utf-8"
);
//格式化
/* String reg = "\\d+\\-\\d+\\-\\d+";
Pattern pattern = Pattern.compile(reg);
Matcher matcher = pattern.matcher(json);
while (matcher.find()) {
System.out.println(matcher.group());
json.replaceAll(matcher.group(), "<br>"+matcher.group());
}*/
//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
);
if
(
StringUtils
.
isEmpty
(
ip
)){
System
.
out
.
println
(
"=====>>>>>日志推送未开启============"
);
}
else
{
System
.
out
.
println
(
"=====>>>>>日志推送开启========kssj===="
+
kssj
+
"====jssj==="
+
jssj
);
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"
);
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
);
}
}
}
src/main/java/com/cc/serviceutil/RemoteShellExecutor.java
View file @
550e39f9
...
...
@@ -121,12 +121,12 @@ public class RemoteShellExecutor {
return
sb
.
toString
();
}
public
static
void
main
(
String
args
[])
throws
Exception
{
//RemoteShellExecutor executor = new RemoteShellExecutor("192.168.193.133", "root", "1823407720
6");
RemoteShellExecutor
executor
=
new
RemoteShellExecutor
(
"192.168.2.120"
,
"root"
,
"12345
6"
);
// 执行myTest.sh 参数为java Know dummy
// ./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/tomcatLogs.sh \"/usr/local/tomcat-portal\" \"\" \"\" "));
//System.out.println(executor.exec("/usr/local/startTomcat.sh \"/usr/local/tomcat-portal1
1\""));
System
.
out
.
println
(
executor
.
exec
(
"/usr/local/startTomcat.sh \"/usr/local/tomcat-control
1\""
));
// 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"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment