Commit ae5e426e by 黄明步

新增服务器资源总监控。修改文件下载方式为minio。

parent f1c5a835
......@@ -33,6 +33,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
......@@ -91,13 +96,7 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-maven-plugin &ndash;&gt;
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.2</version>
</dependency>-->
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
......@@ -201,7 +200,25 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.10.0</version>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.2</version>
<exclusions>
<exclusion>
<artifactId>kotlin-stdlib-common</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.70</version>
<scope>compile</scope>
</dependency>
</dependencies>
......
package com.gxmailu.ocrCloudPlatform.config;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
/**
* @author Hmb
* @version 1.0.0
* @since 2024/7/2 22:36:53
*/
@Configuration
public class MinioConfig {
@Autowired
private MinioProperties minioProperties;
@Bean
public Map<String, MinioClient> minioClients() {
Map<String, MinioClient> clients = new HashMap<>();
for (MinioProperties.MinioClientConfig config : minioProperties.getClients()) {
MinioClient client = MinioClient.builder()
.endpoint(config.getEndpoint())
.credentials(config.getAccessKey(), config.getSecretKey())
.build();
clients.put(config.getName(), client);
}
return clients;
}
}
package com.gxmailu.ocrCloudPlatform.config;
import lombok.*;
import org.checkerframework.checker.units.qual.A;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author Hmb
* @version 1.0.0
* @since 2024/7/2 22:34:28
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioProperties {
private List<MinioClientConfig> clients;
@Data
public static class MinioClientConfig {
private String name;
private String endpoint;
private String accessKey;
private String secretKey;
}
}
......@@ -47,25 +47,21 @@ public class RetransmissionController {
@PostMapping("/ofs/api/sync/v1/pdf")
public void downloadDoubleDeckPdf(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
// retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService.downloadPdfNew(body, response);
}
@PostMapping("/ofs/api/sync/v1/ft/pdf")
public void downloadDoubleDeckPdfByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
// retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService.downloadPdfNew(body, response);
}
@PostMapping("/ofs/api/sync/v1/ofd")
public void downloadDoubleDeckOfd(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
// retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService.downloadOfdNew(body, response);
}
@PostMapping("/ofs/api/sync/v1/ft/ofd")
public void downloadDoubleDeckOfdByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
// retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService.downloadOfdNew(body, response);
}
......
......@@ -53,4 +53,14 @@ public class StatController {
public Result getServerMonitoring(@RequestParam(value = "time", required = false) Long time) {
return statService.getServerMonitoring(time);
}
@ApiOperation(value = "获取服务器监控总数据")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "time", value = "秒级别的时间戳,不传该值则默认当前时刻", dataType = "Long")
})
@GetMapping("/getAllMonitoring")
public Result getAllMonitoring(@RequestParam(value = "time", required = false) Long time) {
return statService.getAllMonitoring(time);
}
}
package com.gxmailu.ocrCloudPlatform.service;
import io.minio.GetObjectArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
/**
* @author Hmb
* @version 1.0.0
* @since 2024/7/2 22:39:18
*/
@Service
public class MinioService {
private final Map<String, MinioClient> minioClients;
@Autowired
public MinioService(Map<String, MinioClient> minioClients) {
this.minioClients = minioClients;
}
public InputStream downloadFile(String clientName, String bucketName, String objectName) throws MinioException, IOException, NoSuchAlgorithmException, InvalidKeyException {
MinioClient minioClient = minioClients.get(clientName);
if (minioClient == null) {
throw new IllegalArgumentException("未知的Minio客户端: " + clientName);
}
return minioClient.getObject(
GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build());
}
}
......@@ -24,8 +24,10 @@ import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.entity.ServerInfo;
import com.gxmailu.ocrCloudPlatform.entity.TmpRecordByTrigger;
import com.gxmailu.ocrCloudPlatform.mapper.*;
import com.gxmailu.ocrCloudPlatform.service.MinioService;
import com.gxmailu.ocrCloudPlatform.service.ServerInfoService;
import com.gxmailu.ocrCloudPlatform.vo.OcrResult;
import io.minio.errors.MinioException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,6 +42,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
......@@ -89,6 +92,9 @@ public class RetransmissionService {
@Autowired
private ElasticSearchService elasticSearchService;
@Autowired
private MinioService minioService;
@Value("${temp.dir}")
private String tempDir;
......@@ -449,12 +455,20 @@ public class RetransmissionService {
String serverIp = appAbilityRecordAll.getServerIp();
String dstUrl = appAbilityRecordAll.getDstUrl();
String objName = appAbilityRecordAll.getPdf();
String fileUrl = StrUtil.format("http://{}:9000/{}/{}", serverIp, dstUrl, objName);
byte[] bytes = HttpUtil.downloadBytes(fileUrl);
try (OutputStream outputStream = response.getOutputStream()) {
outputStream.write(bytes);
try (InputStream inputStream = minioService.downloadFile(serverIp, dstUrl, objName);
OutputStream outputStream = response.getOutputStream()) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + objName);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
} catch (Exception e) {
log.error("在处理ID为 {} 的PDF下载过程中发生异常", id, e);
}
......@@ -496,15 +510,20 @@ public class RetransmissionService {
String serverIp = appAbilityRecordAll.getServerIp();
String dstUrl = appAbilityRecordAll.getDstUrl();
String objName = appAbilityRecordAll.getPdf().substring(0, appAbilityRecordAll.getPdf().lastIndexOf(".")) + ".ofd";
String fileUrl = StrUtil.format("http://{}:9000/{}/{}", serverIp, dstUrl, objName);
try (InputStream inputStream = minioService.downloadFile(serverIp, dstUrl, objName);
OutputStream outputStream = response.getOutputStream()) {
byte[] bytes = HttpUtil.downloadBytes(fileUrl);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + objName);
try (OutputStream outputStream = response.getOutputStream()) {
outputStream.write(bytes);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
} catch (Exception e) {
log.error("在处理ID为 {} 的PDF下载过程中发生异常", id, e);
log.error("在处理ID为 {} 的OFD下载过程中发生异常", id, e);
}
}
......
......@@ -87,3 +87,79 @@ elasticsearch:
http: http
username: elastic
password: vvOxUJVNwxoN4FeIQeYC
minio:
clients:
- name: 147.1.7.131
endpoint: http://147.1.7.131:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.132
endpoint: http://147.1.7.132:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.133
endpoint: http://147.1.7.133:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.136
endpoint: http://147.1.7.136:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.137
endpoint: http://147.1.7.137:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.138
endpoint: http://147.1.7.138:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.139
endpoint: http://147.1.7.139:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.140
endpoint: http://147.1.7.140:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.141
endpoint: http://147.1.7.141:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.142
endpoint: http://147.1.7.142:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.143
endpoint: http://147.1.7.143:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.7.144
endpoint: http://147.1.7.144:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.1.6.152
endpoint: http://147.1.6.152:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.2.4.1
endpoint: http://147.2.4.1:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.2.4.2
endpoint: http://147.2.4.2:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.2.4.5
endpoint: http://147.2.4.5:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.2.4.18
endpoint: http://147.2.4.18:9000
accessKey: admin
secretKey: Docimax@123
- name: 147.2.4.19
endpoint: http://147.2.4.19:9000
accessKey: admin
secretKey: Docimax@123
......@@ -4,7 +4,7 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: Dk2019!23456
password: ZqTestDB#2024#
url: jdbc:mysql://119.45.183.210:13308/ocr_cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
initial-size: 3 # 初始化时建立物理连接的个数
min-idle: 5 # 最小连接池数量
......@@ -40,7 +40,7 @@ spring:
port: 6379
database: 0
password:
jedis:
lettuce:
pool:
max-active: 128
max-wait: 60s
......@@ -72,6 +72,13 @@ elasticsearch:
username: elastic
password: RQuT4eQIdIZ57waX9f87
minio:
clients:
- name: 127.0.0.1
endpoint: http://127.0.0.1:9000
accessKey: minioadmin
secretKey: minioadmin
#eureka:
# client:
# enabled: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment