Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
monitor-reprotdata-frogovernment
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
monitor-reprotdata-frogovernment
Commits
7ac2f7c3
Commit
7ac2f7c3
authored
Jan 10, 2022
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
监控数据库连接报警 gengdidi
parent
60dee462
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
12 deletions
+129
-12
SaticScheduleTask.java
...torreprotdatafrogovernmentnew/task/SaticScheduleTask.java
+70
-9
application.yml
src/main/resources/application.yml
+6
-3
logback-boot.xml
src/main/resources/logback-boot.xml
+53
-0
No files found.
src/main/java/com/zehong/monitorreprotdatafrogovernmentnew/task/SaticScheduleTask.java
View file @
7ac2f7c3
package
com
.
zehong
.
monitorreprotdatafrogovernmentnew
.
task
;
import
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
;
import
com.zehong.monitorreprotdatafrogovernmentnew.dao.jingye.JingyeDetectorInfoDao
;
import
com.zehong.monitorreprotdatafrogovernmentnew.dao.yingde.YingdeDetectorInfoDao
;
import
com.zehong.monitorreprotdatafrogovernmentnew.dao.zhengyuan.ZhengyuanDetectorInfoDao
;
import
com.zehong.monitorreprotdatafrogovernmentnew.entity.DetectorInfo
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -19,6 +22,7 @@ import java.util.Date;
@PropertySource
(
value
=
"classpath:application.yml"
)
public
class
SaticScheduleTask
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SaticScheduleTask
.
class
);
@Resource
private
JingyeDetectorInfoDao
jingyeDetectorInfoDao
;
...
...
@@ -36,19 +40,75 @@ public class SaticScheduleTask {
@Scheduled
(
cron
=
"${cron}"
)
private
void
configureTasks
()
{
DetectorInfo
jingye
=
jingyeDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
jingye
&&
null
!=
jingye
.
getUpdateTime
()){
compareReportDate
(
jingye
.
getUpdateTime
(),
"jingye"
);
//获取敬业数据上报状态
getJingyeReportState
();
//获取盈得数据上报状态
getYingdeReportState
();
//获取正元数据上报状态
getZhengyuanReportState
();
}
/**
* 获取敬业上报状态
*/
private
void
getJingyeReportState
(){
try
{
DetectorInfo
jingye
=
jingyeDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
jingye
&&
null
!=
jingye
.
getUpdateTime
()){
compareReportDate
(
jingye
.
getUpdateTime
(),
"jingye"
);
}
}
catch
(
Exception
e
){
dealCommunicationsException
(
e
,
"jingye"
);
logger
.
error
(
"敬业上报服务异常:"
+
e
);
}
DetectorInfo
yingde
=
yingdeDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
yingde
&&
null
!=
yingde
.
getUpdateTime
()){
compareReportDate
(
yingde
.
getUpdateTime
(),
"yingde"
);
}
/**
* 获取盈得上报状态
*/
private
void
getYingdeReportState
(){
try
{
DetectorInfo
yingde
=
yingdeDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
yingde
&&
null
!=
yingde
.
getUpdateTime
()){
compareReportDate
(
yingde
.
getUpdateTime
(),
"yingde"
);
}
}
catch
(
Exception
e
){
dealCommunicationsException
(
e
,
"yingde"
);
logger
.
error
(
"盈得上报服务异常:"
+
e
);
}
DetectorInfo
zhengyuan
=
zhengyuanDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
zhengyuan
&&
null
!=
zhengyuan
.
getUpdateTime
()){
compareReportDate
(
zhengyuan
.
getUpdateTime
(),
"zhengyuan"
);
}
/**
* 获取正元上报状态
*/
private
void
getZhengyuanReportState
(){
try
{
DetectorInfo
zhengyuan
=
zhengyuanDetectorInfoDao
.
getRecentSendData
();
if
(
null
!=
zhengyuan
&&
null
!=
zhengyuan
.
getUpdateTime
()){
compareReportDate
(
zhengyuan
.
getUpdateTime
(),
"zhengyuan"
);
}
}
catch
(
Exception
e
){
dealCommunicationsException
(
e
,
"zhengyuan"
);
logger
.
error
(
"正元上报服务异常:"
+
e
);
}
}
/**
* 处理数据库连接异常
* @param e 运行异常
* @param company 公司名称
*/
private
void
dealCommunicationsException
(
Exception
e
,
String
company
){
if
(
e
instanceof
CommunicationsException
){
if
(!
dynamicTask
.
isExist
(
company
)){
//发送短信
dynamicTask
.
sendSms
(
company
);
//启动定时半小时后重新发送
dynamicTask
.
add
(
company
,
sendSmsCron
);
}
}
}
...
...
@@ -101,4 +161,5 @@ public class SaticScheduleTask {
dynamicTask
.
stop
(
company
);
}
}
}
src/main/resources/application.yml
View file @
7ac2f7c3
...
...
@@ -17,8 +17,6 @@ zhengyuan.datasource.username: root
zhengyuan.datasource.password
:
mysql@zehong.com
zhengyuan.datasource.driverClassName
:
com.mysql.jdbc.Driver
logging.level.com.zehong.monitorreprotdatafrogovernmentnew.dao
:
DEBUG
#定时检测时间
cron
:
0 0/2 * * * ?
...
...
@@ -30,4 +28,9 @@ sendSmsUrl: http://36.148.23.59:8801/sms/sendBatchSms
secretKey
:
f225e66813e6d6a663daf919c1935dcb
phoneNums
:
13930125936,13315145077,18032932808
signName
:
泽宏云
templateCode
:
SMS_221736528
\ No newline at end of file
templateCode
:
SMS_221736528
#引入日志配置文件
#===================================== log =============================
logging
:
config
:
classpath:logback-boot.xml
\ No newline at end of file
src/main/resources/logback-boot.xml
0 → 100644
View file @
7ac2f7c3
<configuration>
<!-- %m输出的信息, %p日志级别, %t线程名, %d日期, %c类的全名, %i索引 -->
<!-- appender是configuration的子节点,是负责写日志的组件 -->
<!-- ConsoleAppender把日志输出到控制台 -->
<!-- <property name="CONSOLE_LOG_PATTERN" -->
<!-- value="%date{yyyy-MM-dd HH:mm:ss} | %highlight(%-5level) | %boldYellow(%thread) | %boldGreen(%logger) | %msg%n"/> -->
<appender
name=
"STDOUT"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<!--<pattern>${CONSOLE_LOG_PATTERN}</pattern> -->
<pattern>
%date{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) (%file:%line\)- %m%n
</pattern>
<!-- 控制台也要使用utf-8,不要使用gbk -->
<charset>
UTF-8
</charset>
</encoder>
</appender>
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
<!-- 1.先按日期存日志,日期变了,将前一天的日志文件名重命名为xxx%日期%索引,新的日志仍然是sys.log -->
<!-- 2.如果日期没有变化,但是当前日志文件的大小超过1kb时,对当前日志进行分割 重名名 -->
<appender
name=
"syslog"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<File>
${catalina.base}/mylog/sys.log
</File>
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
<!-- 文件名:log/sys.2017-12-05.0.log -->
<fileNamePattern>
${catalina.base}/mylog/sys.%d.%i.log
</fileNamePattern>
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
<maxHistory>
30
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,本篇设置为1KB,只是为了演示 -->
<maxFileSize>
30MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<!-- pattern节点,用来设置日志的输入格式 -->
<pattern>
%d %p (%file:%line\)- %m%n
</pattern>
<!-- 记录日志的编码 -->
<charset>
UTF-8
</charset>
<!-- 此处设置字符集 -->
</encoder>
</appender>
<!-- 控制台日志输出级别 -->
<root
level=
"info"
>
<appender-ref
ref=
"STDOUT"
/>
</root>
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
<!-- com.appley为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger
name=
"com.zehong.monitorreprotdatafrogovernmentnew.dao"
level=
"DEBUG"
>
<appender-ref
ref=
"syslog"
/>
</logger>
</configuration>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment