Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
DQMP
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
data
DQMP
Commits
aa9a80a6
Commit
aa9a80a6
authored
Feb 19, 2020
by
赵建伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add monitor codes
parent
23bd3e16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
271 additions
and
9 deletions
+271
-9
TblMonitorVolatilityRule.java
...a/com/gmei/data/dqmp/domain/TblMonitorVolatilityRule.java
+113
-0
TblMonitorVolatilityRuleCriteria.java
...ei/data/dqmp/domain/TblMonitorVolatilityRuleCriteria.java
+0
-0
TblMonitorVolatilityRuleMapper.java
...gmei/data/dqmp/mapper/TblMonitorVolatilityRuleMapper.java
+31
-0
MonitorScheduler.java
...n/java/com/gmei/data/dqmp/scheduler/MonitorScheduler.java
+19
-0
WarningService.java
src/main/java/com/gmei/data/dqmp/service/WarningService.java
+7
-0
CheckServiceImpl.java
...ava/com/gmei/data/dqmp/service/impl/CheckServiceImpl.java
+6
-7
MonitorServiceImpl.java
...a/com/gmei/data/dqmp/service/impl/MonitorServiceImpl.java
+3
-1
WarningServiceImpl.java
...a/com/gmei/data/dqmp/service/impl/WarningServiceImpl.java
+79
-0
DateUtils.java
src/main/java/com/gmei/data/dqmp/utils/DateUtils.java
+11
-0
generator.xml
src/main/resources/generator.xml
+2
-1
TblMonitorVolatilityRuleMapper.xml
...sources/mybatis/mapper/TblMonitorVolatilityRuleMapper.xml
+0
-0
No files found.
src/main/java/com/gmei/data/dqmp/domain/TblMonitorVolatilityRule.java
0 → 100644
View file @
aa9a80a6
package
com
.
gmei
.
data
.
dqmp
.
domain
;
public
class
TblMonitorVolatilityRule
{
private
Integer
id
;
private
String
dbName
;
private
String
tbName
;
private
String
colName
;
private
String
indicatorType
;
private
String
monitorType
;
private
Double
threshold
;
private
String
checkTime
;
private
String
comment
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getDbName
()
{
return
dbName
;
}
public
void
setDbName
(
String
dbName
)
{
this
.
dbName
=
dbName
==
null
?
null
:
dbName
.
trim
();
}
public
String
getTbName
()
{
return
tbName
;
}
public
void
setTbName
(
String
tbName
)
{
this
.
tbName
=
tbName
==
null
?
null
:
tbName
.
trim
();
}
public
String
getColName
()
{
return
colName
;
}
public
void
setColName
(
String
colName
)
{
this
.
colName
=
colName
==
null
?
null
:
colName
.
trim
();
}
public
String
getIndicatorType
()
{
return
indicatorType
;
}
public
void
setIndicatorType
(
String
indicatorType
)
{
this
.
indicatorType
=
indicatorType
==
null
?
null
:
indicatorType
.
trim
();
}
public
String
getMonitorType
()
{
return
monitorType
;
}
public
void
setMonitorType
(
String
monitorType
)
{
this
.
monitorType
=
monitorType
==
null
?
null
:
monitorType
.
trim
();
}
public
Double
getThreshold
()
{
return
threshold
;
}
public
void
setThreshold
(
Double
threshold
)
{
this
.
threshold
=
threshold
;
}
public
String
getCheckTime
()
{
return
checkTime
;
}
public
void
setCheckTime
(
String
checkTime
)
{
this
.
checkTime
=
checkTime
==
null
?
null
:
checkTime
.
trim
();
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
==
null
?
null
:
comment
.
trim
();
}
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
getClass
().
getSimpleName
());
sb
.
append
(
" ["
);
sb
.
append
(
"Hash = "
).
append
(
hashCode
());
sb
.
append
(
", id="
).
append
(
id
);
sb
.
append
(
", dbName="
).
append
(
dbName
);
sb
.
append
(
", tbName="
).
append
(
tbName
);
sb
.
append
(
", colName="
).
append
(
colName
);
sb
.
append
(
", indicatorType="
).
append
(
indicatorType
);
sb
.
append
(
", monitorType="
).
append
(
monitorType
);
sb
.
append
(
", threshold="
).
append
(
threshold
);
sb
.
append
(
", checkTime="
).
append
(
checkTime
);
sb
.
append
(
", comment="
).
append
(
comment
);
sb
.
append
(
"]"
);
return
sb
.
toString
();
}
}
\ No newline at end of file
src/main/java/com/gmei/data/dqmp/domain/TblMonitorVolatilityRuleCriteria.java
0 → 100644
View file @
aa9a80a6
This diff is collapsed.
Click to expand it.
src/main/java/com/gmei/data/dqmp/mapper/TblMonitorVolatilityRuleMapper.java
0 → 100644
View file @
aa9a80a6
package
com
.
gmei
.
data
.
dqmp
.
mapper
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRule
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRuleCriteria
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
TblMonitorVolatilityRuleMapper
{
int
countByExample
(
TblMonitorVolatilityRuleCriteria
example
);
int
deleteByExample
(
TblMonitorVolatilityRuleCriteria
example
);
int
deleteByPrimaryKey
(
Integer
id
);
int
insert
(
TblMonitorVolatilityRule
record
);
int
insertSelective
(
TblMonitorVolatilityRule
record
);
List
<
TblMonitorVolatilityRule
>
selectByExample
(
TblMonitorVolatilityRuleCriteria
example
);
TblMonitorVolatilityRule
selectByPrimaryKey
(
Integer
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
TblMonitorVolatilityRule
record
,
@Param
(
"example"
)
TblMonitorVolatilityRuleCriteria
example
);
int
updateByExample
(
@Param
(
"record"
)
TblMonitorVolatilityRule
record
,
@Param
(
"example"
)
TblMonitorVolatilityRuleCriteria
example
);
int
updateByPrimaryKeySelective
(
TblMonitorVolatilityRule
record
);
int
updateByPrimaryKey
(
TblMonitorVolatilityRule
record
);
}
\ No newline at end of file
src/main/java/com/gmei/data/dqmp/scheduler/MonitorScheduler.java
0 → 100644
View file @
aa9a80a6
package
com
.
gmei
.
data
.
dqmp
.
scheduler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
com.gmei.data.dqmp.service.WarningService
;
@Component
public
class
MonitorScheduler
{
@Autowired
private
WarningService
warningService
;
@Scheduled
(
cron
=
"*/60 * * * * ?"
)
private
void
uniqueProcess
(){
warningService
.
checkAndWarning
();
}
}
src/main/java/com/gmei/data/dqmp/service/WarningService.java
0 → 100644
View file @
aa9a80a6
package
com
.
gmei
.
data
.
dqmp
.
service
;
public
interface
WarningService
{
void
checkAndWarning
();
}
src/main/java/com/gmei/data/dqmp/service/impl/CheckServiceImpl.java
View file @
aa9a80a6
...
...
@@ -176,7 +176,8 @@ public class CheckServiceImpl implements CheckService {
* @return
*/
private
TblResultCheckUnique
getUniqueCheckResult
(
String
sql
)
{
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#partition_day"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
logger
.
info
(
"Sql content : {}"
,
sql
);
TblResultCheckUnique
tblResultCheckUnique
=
null
;
if
(
StringUtils
.
isBlank
(
sql
))
{
...
...
@@ -212,7 +213,8 @@ public class CheckServiceImpl implements CheckService {
* @return
*/
private
TblResultCheckUnblank
getUnblankCheckResult
(
String
sql
)
{
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#partition_day"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
logger
.
info
(
"Sql content : {}"
,
sql
);
TblResultCheckUnblank
tblResultCheckUnblank
=
null
;
if
(
StringUtils
.
isBlank
(
sql
))
{
...
...
@@ -248,7 +250,8 @@ public class CheckServiceImpl implements CheckService {
* @return
*/
private
TblResultCheckRefer
getReferCheckResult
(
String
sql
)
{
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#partition_day"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
logger
.
info
(
"Sql content : {}"
,
sql
);
TblResultCheckRefer
tblResultCheckRefer
=
null
;
if
(
StringUtils
.
isBlank
(
sql
))
{
...
...
@@ -280,8 +283,4 @@ public class CheckServiceImpl implements CheckService {
}
return
tblResultCheckRefer
;
}
public
static
void
main
(
String
[]
args
)
{
String
sql
=
""
;
}
}
src/main/java/com/gmei/data/dqmp/service/impl/MonitorServiceImpl.java
View file @
aa9a80a6
...
...
@@ -139,7 +139,8 @@ public class MonitorServiceImpl implements MonitorService {
* @return
*/
private
TblResultMonitorVolatility
getMonitorVolatilityResult
(
String
sql
,
String
indicatorType
)
{
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#partition_day"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()));
logger
.
info
(
"Sql content : {},indicatorType: {}"
,
sql
,
indicatorType
);
TblResultMonitorVolatility
tblResultMonitorVolatility
=
null
;
if
(
StringUtils
.
isBlank
(
sql
)
||
StringUtils
.
isBlank
(
indicatorType
))
{
...
...
@@ -176,6 +177,7 @@ public class MonitorServiceImpl implements MonitorService {
*/
private
TblResultMonitorSpecial
getMonitorSpecialResult
(
String
sql
,
String
startTime
)
{
sql
=
sql
.
replaceAll
(
"#partition_date"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#partition_day"
,
String
.
format
(
"'%s'"
,
DateUtils
.
getYesterdayDateStr
()))
.
replaceAll
(
"#start_time"
,
"'"
+
DateUtils
.
getZeroTimeStrsMap
().
get
(
startTime
)
+
"'"
)
.
replaceAll
(
"#end_time"
,
"'"
+
DateUtils
.
getTodayZeroTimeStr
()
+
"'"
);
logger
.
info
(
"Sql content : {}"
,
sql
);
...
...
src/main/java/com/gmei/data/dqmp/service/impl/WarningServiceImpl.java
0 → 100644
View file @
aa9a80a6
package
com
.
gmei
.
data
.
dqmp
.
service
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRule
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRuleCriteria
;
import
com.gmei.data.dqmp.domain.TblResultMonitorVolatility
;
import
com.gmei.data.dqmp.domain.TblResultMonitorVolatilityCriteria
;
import
com.gmei.data.dqmp.domain.TblResultMonitorVolatilityCriteria.Criteria
;
import
com.gmei.data.dqmp.mapper.TblMonitorVolatilityRuleMapper
;
import
com.gmei.data.dqmp.mapper.TblResultMonitorVolatilityMapper
;
import
com.gmei.data.dqmp.service.DingdingService
;
import
com.gmei.data.dqmp.service.WarningService
;
import
com.gmei.data.dqmp.utils.CrontabUtils
;
import
com.gmei.data.dqmp.utils.DateUtils
;
@Service
public
class
WarningServiceImpl
implements
WarningService
{
@Autowired
private
DingdingService
dingdingService
;
@Autowired
private
TblMonitorVolatilityRuleMapper
tblMonitorVolatilityRuleMapper
;
@Autowired
private
TblResultMonitorVolatilityMapper
tblResultMonitorVolatilityMapper
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
WarningServiceImpl
.
class
);
@Override
public
void
checkAndWarning
()
{
List
<
TblMonitorVolatilityRule
>
tblMonitorVolatilityRuleList
=
tblMonitorVolatilityRuleMapper
.
selectByExample
(
new
TblMonitorVolatilityRuleCriteria
());
Date
currentDate
=
new
Date
();
String
lastOneDayDateStr
=
DateUtils
.
getLastNumDaysDateStr
(
1
);
String
lastTwoDayDateStr
=
DateUtils
.
getLastNumDaysDateStr
(
2
);
for
(
TblMonitorVolatilityRule
tblMonitorVolatilityRule
:
tblMonitorVolatilityRuleList
)
{
String
checkTime
=
tblMonitorVolatilityRule
.
getCheckTime
();
String
dbName
=
tblMonitorVolatilityRule
.
getDbName
();
String
tbName
=
tblMonitorVolatilityRule
.
getTbName
();
if
(!
CrontabUtils
.
isToRunByMinites
(
currentDate
,
checkTime
))
{
continue
;
}
TblResultMonitorVolatilityCriteria
tblResultMonitorVolatilityCriteria
=
new
TblResultMonitorVolatilityCriteria
();
Criteria
criteria
=
tblResultMonitorVolatilityCriteria
.
createCriteria
();
criteria
.
andDbNameEqualTo
(
dbName
)
.
andTbNameEqualTo
(
tbName
)
.
andColNameEqualTo
(
tblMonitorVolatilityRule
.
getColName
())
.
andIndicatorTypeEqualTo
(
tblMonitorVolatilityRule
.
getIndicatorType
())
.
andPartitionDateBetween
(
lastTwoDayDateStr
,
lastOneDayDateStr
);
tblResultMonitorVolatilityCriteria
.
setOrderByClause
(
"partition_date"
);
List
<
TblResultMonitorVolatility
>
tblResultMonitorVolatilityList
=
tblResultMonitorVolatilityMapper
.
selectByExample
(
tblResultMonitorVolatilityCriteria
);
Long
lastOneDayIndicatorValue
=
null
,
lastTwoDayIndicatorValue
=
null
;
for
(
TblResultMonitorVolatility
tblResultMonitorVolatility
:
tblResultMonitorVolatilityList
)
{
String
partitionDate
=
tblResultMonitorVolatility
.
getPartitionDate
();
if
(
lastOneDayDateStr
.
equals
(
partitionDate
))
{
lastOneDayIndicatorValue
=
tblResultMonitorVolatility
.
getIndicatorValue
();
}
else
if
(
lastTwoDayDateStr
.
equals
(
partitionDate
)){
lastTwoDayIndicatorValue
=
tblResultMonitorVolatility
.
getIndicatorValue
();
}
else
{
logger
.
error
(
"PartitionDate value is error: {}"
,
partitionDate
);
continue
;
}
}
if
(
lastOneDayIndicatorValue
==
null
||
lastTwoDayIndicatorValue
==
null
)
{
logger
.
error
(
"The indicatorValues of table {} is empty!"
,
tblMonitorVolatilityRule
.
getTbName
());
return
;
}
Double
rs
=
Math
.
abs
((
lastOneDayIndicatorValue
-
lastTwoDayIndicatorValue
)/
Double
.
valueOf
(
lastTwoDayIndicatorValue
))
;
if
(
rs
>
tblMonitorVolatilityRule
.
getThreshold
())
{
dingdingService
.
sendMsgToDingding
(
String
.
format
(
"表%s.%s中的数据量疑似异常,请核实"
,
dbName
,
tbName
));
logger
.
error
(
"表{}.{}中的数据量疑似异常,请核实"
,
dbName
,
tbName
);
}
}
}
}
src/main/java/com/gmei/data/dqmp/utils/DateUtils.java
View file @
aa9a80a6
...
...
@@ -23,6 +23,17 @@ public class DateUtils {
return
new
SimpleDateFormat
(
DATE_FORMATE_YMD
).
format
(
new
Date
());
}
/**
* 获取上N天时间字符串
* @return
*/
public
static
String
getLastNumDaysDateStr
(
int
daysNum
)
{
Calendar
cld
=
Calendar
.
getInstance
();
cld
.
setTime
(
new
Date
());
cld
.
add
(
Calendar
.
DAY_OF_MONTH
,
-
daysNum
);
return
new
SimpleDateFormat
(
DATE_FORMATE_YMD
).
format
(
cld
.
getTime
());
}
/**
* 获取当前时间字符串
* @return
...
...
src/main/resources/generator.xml
View file @
aa9a80a6
...
...
@@ -54,6 +54,7 @@
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table> -->
<!-- <table tableName="tbl_sys_param_info" domainObjectName="TblSysParamInfo"/> -->
<table
tableName=
"tbl_threshold_exceed_all"
domainObjectName=
"TblThresholdExceedAll"
/>
<!-- <table tableName="tbl_threshold_exceed_all" domainObjectName="TblThresholdExceedAll"/> -->
<table
tableName=
"tbl_monitor_volatility_rule"
domainObjectName=
"TblMonitorVolatilityRule"
/>
</context>
</generatorConfiguration>
src/main/resources/mybatis/mapper/TblMonitorVolatilityRuleMapper.xml
0 → 100644
View file @
aa9a80a6
This diff is collapsed.
Click to expand it.
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