From 45a0645559e996140143f82215580cd46f3f5f4c Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Mon, 13 Feb 2023 09:31:26 +0800 Subject: [PATCH] =?UTF-8?q?add:es=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/nl/AppRun.java | 1 + .../org/nl/ElasticSearchClientConfig.java | 68 --- .../main/java/org/nl/common/LogMdcFilter.java | 45 -- .../main/resources/config/application-dev.yml | 16 +- .../resources/config/application-prod.yml | 12 +- .../src/main/resources/config/application.yml | 1 + .../src/main/resources/logback-spring.xml | 6 +- nladmin-ui/src/views/loki/api/loki.js | 6 +- nladmin-ui/src/views/loki/view/index.vue | 424 +++++++----------- 9 files changed, 166 insertions(+), 413 deletions(-) delete mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/ElasticSearchClientConfig.java delete mode 100644 nladmin-system/nlsso-server/src/main/java/org/nl/common/LogMdcFilter.java diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java index 605e471..09fd9fa 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java @@ -11,6 +11,7 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; +import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.bind.annotation.RestController; diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/ElasticSearchClientConfig.java b/nladmin-system/nlsso-server/src/main/java/org/nl/ElasticSearchClientConfig.java deleted file mode 100644 index c4974de..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/ElasticSearchClientConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.nl; - -import org.apache.http.HttpHost; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHits; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.io.IOException; -import java.util.Map; - -/** - * @author ldjun - * @version 1.0 - * @date 2023年02月06日 18:49 - * @desc desc - */ -@Configuration -public class ElasticSearchClientConfig { - - - //配置RestHighLevelClient依赖到spring容器中待用 - @Bean - public RestHighLevelClient restHighLevelClient() { - RestHighLevelClient client = new RestHighLevelClient( - RestClient.builder( - //绑定本机,端口,协议,如果是ES集群,就配置多个 - new HttpHost("127.0.0.1", 9200, "http"))); - - return client; - } - - public static void main(String[] args) throws IOException { - // 指定ip 端口 - HttpHost[] httpHosts = {new HttpHost("47.111.78.178", 27017, "http")}; - RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(httpHosts)); - - SearchRequest searchRequest = new SearchRequest("logs-2023-02-06"); - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); - sourceBuilder.query(QueryBuilders.matchQuery("_id", "HzAeJoYBlkwLvExN1Vg4")); - searchRequest.source(sourceBuilder); - SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); - RestStatus restStatus = searchResponse.status(); - System.out.println(restStatus); - if (restStatus == RestStatus.OK) { - SearchHits searchHits = searchResponse.getHits(); - for (SearchHit searchHit: searchHits) { - System.out.println("id:" + searchHit.getId()); - System.out.println("index:" + searchHit.getIndex()); - System.out.println("score:" + searchHit.getScore()); - Map map = searchHit.getSourceAsMap(); - System.out.println("name:" + (String) map.get("name")); - System.out.println("city:" + (String) map.get("city")); - System.out.println("price:" + (Double) map.get("price")); - } - } - restHighLevelClient.close(); - } -} - diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/common/LogMdcFilter.java b/nladmin-system/nlsso-server/src/main/java/org/nl/common/LogMdcFilter.java deleted file mode 100644 index bf33136..0000000 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/common/LogMdcFilter.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.nl.common; - -/** - * @author ldjun - * @version 1.0 - * @date 2023年02月07日 11:05 - * @desc desc - */ - -import org.nl.common.utils.IdUtil; -import org.slf4j.MDC; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import java.io.IOException; -@WebFilter(urlPatterns = "/*", filterName = "logMdcFilter") -public class LogMdcFilter implements Filter { - private static final String UNIQUE_ID = "traceId"; - - @Override - public void init(FilterConfig filterConfig) { - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - boolean bInsertMDC = insertMDC(); - try { - chain.doFilter(request, response); - } finally { - if(bInsertMDC) { - MDC.remove(UNIQUE_ID); - } - } - } - - @Override - public void destroy() { - } - - private boolean insertMDC() { - String uniqueId = IdUtil.getStringId(); - MDC.put(UNIQUE_ID, uniqueId); - return true; - } -} diff --git a/nladmin-system/nlsso-server/src/main/resources/config/application-dev.yml b/nladmin-system/nlsso-server/src/main/resources/config/application-dev.yml index aa669af..459e160 100644 --- a/nladmin-system/nlsso-server/src/main/resources/config/application-dev.yml +++ b/nladmin-system/nlsso-server/src/main/resources/config/application-dev.yml @@ -21,8 +21,8 @@ spring: #uris: 172.31.185.110:9200,172.31.154.9:9200 #内网 # uris: 47.96.133.178:8200 #外网 uris: http://10.1.3.90:9200 #外网 -# username: elastic -# password: 123456 + # username: elastic + # password: 123456 datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource @@ -64,16 +64,8 @@ spring: enabled: true url-pattern: /druid/* reset-enable: false - filter: - stat: - enabled: true - # 记录慢SQL - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: true - wall: - config: - multi-statement-allow: true + filters: + DruidFilter,stat redis: #数据库索引 database: ${REDIS_DB:2} diff --git a/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml b/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml index 1a7570b..69cfb44 100644 --- a/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml +++ b/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml @@ -41,16 +41,8 @@ spring: reset-enable: false login-username: admin login-password: 123456 - filter: - stat: - enabled: true - # 记录慢SQL - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: true - wall: - config: - multi-statement-allow: true + filters: + DruidFilter,stat redis: #数据库索引 database: ${REDIS_DB:15} diff --git a/nladmin-system/nlsso-server/src/main/resources/config/application.yml b/nladmin-system/nlsso-server/src/main/resources/config/application.yml index 6dae405..92ea8fd 100644 --- a/nladmin-system/nlsso-server/src/main/resources/config/application.yml +++ b/nladmin-system/nlsso-server/src/main/resources/config/application.yml @@ -60,6 +60,7 @@ security: - /api/localStorage/pictures # 参数 - /api/param/getValueByCode + - /api/esLog/** mybatis-plus: configuration: map-underscore-to-camel-case: true diff --git a/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml b/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml index 042287f..0c9ec4c 100644 --- a/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml +++ b/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml @@ -56,7 +56,7 @@ https://juejin.cn/post/6844903775631572999 - http://47.96.133.178:8200/_bulk + http://10.1.3.90:9200/_bulk lms_log lms_log es-logger @@ -76,7 +76,7 @@ https://juejin.cn/post/6844903775631572999 system - lms + sso traceId @@ -118,7 +118,7 @@ https://juejin.cn/post/6844903775631572999 - + diff --git a/nladmin-ui/src/views/loki/api/loki.js b/nladmin-ui/src/views/loki/api/loki.js index f71149d..b5a3094 100644 --- a/nladmin-ui/src/views/loki/api/loki.js +++ b/nladmin-ui/src/views/loki/api/loki.js @@ -2,15 +2,15 @@ import request from '@/utils/request' export function getLogData(param) { return request({ - url: 'api/loki/logs', + url: '/api/esLog/query', method: 'post', data: param }) } -export function labelsValues() { +export function labelsValues(type) { return request({ - url: 'api/loki/labels/values', + url: '/api/esLog/labels/' + type, method: 'get' }) } diff --git a/nladmin-ui/src/views/loki/view/index.vue b/nladmin-ui/src/views/loki/view/index.vue index 054cd61..bad4f01 100644 --- a/nladmin-ui/src/views/loki/view/index.vue +++ b/nladmin-ui/src/views/loki/view/index.vue @@ -2,25 +2,73 @@
- - - + + + + + + + + + + - - + + + + + + + + + + + @@ -49,36 +98,29 @@ - - - - backward - forward - - - + - 查询{{ runStatu }} + 查询 {{ item.label }} @@ -90,10 +132,19 @@ - +
-
+
+ {{ log.system }} + {{ log.thread }} + {{ log.logLevel }} + {{ log.requestIp }} + {{ log.requestTime }} + {{ log.traceId }} + {{ log.requestMethod }} + {{ log.message }} +
@@ -104,39 +155,38 @@