优化log机制
This commit is contained in:
parent
7c9a5b0d26
commit
f9f9575e59
@ -114,15 +114,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version><!-- 使用最新版本 -->
|
|
||||||
<configuration>
|
|
||||||
<source>11</source>
|
|
||||||
<target>11</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.imdroid.sideslope.service;
|
package com.imdroid.sideslope.service;
|
||||||
|
|
||||||
|
import com.imdroid.common.util.ThreadManager;
|
||||||
import com.imdroid.secapi.dto.GnssSingleData;
|
import com.imdroid.secapi.dto.GnssSingleData;
|
||||||
import com.imdroid.secapi.dto.GnssSingleDataMapper;
|
import com.imdroid.secapi.dto.GnssSingleDataMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -32,7 +33,6 @@ public class GnssSingleBufferServiceImpl implements GnssSingleBufferService {
|
|||||||
buffer.add(data);
|
buffer.add(data);
|
||||||
if (buffer.size() >= BUFFER_SIZE) {
|
if (buffer.size() >= BUFFER_SIZE) {
|
||||||
// 溢出时直接保存
|
// 溢出时直接保存
|
||||||
// 此处暂定,但很有必要引入一个线程来保存,避免阻塞主线程
|
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,12 +48,19 @@ public class GnssSingleBufferServiceImpl implements GnssSingleBufferService {
|
|||||||
try {
|
try {
|
||||||
List<GnssSingleData> batchList = new ArrayList<>(buffer);
|
List<GnssSingleData> batchList = new ArrayList<>(buffer);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
// 由于每秒写数据库操作频繁,这里采用批量保存的方式
|
|
||||||
saveBatch(batchList);
|
|
||||||
|
|
||||||
logger.debug("批量插入{}条数据成功", batchList.size());
|
// 数据库操作异步执行,不阻塞主线程
|
||||||
|
ThreadManager.getSingleThreadPool("gnss-single-save").submit(() -> {
|
||||||
|
try {
|
||||||
|
saveBatch(batchList);
|
||||||
|
logger.debug("批量插入{}条数据成功", batchList.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("批量插入数据失败", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("批量插入数据失败", e);
|
logger.error("线程创建失败", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,3 +34,5 @@ mybatis-plus.configuration.map-underscore-to-camel-case=false
|
|||||||
xfz.server.host = 171.106.48.63
|
xfz.server.host = 171.106.48.63
|
||||||
xfz.server.port = 52000
|
xfz.server.port = 52000
|
||||||
xfz.server.data.send = false
|
xfz.server.data.send = false
|
||||||
|
|
||||||
|
warning.log.directory=./log
|
||||||
@ -20,7 +20,7 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="debug">
|
<root level="info">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
</root>
|
</root>
|
||||||
<logger name="org.springframework" level="warn" />
|
<logger name="org.springframework" level="warn" />
|
||||||
|
|||||||
@ -155,7 +155,7 @@
|
|||||||
</exclude>
|
</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>11</source><target>11</target></configuration></plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -80,6 +82,11 @@ public class GnssSingleDataController extends BasicController implements CommonE
|
|||||||
return this.pageList(session, page, limit, searchParams);
|
return this.pageList(session, page, limit, searchParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/gnss/data/single/export")
|
||||||
|
@ResponseBody
|
||||||
|
public void exportData(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
this.export(session, request, response);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<GnssSingleData> getEntityClass() {
|
public Class<GnssSingleData> getEntityClass() {
|
||||||
|
|||||||
@ -46,3 +46,5 @@ aliyun.oss.accessKey = LTAI4G6hmpX7h9hQvUnwKWxj
|
|||||||
aliyun.oss.accessSecret = GHVzHKLLor8i5ZR1qyeoi4KMf3mjHb
|
aliyun.oss.accessSecret = GHVzHKLLor8i5ZR1qyeoi4KMf3mjHb
|
||||||
aliyun.oss.bucket = imdroid-device-management
|
aliyun.oss.bucket = imdroid-device-management
|
||||||
aliyun.oss.publicReadUrl = https://imdroid-device-management.oss-cn-shanghai.aliyuncs.com
|
aliyun.oss.publicReadUrl = https://imdroid-device-management.oss-cn-shanghai.aliyuncs.com
|
||||||
|
|
||||||
|
warning.log.directory=./log
|
||||||
@ -67,6 +67,7 @@ CREATE TABLE IF NOT EXISTS `gnssdevices` (
|
|||||||
`appver` varchar(16) DEFAULT NULL COMMENT '固件版本',
|
`appver` varchar(16) DEFAULT NULL COMMENT '固件版本',
|
||||||
`imei` varchar(16) DEFAULT NULL,
|
`imei` varchar(16) DEFAULT NULL,
|
||||||
`model` smallint DEFAULT 0,
|
`model` smallint DEFAULT 0,
|
||||||
|
`loggingmode` smallint DEFAULT 0 COMMENT '日志模式: 0-精简模式(仅D3F0和D3F2), 1-完整模式',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
@ -320,3 +321,17 @@ CREATE TABLE IF NOT EXISTS `ApiKey` (
|
|||||||
`tenantname` varchar(100) DEFAULT NULL,
|
`tenantname` varchar(100) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `gnssdevicesinglerecords` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||||
|
`deviceid` varchar(64) NOT NULL COMMENT '设备ID',
|
||||||
|
`createtime` datetime(3) NOT NULL COMMENT '创建时间',
|
||||||
|
`model` smallint NOT NULL COMMENT '设备型号: 0-F9P(G505), 1-博通(G510)',
|
||||||
|
`x` double NOT NULL COMMENT 'GGA时是latitude, ECEF时是x',
|
||||||
|
`y` double NOT NULL COMMENT 'GGA时是longitude, ECEF时是y',
|
||||||
|
`z` double NOT NULL COMMENT 'GGA时是altitude, ECEF时是z',
|
||||||
|
`status` int NOT NULL DEFAULT '0' COMMENT 'GGA: 0初始化,1单点定位,2码差分,3无效PPS,4固定解,5浮点解,6估算,7人工固定,8模拟,9WAAS差分; ECEF: 0无B562,1浮点解,2固定解',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_deviceid_createtime` (`deviceid`,`createtime`),
|
||||||
|
KEY `idx_createtime` (`createtime`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='GNSS单次解算记录表';
|
||||||
@ -149,7 +149,7 @@
|
|||||||
// 监听导出操作
|
// 监听导出操作
|
||||||
form.on('submit(data-export-btn)', function (data) {
|
form.on('submit(data-export-btn)', function (data) {
|
||||||
var result = $('#searchFrm').serialize();
|
var result = $('#searchFrm').serialize();
|
||||||
var u = "/gnss/data/calc/export?" + result;
|
var u = "/gnss/data/single/export?" + result;
|
||||||
window.open(u, "_blank");
|
window.open(u, "_blank");
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class WarningLogExecutor {
|
public class WarningLogExecutor {
|
||||||
|
|
||||||
@ -32,14 +33,15 @@ public class WarningLogExecutor {
|
|||||||
initializeWarningFile(warningFile, keyword, warningTypeName);
|
initializeWarningFile(warningFile, keyword, warningTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 找到日志文件
|
try (Stream<Path> logFilesStream = Files.list(Paths.get(logDirectory))) {
|
||||||
List<Path> logFiles = Files.list(Paths.get(logDirectory))
|
List<Path> logFiles = logFilesStream
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.filter(path -> path.getFileName().toString().matches("sideslopertcm(\\.\\d{4}-\\d{2}-\\d{2}\\.\\d+)?\\.log"))
|
.filter(path -> path.getFileName().toString().matches("sideslopertcm(\\.\\d{4}-\\d{2}-\\d{2}\\.\\d+)?\\.log"))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (Path logFile : logFiles) {
|
for (Path logFile : logFiles) {
|
||||||
executor.submit(() -> processFile(logFile, keyword, warningTypeName, warningFile));
|
executor.submit(() -> processFile(logFile, keyword, warningFile));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -67,7 +69,7 @@ public class WarningLogExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFile(Path logFile, String keyword, String warningTypeName, Path warningFile) {
|
private void processFile(Path logFile, String keyword, Path warningFile) {
|
||||||
try (BufferedReader reader = Files.newBufferedReader(logFile);
|
try (BufferedReader reader = Files.newBufferedReader(logFile);
|
||||||
BufferedWriter writer = Files.newBufferedWriter(warningFile,
|
BufferedWriter writer = Files.newBufferedWriter(warningFile,
|
||||||
StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
|
StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
|
||||||
|
|||||||
@ -100,14 +100,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>11</source>
|
|
||||||
<target>11</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -20,3 +20,5 @@ app.format.time = HH:mm:ss
|
|||||||
app.format.datetime = yyyy-MM-dd HH:mm:ss
|
app.format.datetime = yyyy-MM-dd HH:mm:ss
|
||||||
|
|
||||||
mybatis-plus.configuration.map-underscore-to-camel-case=false
|
mybatis-plus.configuration.map-underscore-to-camel-case=false
|
||||||
|
|
||||||
|
netty.test.port = 9917
|
||||||
Loading…
x
Reference in New Issue
Block a user