日志开发

parent 81fb9758
......@@ -30,6 +30,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!-- webSocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 引入web模块 -->
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -24,6 +24,9 @@ public class ServicesRest {
private String stopRest;
//监控服务心跳
private String reportRest;
//实时日志推送
private String LogsRest;
//调用运行监控微服务shell脚本位置(注意:不建议修改)
private String shellPaht;
// 启动tomcat
......@@ -32,6 +35,13 @@ public class ServicesRest {
private String stopTomcatName;
// 监控tomcat
private String reportTomcatName;
// 监控tomcat
private String LogsTomcatName;
// 远程控制台url
private String Capability;
......
package com.cc.config;
/**
* Created by changc on 2018/9/18.
*/
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
/**
* 配置WebSocket
*/
@Configuration
//注解开启使用STOMP协议来传输基于代理(message broker)的消息,这时控制器支持使用@MessageMapping,就像使用@RequestMapping一样
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
//注册STOMP协议的节点(endpoint),并映射指定的url
public void registerStompEndpoints(StompEndpointRegistry registry) {
//注册一个STOMP的endpoint,并指定使用SockJS协议
registry.addEndpoint("/logss").setAllowedOrigins("*").withSockJS();
}
@Override
//配置消息代理(Message Broker)
public void configureMessageBroker(MessageBrokerRegistry registry) {
//点对点应配置一个/user消息代理,广播式应配置一个/topic消息代理
registry.enableSimpleBroker("/topic","/user");
//点对点使用的订阅前缀(客户端订阅路径上会体现出来),不设置的话,默认也是/user/
registry.setUserDestinationPrefix("/user");
}
}
\ No newline at end of file
......@@ -55,6 +55,8 @@ public class LoginController {
session.setAttribute("startTomcatName",servicesRest.getStartTomcatName());
session.setAttribute("stopTomcatName",servicesRest.getStopTomcatName());
session.setAttribute("reportTomcatName",servicesRest.getReportTomcatName());
session.setAttribute("logsRest",servicesRest.getLogsRest());
session.setAttribute("capability",servicesRest.getCapability());
return "redirect:/main";
}
else{
......
package com.cc.controller;
import com.cc.bean.ServicesRest;
import com.cc.bean.User;
import com.cc.common.XzxtRestResult;
import com.sun.deploy.net.HttpRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.cc.common.util.HttpClientUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
/**
* Created by changc on 2018/9/18.
*/
@Component
public class WebSocketController {
@Autowired
private SimpMessagingTemplate template;
@Autowired
private ServicesRest servicesRest;
//日志
// @Scheduled(cron = "*/60 * * * * ?") //30秒
// @Async("taskExecutor")
public void sendTopicMessage() {
System.out.println("后台广播推送!");
//调用日志服务ip, ipUsername,ipPassword,shellPaht,shellname,servletPath,kssj,jssj
String ip="2018-09-20 00:07:02";
String ipUsername="root";
String ipPassword="18234077206";
String servletPath="/usr/local/tomcat-portal";
String kssj="2018-09-20 00:06:57";
String jssj="2018-09-20 00:07:02";
Map<String, String> param = new HashMap<>();
param.put("ip", ip);
param.put("ipUsername",ipUsername);
param.put("ipPassword",ipPassword);
param.put("shellPaht",servicesRest.getShellPaht());
param.put("shellname",servicesRest.getLogsTomcatName());
param.put("servletPath",servletPath);
param.put("kssj",kssj);
param.put("jssj",jssj);
String json = HttpClientUtil.doGet(servicesRest.getLogsRest(), param);
//String json="五月 04, 2018 1:45:43 上午 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 信息 04, 2018 1:45:45 上午 org.apache.coyote.AbstractProtocol init 信息: Initiali";
String s1 = json.replaceAll("信息","<br>信息");
User user=new User();
user.setStaffname(s1);
this.template.convertAndSend("/topic/getResponse",user);
}
}
......@@ -34,15 +34,20 @@ mybatis:
# - classpath:sql/employee.sql
# 调用运行监控微服务url
service-rest:
startRest: "http://127.0.0.1:8081/service-rest/start"
stopRest: "http://127.0.0.1:8081/service-rest/stop"
reportRest: "http://127.0.0.1:8081/service-rest/report"
startRest: "http://localhost:8081/service-rest/start"
stopRest: "http://localhost:8081/service-rest/stop"
reportRest: "http://localhost:8081/service-rest/report"
LogsRest: "http://localhost:8081/service-rest/logs"
# 调用运行监控微服务shell脚本位置(注意:不建议修改)
shellPaht: "/usr/local/"
# 调用运行监控微服务shell脚本
startTomcatName: "startTomcat.sh"
stopTomcatName: "shutTomcat.sh"
reportTomcatName: "reportTomcat.sh"
LogsTomcatName: "tomcatLogs.sh"
# 远程控制台地址
Capability: "http://192.168.193.134:3001/"
ThreadPool:
#核心线程数
corePoolSize: 20
......
This source diff could not be displayed because it is too large. You can view the blob instead.
var stompClient = null;
//加载完浏览器后 调用connect(),打开双通道
$(function(){
//打开双通道
connect()
})
//强制关闭浏览器 调用websocket.close(),进行正常关闭
window.onunload = function() {
disconnect()
}
function connect(){
var socket = new SockJS('http://localhost:8081/logs'); //连接SockJS的endpoint名称为"endpointOyzc"
stompClient = Stomp.over(socket);//使用STMOP子协议的WebSocket客户端
stompClient.connect({},function(frame){//连接WebSocket服务端
console.log('Connected:' + frame);
//通过stompClient.subscribe订阅/topic/getResponse 目标(destination)发送的消息
stompClient.subscribe('/topic/getResponse',function(response){
showResponse(JSON.parse(response.body));
});
});
}
//关闭双通道
function disconnect(){
if(stompClient != null) {
stompClient.disconnect();
}
console.log("Disconnected");
}
function showResponse(message){
var response = $("#response");
var str=message.staffname;
response.html("");
response.html("<div>"+str+"</div>");
}
\ No newline at end of file
......@@ -155,14 +155,14 @@
<li class="list" >
<a href="javascript:;">
<i class="iconfont">&#xe6a3;</i>
日志管理
数据库管理
<i class="iconfont nav_right">&#xe697;</i>
</a>
<ul class="sub-menu" style="display:none">
<li>
<a href="./banner-list.html">
<i class="iconfont">&#xe6a7;</i>
日志分析
数据库监控
</a>
</li>
</ul>
......
......@@ -124,7 +124,8 @@
window.open("http://"+ip+":90");
}
function connect() {
window.open("http://192.168.193.134:3001/");
var url="${capability}";
window.open(url);
}
$(function(){
$.ajax({
......
......@@ -30,7 +30,7 @@
<div class="page-content" style="display: none">
<div class="content">
<table class="layui-hide" id="test" lay-filter="test" width="100%"></table>
<table class="layui-hide" id="test" lay-filter="test" width="98%"></table>
</div>
</div>
......@@ -77,7 +77,9 @@
<span>Jetty</span>
{{# } }}
</script>
<script type="text/html" id="barDemo4">
<a class="layui-btn layui-btn-xs" lay-event="logs">查看日志</a>
</script>
<script src="/layui/layui.js" charset="utf-8"></script>
......@@ -96,15 +98,16 @@
,limit: 10
,cols: [[
{type: 'checkbox', fixed: 'left',align:'center'}
,{field:'id', title:'服务id', width:100, fixed: 'left', align:'center',unresize: true, sort: true}
/* ,{field:'id', title:'服务id', width:100, fixed: 'left', align:'center',unresize: true, sort: true}*/
,{field:'applyName', title:'应用名称',align:'center', width:150, edit: 'text'}
,{field:'serviceName', title:'服务名称', width:100,align:'center', edit: 'text',templet:'#barDemo3'}
,{field:'port', title:'服务端口', width:150,align:'center', edit: 'text'}
,{field:'port', title:'服务端口', width:120,align:'center', edit: 'text'}
,{field:'servletPath', title:'服务位置', width:200,align:'center', edit: 'text'}
,{field:'serviceIp', title:'服务IP', width:200,align:'center', sort: true}
,{field:'sqlType', title:'SQL类型', width:150,align:'center', sort: true,templet:'#barDemo2'}
,{field:'sqlType', title:'SQL类型', width:120,align:'center', sort: true,templet:'#barDemo2'}
,{field:'status', title:'服务状态', width:150,align:'center', edit: 'text', templet:'#barDemo1'}
,{field: 'right', title:'操作',align:'center', toolbar: '#barDemo', width:200}
,{field: 'right', title:'操作',align:'center', toolbar: '#barDemo', width:140}
,{field: 'right', title:'操作',align:'center', toolbar: '#barDemo4', width:140}
]]
});
//头工具栏事件
......@@ -265,6 +268,10 @@
});
}})
}
else if(obj.event === 'logs'){
var url="${logsRest}";
window.open(url+"?ip="+data.serviceIp+"&ipUsername="+data.ipUsername+"&ipPassword="+data.ipPassword+"&servletPath="+data.servletPath);
}
});
});
......@@ -279,6 +286,7 @@
debugger;
if(data.status==201){
layer.msg("状态修改成功");
$('.layui-laypage-btn').click();//模拟点击
}else{
layer.msg("状态修改失败");
}
......
......@@ -3,4 +3,5 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<session-config> <session-timeout>0</session-timeout></session-config>
</web-app>
\ No newline at end of file
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<title>websocket.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html" charset="UTF-8">
<%-- <link rel="stylesheet" href="/layui/css/layui.css" media="all">
<link rel="stylesheet" href="/css/xadmin.css">
<link rel="stylesheet" href="/fenye/fenye.css" media="all">
<link rel="stylesheet" href="/fenye/font-awesome.min.css" media="all">
<script type="text/javascript" src="/jquery/jquery.min.js"></script>
<!-- 引入公共js-->
<script type="text/javascript" src="/js/common.js"></script>
<!-- 引入公共页面-->
<jsp:include page="/WEB-INF/common/index.jsp"></jsp:include>--%>
</head>
<body>
<%--<div class="page-content" style="display: none">
<div class="content">
<div id="response"></div>
</div>
</div>--%>
<div class="content">
<div id="response"></div>
</div>
<!-- 独立JS -->
<script type="text/javascript" src="/jquery/jquery.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/webSocket.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/sockjs.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/stomp.min.js" charset="utf-8"></script>
</body>
</html>
\ 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