diff --git a/wcs/nladmin-system/pom.xml b/wcs/nladmin-system/pom.xml index cce6ee81..ae175695 100644 --- a/wcs/nladmin-system/pom.xml +++ b/wcs/nladmin-system/pom.xml @@ -206,15 +206,15 @@ com.github.oshi oshi-core - 5.0.1 + 5.5.0 - - com.github.loki4j - loki-logback-appender-jdk8 - 1.3.2 - + + + + + org.apache.httpcomponents httpclient diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java b/wcs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java deleted file mode 100644 index e498cb66..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.nl.modules.loki.rest; - -import com.alibaba.fastjson.JSONObject; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.modules.common.annotation.RateLimiter; -import org.nl.modules.loki.service.LokiService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -/** - * @Author: lyd - * @Description: 日志监控 - * @Date: 2022-08-15 - */ -@RestController -@RequiredArgsConstructor -@Api(tags = "日志监控") -@RequestMapping("/api/loki") -@Slf4j -public class LokiController { - - private final LokiService lokiService; - - @GetMapping("/labels/values") - @ApiOperation("获取标签") - public ResponseEntity labelsValues() { - return new ResponseEntity<>(lokiService.getLabelsValues(), HttpStatus.OK); - } - - @PostMapping("/logs") - @ApiOperation("获取日志") - @RateLimiter(value = 1, timeout = 300) // 限流 - public ResponseEntity getLogData(@RequestBody JSONObject json) { - return new ResponseEntity<>(lokiService.getLogData(json), HttpStatus.OK); - } -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java b/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java deleted file mode 100644 index 10101c91..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.nl.modules.loki.service; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; - -/** - * @Author: lyd - * @Description: 服务类 - * @Date: 2022-08-15 - */ -public interface LokiService { - - /** - * 获取日志信息 - * @param json - * @return - */ - JSONObject getLogData(JSONObject json); - - /** - * 获取labels和values树 - * @return - */ - JSONArray getLabelsValues(); -} diff --git a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java b/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java deleted file mode 100644 index f6eeb49c..00000000 --- a/wcs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.nl.modules.loki.service.impl; - -import cn.hutool.core.util.CharsetUtil; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.RequiredArgsConstructor; -import org.nl.modules.loki.service.LokiService; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -/** - * @Author: lyd - * @Description: 实现类 - * @Date: 2022-08-15 - */ -@Service -@RequiredArgsConstructor -public class LokiServiceImpl implements LokiService { - - @Value("${loki.url}") - private String lokiUrl; - - @Value("${loki.systemName}") - private String systemName; - - @Override - public JSONObject getLogData(JSONObject json) { - String logLabel = ""; - String logLabelValue = ""; - Long start = 0L; - Long end = 0L; - String text = ""; - String limit = "100"; - String direction = "backward"; - if (json.get("logLabel") != null) logLabel = json.getString("logLabel"); - if (json.get("logLabelValue") != null) logLabelValue = json.getString("logLabelValue"); - if (json.get("text") != null) text = json.getString("text"); - if (json.get("start") != null) start = json.getLong("start"); - if (json.get("end") != null) end = json.getLong("end"); - if (json.get("limits") != null) limit = json.getString("limits"); - if (json.get("direction") != null) direction = json.getString("direction"); - /** - * 组织参数 - * 纳秒数 - * 1660037391880000000 - * 1641453208415000000 - * http://localhost:3100/loki/api/v1/query_range?query={host="localhost"} |= ``&limit=1500&start=1641453208415000000&end=1660027623419419002 - */ - JSONObject parse = null; - String query = lokiUrl + "/query_range?query={system=\"" + systemName + "\", " + logLabel + "=\"" + logLabelValue + "\"} |= `" + text + "`"; - String result = ""; - if (start==0L) { - result = HttpUtil.get(query + "&limit=" + limit + "&direction=" + direction, CharsetUtil.CHARSET_UTF_8); - } else { - result = HttpUtil.get(query + "&limit=" + limit + "&start=" + start + "&end=" + end + "&direction=" + direction, CharsetUtil.CHARSET_UTF_8); - } - try { - parse = (JSONObject) JSONObject.parse(result); - } catch (Exception e) { -// reslut的值可能为:too many outstanding requests,无法转化成Json - System.out.println("reslut:" + result); -// e.printStackTrace(); - } - return parse; - } - - /** - * 获取labels和values树 - * - * @return - */ - @Override - public JSONArray getLabelsValues() { - /** - * [{ - * label: - * value: - * children:[{ - * label - * value - * }] - * }] - */ - JSONArray result = new JSONArray(); - // 获取所有标签 - String labelString = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8); - JSONObject parse = (JSONObject) JSONObject.parse(labelString); - JSONArray labels = parse.getJSONArray("data"); - for (int i=0; i - + - + @@ -68,23 +68,23 @@ https://juejin.cn/post/6844903775631572999 - - 1000 - - ${LOKI_URL}/push - - - - - ${log.pattern} - - true - - + + + + + + + + + + + + + + + + + @@ -111,21 +111,21 @@ https://juejin.cn/post/6844903775631572999 - + - + - + - + @@ -165,20 +165,20 @@ https://juejin.cn/post/6844903775631572999 - + - + - + - +