init project v1.0.0
This commit is contained in:
@@ -0,0 +1 @@
|
||||
*.iml
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,56 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-monitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>log-center</artifactId>
|
||||
<dependencies>
|
||||
<!-- 公共实体类模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-common-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- swagger -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-swagger2-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.central;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class LogApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LogApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.central.log.config;
|
||||
|
||||
import com.central.common.exception.DefaultExceptionAdvice;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
||||
/**
|
||||
* 统一异常处理
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2018/12/22
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class ExceptionAdvice extends DefaultExceptionAdvice {
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.central.log.controller;
|
||||
|
||||
import com.central.common.model.PageResult;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 日志父类
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
public class LogController<E> {
|
||||
public PageResult<E> getPage(@RequestParam Map<String, Object> params, BoolQueryBuilder builder, ElasticsearchRepository repository) {
|
||||
// 分页参数
|
||||
Pageable pageable = PageRequest.of(MapUtils.getInteger(params, "page") - 1, MapUtils.getInteger(params, "limit")
|
||||
, Sort.Direction.DESC, "timestamp");
|
||||
SearchQuery query = new NativeSearchQueryBuilder().withQuery(builder).withPageable(pageable).build();
|
||||
Page<E> result = (Page<E>)repository.search(query);
|
||||
return PageResult.<E>builder().data(result.getContent()).code(0).count(result.getTotalElements()).build();
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.central.log.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.log.dao.SlowQueryLogDao;
|
||||
import com.central.log.model.SlowQueryLog;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 慢查询日志
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@RestController
|
||||
public class SlowQueryLogController extends LogController<SlowQueryLog> {
|
||||
private static final String ES_PARAM_QUERY = "query_str";
|
||||
|
||||
@Autowired
|
||||
public SlowQueryLogDao logDao;
|
||||
|
||||
@ApiOperation(value = "系统日志查询列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
|
||||
})
|
||||
@GetMapping(value = "/slowQueryLog")
|
||||
public PageResult<SlowQueryLog> getPage(@RequestParam Map<String, Object> params) {
|
||||
BoolQueryBuilder builder = QueryBuilders.boolQuery();
|
||||
String searchKey = (String) params.get("searchKey");
|
||||
String searchValue = (String) params.get("searchValue");
|
||||
if (StrUtil.isNotEmpty(searchKey)) {
|
||||
if (ES_PARAM_QUERY.equals(searchKey)) {
|
||||
// 模糊查询
|
||||
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_QUERY, searchValue.toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
return super.getPage(params, builder, logDao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.central.log.controller;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.log.dao.SysLogDao;
|
||||
import com.central.log.model.SysLog;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 系统日志
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@RestController
|
||||
public class SysLogController extends LogController<SysLog> {
|
||||
private static final String ES_PARAM_MESSAGE = "message";
|
||||
private static final String ES_PARAM_LOG_LEVEL = "logLevel";
|
||||
private static final String ES_PARAM_APP_NAME = "appName";
|
||||
private static final String ES_PARAM_CLASSNAME = "classname";
|
||||
|
||||
@Autowired
|
||||
public SysLogDao logDao;
|
||||
|
||||
@ApiOperation(value = "系统日志查询列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")
|
||||
})
|
||||
@GetMapping(value = "/sysLog")
|
||||
public PageResult<SysLog> getPage(@RequestParam Map<String, Object> params) {
|
||||
BoolQueryBuilder builder = QueryBuilders.boolQuery();
|
||||
String searchKey = (String) params.get("searchKey");
|
||||
String searchValue = (String) params.get("searchValue");
|
||||
if (StrUtil.isNotEmpty(searchKey)) {
|
||||
if (ES_PARAM_MESSAGE.equals(searchKey)) {
|
||||
// 整词模糊查询 日志信息
|
||||
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_MESSAGE, searchValue));
|
||||
}
|
||||
if (ES_PARAM_LOG_LEVEL.equals(searchKey)) {
|
||||
// 模糊查询
|
||||
builder.must(QueryBuilders.matchPhraseQuery(ES_PARAM_LOG_LEVEL, searchValue.toUpperCase()));
|
||||
}
|
||||
if (ES_PARAM_APP_NAME.equals(searchKey)) {
|
||||
// 模糊查询
|
||||
builder.must(QueryBuilders.fuzzyQuery(ES_PARAM_APP_NAME, searchValue));
|
||||
}
|
||||
if (ES_PARAM_CLASSNAME.equals(searchKey)) {
|
||||
// 模糊查询
|
||||
builder.must(QueryBuilders.fuzzyQuery(ES_PARAM_CLASSNAME, searchValue));
|
||||
}
|
||||
}
|
||||
|
||||
return super.getPage(params, builder, logDao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.central.log.dao;
|
||||
|
||||
import com.central.log.model.SlowQueryLog;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Component
|
||||
public interface SlowQueryLogDao extends ElasticsearchRepository<SlowQueryLog, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.central.log.dao;
|
||||
|
||||
import com.central.log.model.SysLog;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@Component
|
||||
public interface SysLogDao extends ElasticsearchRepository<SysLog, String> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.central.log.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 慢查询日志对象
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Data
|
||||
@Document(indexName = "mysql-slowlog-*", type = "doc")
|
||||
public class SlowQueryLog {
|
||||
@Id
|
||||
private String id;
|
||||
private Date timestamp;
|
||||
private String query_str;
|
||||
private String user;
|
||||
private String clientip;
|
||||
private Float query_time;
|
||||
private Float lock_time;
|
||||
private Long rows_sent;
|
||||
private Long rows_examined;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.central.log.model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 系统日志对象
|
||||
*
|
||||
* @author zlt
|
||||
*/
|
||||
@Data
|
||||
@Document(indexName = "sys-log-*", type = "doc")
|
||||
public class SysLog {
|
||||
@Id
|
||||
private String id;
|
||||
private Date timestamp;
|
||||
private String message;
|
||||
private String threadName;
|
||||
private String serverPort;
|
||||
private String serverIp;
|
||||
private String logLevel;
|
||||
private String appName;
|
||||
private String classname;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
spring:
|
||||
data:
|
||||
elasticsearch:
|
||||
cluster-name: ${zlt.elasticsearch.cluster-name}
|
||||
cluster-nodes: ${zlt.elasticsearch.cluster-nodes}
|
||||
repositories:
|
||||
enabled: true
|
||||
|
||||
zlt:
|
||||
swagger:
|
||||
enabled: true
|
||||
title: 日志中心
|
||||
description: 日志中心接口文档
|
||||
version: 1.0
|
||||
base-package: com.central.log.controller
|
||||
@@ -0,0 +1,14 @@
|
||||
server:
|
||||
port: 7200
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: log-center
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
file-extension: yml
|
||||
shared-dataids: common.yml
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
@@ -0,0 +1,17 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>central-platform</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>zlt-monitor</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<!-- 应用监控 -->
|
||||
<module>sc-admin</module>
|
||||
<!-- 日志中心 -->
|
||||
<module>log-center</module>
|
||||
</modules>
|
||||
</project>
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
*.iml
|
||||
@@ -0,0 +1,63 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-monitor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>sc-admin</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.central.gateway;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
*/
|
||||
@EnableAdminServer
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class MonitorApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MonitorApp.class, args);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.central.gateway.monitor.config;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.AdminServerProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2019/1/8
|
||||
*/
|
||||
@Configuration
|
||||
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
|
||||
private final String adminContextPath;
|
||||
|
||||
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
|
||||
this.adminContextPath = adminServerProperties.getContextPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
successHandler.setTargetUrlParameter("redirectTo");
|
||||
|
||||
http.authorizeRequests()
|
||||
.antMatchers(adminContextPath + "/assets/**").permitAll()
|
||||
.antMatchers(adminContextPath + "/login").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
|
||||
.logout().logoutUrl(adminContextPath + "/logout").and()
|
||||
.httpBasic()
|
||||
.and()
|
||||
.headers()
|
||||
.frameOptions()
|
||||
.disable()
|
||||
.and()
|
||||
.csrf().disable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
server:
|
||||
port: 6500
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: sc-admin
|
||||
security:
|
||||
user:
|
||||
name: 'admin'
|
||||
password: 'admin'
|
||||
cloud:
|
||||
nacos:
|
||||
config:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
file-extension: yml
|
||||
shared-dataids: common.yml
|
||||
discovery:
|
||||
server-addr: ${zlt.nacos.server-addr}
|
||||
metadata:
|
||||
user.name: ${spring.security.user.name}
|
||||
user.password: ${spring.security.user.password}
|
||||
Reference in New Issue
Block a user