fix:data存储预警改造xxljob
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
package com.sdm.data.config.xxljob;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.timeout}")
|
||||||
|
private int timeout;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.enabled}")
|
||||||
|
private Boolean enabled;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appname;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.address}")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
@Value("${xxl.job.executor.excludedpackage}")
|
||||||
|
private String excludedPackage;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobSpringExecutor.setTimeout(timeout);
|
||||||
|
xxlJobSpringExecutor.setEnabled(enabled);
|
||||||
|
xxlJobSpringExecutor.setAppname(appname);
|
||||||
|
xxlJobSpringExecutor.setAddress(address);
|
||||||
|
xxlJobSpringExecutor.setIp(ip);
|
||||||
|
xxlJobSpringExecutor.setPort(port);
|
||||||
|
xxlJobSpringExecutor.setLogPath(logPath);
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
xxlJobSpringExecutor.setExcludedPackage(excludedPackage);
|
||||||
|
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
|
||||||
|
*
|
||||||
|
* 1、引入依赖:
|
||||||
|
* <dependency>
|
||||||
|
* <groupId>org.springframework.cloud</groupId>
|
||||||
|
* <artifactId>spring-cloud-commons</artifactId>
|
||||||
|
* <version>${version}</version>
|
||||||
|
* </dependency>
|
||||||
|
*
|
||||||
|
* 2、配置文件,或者容器启动变量
|
||||||
|
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
|
||||||
|
*
|
||||||
|
* 3、获取IP
|
||||||
|
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.sdm.data.schedule;
|
||||||
|
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DataStorageMonitorSchedule {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataStorageMonitorScheduleExcutor dataStorageMonitorScheduleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时筛选存储空间达到阈值的用户 发送告警消息
|
||||||
|
*/
|
||||||
|
@XxlJob("dataStorageMonitorHandler")
|
||||||
|
public void checkDataStorageSpaceAndSendAlert() throws Exception {
|
||||||
|
log.info("开始执行定时筛选存储空间达到阈值的用户任务");
|
||||||
|
// 业务逻辑方法调度
|
||||||
|
dataStorageMonitorScheduleService.run();
|
||||||
|
log.info("定时筛选存储空间达到阈值的用户任务执行完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
package com.sdm.data.job;
|
package com.sdm.data.schedule;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.sdm.common.common.SdmResponse;
|
import com.sdm.common.common.SdmResponse;
|
||||||
@@ -12,33 +11,30 @@ import com.sdm.common.feign.impl.system.SysUserFeignClientImpl;
|
|||||||
import com.sdm.common.service.UserNameCacheService;
|
import com.sdm.common.service.UserNameCacheService;
|
||||||
import com.sdm.data.model.entity.FileStorageQuota;
|
import com.sdm.data.model.entity.FileStorageQuota;
|
||||||
import com.sdm.data.service.DataStorageAnalysis;
|
import com.sdm.data.service.DataStorageAnalysis;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@Service
|
||||||
public class DataStorageMonitorJob {
|
public class DataStorageMonitorScheduleExcutor {
|
||||||
|
|
||||||
private final DataStorageAnalysis dataStorageAnalysis;
|
@Autowired
|
||||||
private final MessageFeignClientImpl messageFeignClient;
|
private DataStorageAnalysis dataStorageAnalysis;
|
||||||
private final SysUserFeignClientImpl sysUserFeignClient;
|
@Autowired
|
||||||
private final UserNameCacheService userNameCacheService;
|
private MessageFeignClientImpl messageFeignClient;
|
||||||
|
@Autowired
|
||||||
|
private SysUserFeignClientImpl sysUserFeignClient;
|
||||||
|
@Autowired
|
||||||
|
private UserNameCacheService userNameCacheService;
|
||||||
|
|
||||||
/**
|
public void run() {
|
||||||
* 定时筛选存储空间达到阈值的用户 发送告警消息
|
|
||||||
*/
|
|
||||||
@Scheduled(cron = "${data.storage-monitor.cron:0 */10 * * * ?}")
|
|
||||||
public void checkDataStorageSpaceAndSendAlert() {
|
|
||||||
log.info("开始执行定时筛选存储空间达到阈值的用户任务");
|
|
||||||
try {
|
try {
|
||||||
SdmResponse<List<FileStorageQuota>> sdmResponse = dataStorageAnalysis.listAllUserQuotaForJob();
|
SdmResponse<List<FileStorageQuota>> sdmResponse = dataStorageAnalysis.listAllUserQuotaForJob();
|
||||||
if (CollectionUtils.isNotEmpty(sdmResponse.getData())) {
|
if (CollectionUtils.isNotEmpty(sdmResponse.getData())) {
|
||||||
@@ -73,11 +69,9 @@ public class DataStorageMonitorJob {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
log.info("定时筛选存储空间达到阈值的用户任务执行完成");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("定时筛选存储空间达到阈值的用户任务执行失败", e);
|
log.error("定时筛选存储空间达到阈值的用户任务执行失败", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -132,4 +132,35 @@ security:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
storage-monitor:
|
storage-monitor:
|
||||||
cron: 0 0 0/1 * * ?
|
cron: 0 0 0/1 * * ?
|
||||||
|
|
||||||
|
|
||||||
|
# xxljob 配置开始
|
||||||
|
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
# 调度中心地址列表
|
||||||
|
addresses: http://192.168.190.161:7110/xxl-job-admin
|
||||||
|
# 调度中心访问令牌
|
||||||
|
accessToken: default_token
|
||||||
|
# xxl-job 超时时间(秒),默认3秒
|
||||||
|
timeout: 3
|
||||||
|
executor:
|
||||||
|
# 执行器是否启用,默认true
|
||||||
|
enabled: true
|
||||||
|
# 执行器应用名称 服务名-job-executor
|
||||||
|
appname: data-job-executor
|
||||||
|
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||||
|
address:
|
||||||
|
# 执行器IP
|
||||||
|
ip:
|
||||||
|
# 执行器端口,为了好记,web服务端口+1000
|
||||||
|
port: 8104
|
||||||
|
# 执行器日志路径
|
||||||
|
logpath: /home/app/data/xxljob
|
||||||
|
# 执行器日志保留天数
|
||||||
|
logretentiondays: 14
|
||||||
|
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||||
|
excludedpackage:
|
||||||
|
# xxljob 配置结束
|
||||||
@@ -132,4 +132,35 @@ security:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
storage-monitor:
|
storage-monitor:
|
||||||
cron: 0 0 0/1 * * ?
|
cron: 0 0 0/1 * * ?
|
||||||
|
|
||||||
|
|
||||||
|
# xxljob 配置开始
|
||||||
|
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
# 调度中心地址列表
|
||||||
|
addresses: http://192.168.65.161:7110/xxl-job-admin
|
||||||
|
# 调度中心访问令牌
|
||||||
|
accessToken: default_token
|
||||||
|
# xxl-job 超时时间(秒),默认3秒
|
||||||
|
timeout: 3
|
||||||
|
executor:
|
||||||
|
# 执行器是否启用,默认true
|
||||||
|
enabled: true
|
||||||
|
# 执行器应用名称 服务名-job-executor
|
||||||
|
appname: data-job-executor
|
||||||
|
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||||
|
address:
|
||||||
|
# 执行器IP
|
||||||
|
ip:
|
||||||
|
# 执行器端口,为了好记,web服务端口+1000
|
||||||
|
port: 8104
|
||||||
|
# 执行器日志路径
|
||||||
|
logpath: /home/app/data/xxljob
|
||||||
|
# 执行器日志保留天数
|
||||||
|
logretentiondays: 14
|
||||||
|
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||||
|
excludedpackage:
|
||||||
|
# xxljob 配置结束
|
||||||
@@ -142,4 +142,34 @@ data:
|
|||||||
# 0单机处理,可以指向本地,1负载均衡轮询
|
# 0单机处理,可以指向本地,1负载均衡轮询
|
||||||
serverType: 0
|
serverType: 0
|
||||||
#serverIp: 192.168.65.161
|
#serverIp: 192.168.65.161
|
||||||
serverIp: 192.168.65.73
|
serverIp: 192.168.65.73
|
||||||
|
|
||||||
|
# xxljob 配置开始
|
||||||
|
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
# 调度中心地址列表
|
||||||
|
addresses: http://127.0.0.1:7110/xxl-job-admin
|
||||||
|
# 调度中心访问令牌
|
||||||
|
accessToken: default_token
|
||||||
|
# xxl-job 超时时间(秒),默认3秒
|
||||||
|
timeout: 3
|
||||||
|
executor:
|
||||||
|
# 执行器是否启用,默认true
|
||||||
|
enabled: true
|
||||||
|
# 执行器应用名称 服务名-job-executor
|
||||||
|
appname: data-job-executor
|
||||||
|
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||||
|
address:
|
||||||
|
# 执行器IP
|
||||||
|
ip:
|
||||||
|
# 执行器端口,为了好记,web服务端口+1000
|
||||||
|
port: 8104
|
||||||
|
# 执行器日志路径
|
||||||
|
logpath: D:\home\app\pbs\xxljob
|
||||||
|
# 执行器日志保留天数
|
||||||
|
logretentiondays: 14
|
||||||
|
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||||
|
excludedpackage:
|
||||||
|
# xxljob 配置结束
|
||||||
@@ -132,4 +132,34 @@ security:
|
|||||||
|
|
||||||
data:
|
data:
|
||||||
storage-monitor:
|
storage-monitor:
|
||||||
cron: 0 0 0/1 * * ?
|
cron: 0 0 0/1 * * ?
|
||||||
|
|
||||||
|
# xxljob 配置开始
|
||||||
|
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl:
|
||||||
|
job:
|
||||||
|
admin:
|
||||||
|
# 调度中心地址列表
|
||||||
|
addresses: http://192.168.30.146:7110/xxl-job-admin
|
||||||
|
# 调度中心访问令牌
|
||||||
|
accessToken: default_token
|
||||||
|
# xxl-job 超时时间(秒),默认3秒
|
||||||
|
timeout: 3
|
||||||
|
executor:
|
||||||
|
# 执行器是否启用,默认true
|
||||||
|
enabled: true
|
||||||
|
# 执行器应用名称 服务名-job-executor
|
||||||
|
appname: data-job-executor
|
||||||
|
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||||
|
address:
|
||||||
|
# 执行器IP
|
||||||
|
ip:
|
||||||
|
# 执行器端口,为了好记,web服务端口+1000
|
||||||
|
port: 8104
|
||||||
|
# 执行器日志路径
|
||||||
|
logpath: /home/app/data/xxljob
|
||||||
|
# 执行器日志保留天数
|
||||||
|
logretentiondays: 14
|
||||||
|
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||||
|
excludedpackage:
|
||||||
|
# xxljob 配置结束
|
||||||
Reference in New Issue
Block a user