更新日志监控

This commit is contained in:
lyd
2022-08-17 10:01:57 +08:00
parent 3bd5e9827c
commit 7701d9f0ba
4 changed files with 64 additions and 19 deletions

View File

@@ -20,6 +20,9 @@ public class LokiServiceImpl implements LokiService {
@Value("${loki.url}")
private String lokiUrl;
@Value("${loki.systemName}")
private String systemName;
@Override
public JSONObject getLabels() {
String result = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8);
@@ -58,7 +61,7 @@ public class LokiServiceImpl implements LokiService {
* 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={" + logLabel + "=\"" + logLabelValue + "\"} |= `" + text + "`";
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);

View File

@@ -161,4 +161,5 @@ jetcache:
- redis://127.0.0.1:6379
loki:
url: http://localhost:3100/loki/api/v1
systemName: acs

View File

@@ -15,7 +15,9 @@ https://juejin.cn/post/6844903775631572999
value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
<springProperty scope="context" name="lokiUrl" source="loki.url"/>
<springProperty scope="context" name="systemName" source="loki.systemName"/>
<property name="LOKI_URL" value="${lokiUrl}"/>
<property name="SYSTEM_NAME" value="${systemName}"/>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${logPath}"/>
<!--引入默认的一些设置-->
@@ -70,7 +72,7 @@ https://juejin.cn/post/6844903775631572999
</http>
<format>
<label>
<pattern>root=root,level=%level,logType=%X{log_file_type:-logType},device=%X{device_code_log:-device}</pattern>
<pattern>system=${SYSTEM_NAME},level=%level,logType=%X{log_file_type:-logType},device=%X{device_code_log:-device}</pattern>
</label>
<message>
<pattern>${log.pattern}</pattern>