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
970ae981
Commit
970ae981
authored
Feb 20, 2020
by
赵建伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update monitor codes
parent
aa9a80a6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
36 deletions
+49
-36
Constants.java
src/main/java/com/gmei/data/dqmp/common/Constants.java
+2
-0
WarningServiceImpl.java
...a/com/gmei/data/dqmp/service/impl/WarningServiceImpl.java
+47
-36
No files found.
src/main/java/com/gmei/data/dqmp/common/Constants.java
View file @
970ae981
...
...
@@ -41,5 +41,7 @@ public class Constants {
public
static
final
String
REFER
=
"refer"
;
public
static
final
String
VOLATILITY
=
"volatility"
;
public
static
final
String
SPECIAL
=
"special"
;
// 日环比监控类型
public
static
final
String
MONITOR_TYPE
=
"day_chain"
;
}
src/main/java/com/gmei/data/dqmp/service/impl/WarningServiceImpl.java
View file @
970ae981
...
...
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.gmei.data.dqmp.common.Constants
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRule
;
import
com.gmei.data.dqmp.domain.TblMonitorVolatilityRuleCriteria
;
import
com.gmei.data.dqmp.domain.TblResultMonitorVolatility
;
...
...
@@ -16,6 +17,7 @@ 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.MailService
;
import
com.gmei.data.dqmp.service.WarningService
;
import
com.gmei.data.dqmp.utils.CrontabUtils
;
import
com.gmei.data.dqmp.utils.DateUtils
;
...
...
@@ -26,53 +28,62 @@ public class WarningServiceImpl implements WarningService {
@Autowired
private
DingdingService
dingdingService
;
@Autowired
private
MailService
mailService
;
@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
());
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
);
for
(
TblMonitorVolatilityRule
tblMonitorVolatilityRule
:
tblMonitorVolatilityRuleList
)
{
if
(
Constants
.
MONITOR_TYPE
.
equals
(
tblMonitorVolatilityRule
.
getMonitorType
()))
{
String
checkTime
=
tblMonitorVolatilityRule
.
getCheckTime
();
String
dbName
=
tblMonitorVolatilityRule
.
getDbName
();
String
tbName
=
tblMonitorVolatilityRule
.
getTbName
();
if
(!
CrontabUtils
.
isToRunByMinites
(
currentDate
,
checkTime
))
{
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
);
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 lastOneDayIndicatorValue or lastTwoDayIndicatorValue or all values of table {} is empty!"
,
tblMonitorVolatilityRule
.
getTbName
());
return
;
}
Double
rs
=
Math
.
abs
((
lastOneDayIndicatorValue
-
lastTwoDayIndicatorValue
)
/
Double
.
valueOf
(
lastTwoDayIndicatorValue
));
Double
threshold
=
tblMonitorVolatilityRule
.
getThreshold
();
if
(
rs
>
threshold
)
{
String
warningMsg
=
String
.
format
(
"表%s.%s中数据量变化超过%s,疑似异常,请核实!"
,
dbName
,
tbName
,
threshold
*
100
+
"%"
);
mailService
.
sendSimpleMail
(
warningMsg
);
dingdingService
.
sendMsgToDingding
(
warningMsg
);
logger
.
error
(
"表{}.{}中数据量变化超过{},疑似异常,请核实!"
,
dbName
,
tbName
,
threshold
*
100
+
"%"
);
}
}
}
}
...
...
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