Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
94f52e0a
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
94f52e0a
编写于
7月 07, 2014
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:dianping/cat
上级
d29d0d8d
4d24db91
变更
32
展开全部
隐藏空白更改
内联
并排
Showing
32 changed file
with
456 addition
and
188 deletion
+456
-188
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
...n/java/com/dianping/cat/build/ComponentsConfigurator.java
+12
-10
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
...com/dianping/cat/report/task/alert/AlertResultEntity.java
+44
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+47
-9
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
...a/com/dianping/cat/report/task/alert/BaseAlertConfig.java
+2
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
.../java/com/dianping/cat/report/task/alert/DataChecker.java
+1
-3
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
...om/dianping/cat/report/task/alert/DefaultDataChecker.java
+4
-5
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
...ianping/cat/report/task/alert/business/BusinessAlert.java
+20
-12
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
...g/cat/report/task/alert/business/BusinessAlertConfig.java
+3
-3
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
...at/report/task/alert/exception/AlertExceptionBuilder.java
+0
-7
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
...nping/cat/report/task/alert/exception/ExceptionAlert.java
+44
-3
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
...cat/report/task/alert/exception/ExceptionAlertConfig.java
+10
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlert.java
.../dianping/cat/report/task/alert/network/NetworkAlert.java
+7
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
...ing/cat/report/task/alert/network/NetworkAlertConfig.java
+3
-3
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlert.java
...om/dianping/cat/report/task/alert/system/SystemAlert.java
+7
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
...nping/cat/report/task/alert/system/SystemAlertConfig.java
+3
-3
cat-home/src/main/java/com/dianping/cat/system/config/BaseRuleConfigManager.java
...com/dianping/cat/system/config/BaseRuleConfigManager.java
+28
-19
cat-home/src/main/java/com/dianping/cat/system/config/BusinessRuleConfigManager.java
...dianping/cat/system/config/BusinessRuleConfigManager.java
+17
-6
cat-home/src/main/java/com/dianping/cat/system/config/NetworkRuleConfigManager.java
.../dianping/cat/system/config/NetworkRuleConfigManager.java
+7
-0
cat-home/src/main/java/com/dianping/cat/system/config/SystemRuleConfigManager.java
...m/dianping/cat/system/config/SystemRuleConfigManager.java
+10
-3
cat-home/src/main/java/com/dianping/cat/system/page/config/Handler.java
...ain/java/com/dianping/cat/system/page/config/Handler.java
+1
-1
cat-home/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
...e/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
+41
-0
cat-home/src/main/resources/META-INF/dal/jdbc/report-dal.xml
cat-home/src/main/resources/META-INF/dal/jdbc/report-dal.xml
+3
-0
cat-home/src/main/resources/META-INF/dal/model/monitor-rules-codegen.xml
...in/resources/META-INF/dal/model/monitor-rules-codegen.xml
+2
-2
cat-home/src/main/resources/META-INF/dal/model/monitor-rules-model.xml
...main/resources/META-INF/dal/model/monitor-rules-model.xml
+2
-2
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+31
-0
cat-home/src/main/resources/META-INF/wizard/jdbc/wizard.xml
cat-home/src/main/resources/META-INF/wizard/jdbc/wizard.xml
+1
-0
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
...st/java/com/dianping/cat/report/alert/RuleConfigTest.java
+14
-14
cat-home/src/test/java/com/dianping/cat/report/task/alert/MetricIdAndRuleMappingTest.java
...ing/cat/report/task/alert/MetricIdAndRuleMappingTest.java
+6
-1
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
.../com/dianping/cat/report/task/metric/AlertConfigTest.java
+29
-30
cat-home/src/test/resources/config/demo-rule-monitor.xml
cat-home/src/test/resources/config/demo-rule-monitor.xml
+2
-2
cat-home/src/test/resources/config/monitor-rule.xml
cat-home/src/test/resources/config/monitor-rule.xml
+44
-44
script/Cat.sql
script/Cat.sql
+11
-0
未找到文件。
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
浏览文件 @
94f52e0a
...
...
@@ -20,6 +20,7 @@ import com.dianping.cat.consumer.top.TopAnalyzer;
import
com.dianping.cat.core.config.ConfigDao
;
import
com.dianping.cat.core.dal.HostinfoDao
;
import
com.dianping.cat.core.dal.ProjectDao
;
import
com.dianping.cat.home.dal.report.AlertDao
;
import
com.dianping.cat.home.dal.report.EventDao
;
import
com.dianping.cat.home.dal.report.TopologyGraphDao
;
import
com.dianping.cat.report.baseline.BaselineService
;
...
...
@@ -132,11 +133,11 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
ConfigReloadTask
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
));
all
.
add
(
C
(
IpService
.
class
));
all
.
add
(
C
(
CdnGraphCreator
.
class
).
req
(
BaselineService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
,
CachedMetricReportService
.
class
,
Metric
ConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
CachedMetricReportService
.
class
,
CachedMetricReportServiceImpl
.
class
)
.
req
(
ModelService
.
class
,
MetricAnalyzer
.
ID
).
req
(
ReportService
.
class
).
req
(
IpService
.
class
));
all
.
add
(
C
(
CdnGraphCreator
.
class
).
req
(
BaselineService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
,
CachedMetricReportService
.
class
,
MetricConfigManager
.
class
,
ProductLine
ConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
CachedMetricReportService
.
class
,
CachedMetricReportServiceImpl
.
class
)
.
req
(
ModelService
.
class
,
MetricAnalyzer
.
ID
).
req
(
ReportService
.
class
).
req
(
IpService
.
class
));
all
.
add
(
C
(
DataExtractor
.
class
,
DataExtractorImpl
.
class
));
...
...
@@ -184,21 +185,22 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
DataChecker
.
class
,
DefaultDataChecker
.
class
));
all
.
add
(
C
(
BusinessAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
BusinessAlertConfig
.
class
,
AlertInfo
.
class
)
//
BaselineService
.
class
,
MailSMS
.
class
,
BusinessAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
BusinessRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
NetworkAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
NetworkAlertConfig
.
class
,
AlertInfo
.
class
)
//
BaselineService
.
class
,
MailSMS
.
class
,
NetworkAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
NetworkRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
SystemAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
SystemAlertConfig
.
class
,
AlertInf
o
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
SystemRuleConfigManager
.
class
,
DataChecker
.
class
));
BaselineService
.
class
,
MailSMS
.
class
,
SystemAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDa
o
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
SystemRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
AlertExceptionBuilder
.
class
).
req
(
ExceptionConfigManager
.
class
));
all
.
add
(
C
(
ExceptionAlert
.
class
).
req
(
ProjectDao
.
class
,
ExceptionAlertConfig
.
class
,
MailSMS
.
class
,
ExceptionConfigManager
.
class
,
AlertExceptionBuilder
.
class
).
req
(
ModelService
.
class
,
TopAnalyzer
.
ID
));
ExceptionConfigManager
.
class
,
AlertExceptionBuilder
.
class
,
AlertDao
.
class
).
req
(
ModelService
.
class
,
TopAnalyzer
.
ID
));
all
.
add
(
C
(
NetGraphConfigManager
.
class
).
req
(
ConfigDao
.
class
));
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
0 → 100644
浏览文件 @
94f52e0a
package
com.dianping.cat.report.task.alert
;
import
java.util.Date
;
public
class
AlertResultEntity
{
private
boolean
m_isTriggered
;
private
String
m_content
;
private
String
m_alertType
;
private
Date
m_alertTime
;
public
AlertResultEntity
(){
this
.
m_isTriggered
=
false
;
this
.
m_content
=
""
;
this
.
m_alertType
=
""
;
this
.
m_alertTime
=
new
Date
();
}
public
AlertResultEntity
(
boolean
result
,
String
content
,
String
alertType
){
this
.
m_isTriggered
=
result
;
this
.
m_content
=
content
;
this
.
m_alertType
=
alertType
;
this
.
m_alertTime
=
new
Date
();
}
public
Date
getAlertTime
()
{
return
m_alertTime
;
}
public
String
getAlertType
()
{
return
m_alertType
;
}
public
String
getContent
()
{
return
m_content
;
}
public
boolean
isTriggered
()
{
return
m_isTriggered
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
94f52e0a
...
...
@@ -9,9 +9,9 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.tuple.Pair
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
...
...
@@ -23,6 +23,8 @@ import com.dianping.cat.consumer.metric.model.entity.MetricItem;
import
com.dianping.cat.consumer.metric.model.entity.MetricReport
;
import
com.dianping.cat.consumer.metric.model.entity.Segment
;
import
com.dianping.cat.helper.TimeUtil
;
import
com.dianping.cat.home.dal.report.Alert
;
import
com.dianping.cat.home.dal.report.AlertDao
;
import
com.dianping.cat.home.rule.entity.Condition
;
import
com.dianping.cat.home.rule.entity.Config
;
import
com.dianping.cat.report.baseline.BaselineService
;
...
...
@@ -34,11 +36,14 @@ import com.dianping.cat.system.tool.MailSMS;
public
abstract
class
BaseAlert
{
@Inject
protected
BaseRuleConfigManager
m_
metricR
uleConfigManager
;
protected
BaseRuleConfigManager
m_
r
uleConfigManager
;
@Inject
protected
MailSMS
m_mailSms
;
@Inject
protected
AlertDao
m_alertDao
;
@Inject
protected
AlertInfo
m_alertInfo
;
...
...
@@ -69,6 +74,19 @@ public abstract class BaseAlert {
protected
Map
<
String
,
MetricReport
>
m_lastReports
=
new
HashMap
<
String
,
MetricReport
>();
private
Alert
buildAlert
(
String
domainName
,
String
metricTitle
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
alertResult
.
getAlertTime
());
alert
.
setCategory
(
getName
());
alert
.
setType
(
alertResult
.
getAlertType
());
alert
.
setContent
(
mailTitle
+
"<br/>"
+
alertResult
.
getContent
());
alert
.
setMetric
(
metricTitle
);
return
alert
;
}
private
String
buildMetricTitle
(
String
metricKey
)
{
try
{
return
metricKey
.
split
(
":"
)[
2
];
...
...
@@ -87,11 +105,10 @@ public abstract class BaseAlert {
return
result
;
}
protected
Triple
<
Boolean
,
String
,
String
>
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
protected
AlertResultEntity
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
double
[]
value
=
null
;
double
[]
baseline
=
null
;
List
<
Config
>
configs
=
m_
metricRuleConfigManager
.
queryConfigs
(
metricKey
,
type
);
List
<
Config
>
configs
=
m_
ruleConfigManager
.
queryConfigs
(
product
,
metricKey
,
type
);
Pair
<
Integer
,
List
<
Condition
>>
resultPair
=
queryCheckMinuteAndConditions
(
configs
);
int
maxMinute
=
resultPair
.
getKey
();
List
<
Condition
>
conditions
=
resultPair
.
getValue
();
...
...
@@ -221,13 +238,16 @@ public abstract class BaseAlert {
private
void
processMetricItem
(
int
minute
,
ProductLine
productLine
,
String
metricKey
)
{
for
(
MetricType
type
:
MetricType
.
values
())
{
Triple
<
Boolean
,
String
,
String
>
alert
=
computeAlertInfo
(
minute
,
productLine
.
getId
(),
metricKey
,
type
);
String
productlineName
=
productLine
.
getId
();
AlertResultEntity
alertResult
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
if
(
alert
!=
null
&&
alert
.
getFirst
())
{
if
(
alert
Result
!=
null
&&
alertResult
.
isTriggered
())
{
String
metricTitle
=
buildMetricTitle
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metricTitle
);
m_alertInfo
.
addAlertInfo
(
metricKey
,
new
Date
().
getTime
());
sendAlertInfo
(
productLine
,
metricTitle
,
alert
.
getMiddle
(),
alert
.
getLast
());
storeAlert
(
productlineName
,
metricTitle
,
mailTitle
,
alertResult
);
sendAlertInfo
(
productLine
,
mailTitle
,
alertResult
.
getContent
(),
alertResult
.
getAlertType
());
}
}
}
...
...
@@ -304,5 +324,23 @@ public abstract class BaseAlert {
return
result
;
}
protected
abstract
void
sendAlertInfo
(
ProductLine
productLine
,
String
metricTitle
,
String
content
,
String
alertType
);
protected
void
storeAlert
(
String
domainName
,
String
metricTitle
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
buildAlert
(
domainName
,
metricTitle
,
mailTitle
,
alertResult
);
try
{
int
count
=
m_alertDao
.
insert
(
alert
);
if
(
count
!=
1
)
{
Cat
.
logError
(
"insert alert error: "
+
alert
.
toString
(),
new
RuntimeException
());
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
protected
abstract
String
getName
();
protected
abstract
BaseAlertConfig
getAlertConfig
();
protected
abstract
void
sendAlertInfo
(
ProductLine
productLine
,
String
mailTitle
,
String
content
,
String
alertType
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
浏览文件 @
94f52e0a
...
...
@@ -68,6 +68,8 @@ public abstract class BaseAlertConfig {
return
smsReceivers
;
}
}
protected
abstract
String
buildMailTitle
(
String
artifactName
,
String
configTitle
);
public
abstract
String
getId
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
浏览文件 @
94f52e0a
...
...
@@ -2,11 +2,9 @@ package com.dianping.cat.report.task.alert;
import
java.util.List
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.home.rule.entity.Condition
;
public
interface
DataChecker
{
public
Triple
<
Boolean
,
String
,
String
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
浏览文件 @
94f52e0a
...
...
@@ -3,7 +3,6 @@ package com.dianping.cat.report.task.alert;
import
java.util.List
;
import
org.unidal.tuple.Pair
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.home.rule.entity.Condition
;
...
...
@@ -26,8 +25,8 @@ public class DefaultDataChecker implements DataChecker {
return
result
;
}
public
Triple
<
Boolean
,
String
,
String
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
Triple
<
Boolean
,
String
,
String
>
result
=
new
Triple
<
Boolean
,
String
,
String
>(
false
,
""
,
""
);
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
AlertResultEntity
result
=
new
AlertResultEntity
(
);
for
(
Condition
condition
:
conditions
)
{
int
conditionMinute
=
condition
.
getMinute
();
...
...
@@ -39,9 +38,9 @@ public class DefaultDataChecker implements DataChecker {
if
(
condResult
.
getKey
()
==
true
)
{
String
alertType
=
condition
.
getAlertType
();
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
return
new
Triple
<
Boolean
,
String
,
String
>
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
return
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
else
{
result
=
new
Triple
<
Boolean
,
String
,
String
>
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
result
=
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
}
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
浏览文件 @
94f52e0a
...
...
@@ -9,20 +9,21 @@ import org.codehaus.plexus.logging.LogEnabled;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.BaseAlert
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
import
com.dianping.cat.report.task.alert.MetricType
;
public
class
BusinessAlert
extends
BaseAlert
implements
Task
,
LogEnabled
{
@Inject
pr
ivate
BusinessAlertConfig
m_alertConfig
;
pr
otected
BusinessAlertConfig
m_alertConfig
;
private
Logger
m_logger
;
...
...
@@ -35,6 +36,11 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
public
String
getName
()
{
return
"metric-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
public
boolean
needAlert
(
MetricItemConfig
config
)
{
if
((
config
.
getAlarm
()
||
config
.
isShowAvgDashboard
()
||
config
.
isShowSumDashboard
()
||
config
...
...
@@ -48,24 +54,27 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
private
void
processMetricItemConfig
(
MetricItemConfig
config
,
int
minute
,
ProductLine
productLine
)
{
if
(
needAlert
(
config
))
{
String
product
=
productLine
.
getId
();
String
metricKey
=
m_metricConfigManager
.
buildMetricKey
(
config
.
getDomain
(),
config
.
getType
(),
config
.
getMetricKey
());
String
domain
=
config
.
getDomain
();
String
metric
=
config
.
getMetricKey
();
String
metricKey
=
m_metricConfigManager
.
buildMetricKey
(
domain
,
config
.
getType
(),
metric
);
Triple
<
Boolean
,
String
,
String
>
aler
t
=
null
;
AlertResultEntity
alertResul
t
=
null
;
if
(
config
.
isShowAvg
())
{
alert
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
AVG
);
alert
Result
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
AVG
);
}
if
(
config
.
isShowCount
())
{
alert
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
COUNT
);
alert
Result
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
COUNT
);
}
if
(
config
.
isShowSum
())
{
alert
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
SUM
);
alert
Result
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
SUM
);
}
if
(
alert
!=
null
&&
alert
.
getFirst
())
{
if
(
alertResult
!=
null
&&
alertResult
.
isTriggered
())
{
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
productLine
.
getTitle
(),
config
.
getTitle
());
m_alertInfo
.
addAlertInfo
(
metricKey
,
new
Date
().
getTime
());
sendAlertInfo
(
productLine
,
config
.
getTitle
(),
alert
.
getMiddle
(),
alert
.
getLast
());
storeAlert
(
domain
,
metric
,
mailTitle
,
alertResult
);
sendAlertInfo
(
productLine
,
mailTitle
,
alertResult
.
getContent
(),
alertResult
.
getAlertType
());
}
}
}
...
...
@@ -138,9 +147,8 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
}
@Override
public
void
sendAlertInfo
(
ProductLine
productLine
,
String
metricT
itle
,
String
content
,
String
alertType
)
{
public
void
sendAlertInfo
(
ProductLine
productLine
,
String
t
itle
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
String
title
=
m_alertConfig
.
buildMailTitle
(
productLine
,
metricTitle
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
浏览文件 @
94f52e0a
package
com.dianping.cat.report.task.alert.business
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
public
class
BusinessAlertConfig
extends
BaseAlertConfig
{
private
String
m_id
=
"business"
;
public
String
buildMailTitle
(
ProductLine
productLine
,
String
configTitle
)
{
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitle
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[业务告警] [产品线 "
).
append
(
product
Line
.
getTitle
()
).
append
(
"]"
);
sb
.
append
(
"[业务告警] [产品线 "
).
append
(
product
lineName
).
append
(
"]"
);
sb
.
append
(
"[业务指标 "
).
append
(
configTitle
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
浏览文件 @
94f52e0a
...
...
@@ -125,13 +125,6 @@ public class AlertExceptionBuilder {
return
limits
;
}
public
String
buildMailTitle
(
String
domain
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"]"
);
return
sb
.
toString
();
}
public
String
buildMailContent
(
String
exceptions
,
String
domain
)
{
String
content
=
buildContent
(
exceptions
,
domain
);
String
url
=
"http://cat.dianpingoa.com/cat/r/p?domain="
+
domain
;
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
浏览文件 @
94f52e0a
...
...
@@ -10,6 +10,7 @@ import java.util.Map.Entry;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
...
...
@@ -21,6 +22,8 @@ import com.dianping.cat.core.dal.Project;
import
com.dianping.cat.core.dal.ProjectDao
;
import
com.dianping.cat.core.dal.ProjectEntity
;
import
com.dianping.cat.helper.TimeUtil
;
import
com.dianping.cat.home.dal.report.Alert
;
import
com.dianping.cat.home.dal.report.AlertDao
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
...
...
@@ -34,6 +37,9 @@ import com.dianping.cat.system.tool.MailSMS;
public
class
ExceptionAlert
implements
Task
,
LogEnabled
{
@Inject
protected
AlertDao
m_alertDao
;
@Inject
private
ProjectDao
m_projectDao
;
...
...
@@ -58,6 +64,19 @@ public class ExceptionAlert implements Task, LogEnabled {
private
Logger
m_logger
;
private
Alert
buildAlert
(
String
domainName
,
AlertException
exception
,
String
mailContent
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
new
Date
());
alert
.
setCategory
(
getName
());
alert
.
setType
(
exception
.
getType
());
alert
.
setContent
(
mailContent
);
alert
.
setMetric
(
exception
.
getName
());
return
alert
;
}
private
TopMetric
buildTopMetric
(
Date
date
)
{
TopReport
topReport
=
queryTopReport
(
date
);
TopMetric
topMetric
=
new
TopMetric
(
ALERT_PERIOD
,
Integer
.
MAX_VALUE
,
m_exceptionConfigManager
);
...
...
@@ -132,7 +151,7 @@ public class ExceptionAlert implements Task, LogEnabled {
for
(
Entry
<
String
,
List
<
AlertException
>>
entry
:
alertExceptions
.
entrySet
())
{
try
{
sendA
lertForDomain
(
entry
.
getKey
(),
entry
.
getValue
());
sendA
ndStoreAlert
(
entry
.
getKey
(),
entry
.
getValue
());
}
catch
(
Exception
e
)
{
m_logger
.
error
(
e
.
getMessage
());
}
...
...
@@ -155,17 +174,19 @@ public class ExceptionAlert implements Task, LogEnabled {
}
}
private
void
sendA
lertForDomain
(
String
domain
,
List
<
AlertException
>
exceptions
)
{
private
void
sendA
ndStoreAlert
(
String
domain
,
List
<
AlertException
>
exceptions
)
{
Project
project
=
queryProjectByDomain
(
domain
);
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
project
);
List
<
String
>
phones
=
m_alertConfig
.
buildSMSReceivers
(
project
);
String
mailTitle
=
m_alert
Builder
.
buildMailTitle
(
domain
);
String
mailTitle
=
m_alert
Config
.
buildMailTitle
(
domain
,
null
);
String
mailContent
=
m_alertBuilder
.
buildMailContent
(
exceptions
.
toString
(),
domain
);
m_mailSms
.
sendEmail
(
mailTitle
,
mailContent
,
emails
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
emails
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[邮件告警] "
+
mailTitle
+
" "
+
mailContent
);
storeAlerts
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
List
<
AlertException
>
errorExceptions
=
m_alertBuilder
.
buildErrorException
(
exceptions
);
if
(!
errorExceptions
.
isEmpty
())
{
...
...
@@ -177,6 +198,26 @@ public class ExceptionAlert implements Task, LogEnabled {
}
}
private
void
storeAlerts
(
String
domain
,
List
<
AlertException
>
exceptions
,
String
mailContent
)
{
for
(
AlertException
exception
:
exceptions
)
{
storeAlert
(
domain
,
exception
,
mailContent
);
}
}
private
void
storeAlert
(
String
domainName
,
AlertException
exception
,
String
mailContent
)
{
Alert
alert
=
buildAlert
(
domainName
,
exception
,
mailContent
);
try
{
int
count
=
m_alertDao
.
insert
(
alert
);
if
(
count
!=
1
)
{
Cat
.
logError
(
"insert alert error: "
+
alert
.
toString
(),
new
RuntimeException
());
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
@Override
public
void
shutdown
()
{
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
浏览文件 @
94f52e0a
...
...
@@ -25,10 +25,18 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
}
}
@Override
public
String
buildMailTitle
(
String
domain
,
String
configTitle
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"]"
);
return
sb
.
toString
();
}
private
List
<
String
>
buildProjectMailReceivers
(
Project
project
)
{
return
split
(
project
.
getEmail
());
}
public
List
<
String
>
buildSMSReceivers
(
Project
project
)
{
List
<
String
>
smsReceivers
=
new
ArrayList
<
String
>();
Receiver
receiver
=
m_manager
.
queryReceiverById
(
getId
());
...
...
@@ -42,7 +50,7 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
return
smsReceivers
;
}
}
private
List
<
String
>
buildProjectSMSReceivers
(
Project
project
)
{
return
split
(
project
.
getPhone
());
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlert.java
浏览文件 @
94f52e0a
...
...
@@ -14,6 +14,7 @@ import com.dianping.cat.consumer.company.model.entity.ProductLine;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.task.alert.BaseAlert
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
public
class
NetworkAlert
extends
BaseAlert
implements
Task
,
LogEnabled
{
...
...
@@ -29,6 +30,11 @@ public class NetworkAlert extends BaseAlert implements Task, LogEnabled {
public
String
getName
()
{
return
"network-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
@Override
public
void
run
()
{
...
...
@@ -82,9 +88,8 @@ public class NetworkAlert extends BaseAlert implements Task, LogEnabled {
}
@Override
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
metricT
itle
,
String
content
,
String
alertType
)
{
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
t
itle
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
String
title
=
m_alertConfig
.
buildMailTitle
(
productLine
,
metricTitle
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
浏览文件 @
94f52e0a
package
com.dianping.cat.report.task.alert.network
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
public
class
NetworkAlertConfig
extends
BaseAlertConfig
{
private
String
m_id
=
"network"
;
public
String
buildMailTitle
(
ProductLine
productLine
,
String
configTitle
)
{
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitle
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[网络告警] [产品线 "
).
append
(
product
Line
.
getTitle
()
).
append
(
"]"
);
sb
.
append
(
"[网络告警] [产品线 "
).
append
(
product
lineName
).
append
(
"]"
);
sb
.
append
(
"[网络指标 "
).
append
(
configTitle
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlert.java
浏览文件 @
94f52e0a
...
...
@@ -14,6 +14,7 @@ import com.dianping.cat.consumer.company.model.entity.ProductLine;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.task.alert.BaseAlert
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
public
class
SystemAlert
extends
BaseAlert
implements
Task
,
LogEnabled
{
...
...
@@ -29,6 +30,11 @@ public class SystemAlert extends BaseAlert implements Task, LogEnabled {
public
String
getName
()
{
return
"system-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
@Override
public
void
run
()
{
...
...
@@ -82,9 +88,8 @@ public class SystemAlert extends BaseAlert implements Task, LogEnabled {
}
@Override
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
metricT
itle
,
String
content
,
String
alertType
)
{
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
t
itle
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
String
title
=
m_alertConfig
.
buildMailTitle
(
productLine
,
metricTitle
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
浏览文件 @
94f52e0a
package
com.dianping.cat.report.task.alert.system
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
public
class
SystemAlertConfig
extends
BaseAlertConfig
{
private
String
m_id
=
"system"
;
public
String
buildMailTitle
(
ProductLine
productLine
,
String
configTitle
)
{
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitle
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[系统告警] [产品线 "
).
append
(
product
Line
.
getTitle
()
).
append
(
"]"
);
sb
.
append
(
"[系统告警] [产品线 "
).
append
(
product
lineName
).
append
(
"]"
);
sb
.
append
(
"[系统指标 "
).
append
(
configTitle
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/system/config/BaseRuleConfigManager.java
浏览文件 @
94f52e0a
...
...
@@ -15,7 +15,9 @@ import com.dianping.cat.home.rule.entity.MetricItem;
import
com.dianping.cat.home.rule.entity.MonitorRules
;
import
com.dianping.cat.home.rule.entity.Rule
;
import
com.dianping.cat.home.rule.transform.DefaultSaxParser
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.report.task.alert.MetricType
;
import
com.site.lookup.util.StringUtils
;
public
abstract
class
BaseRuleConfigManager
{
...
...
@@ -26,6 +28,8 @@ public abstract class BaseRuleConfigManager {
protected
MonitorRules
m_config
;
protected
abstract
String
getCategoryName
();
protected
abstract
String
getConfigName
();
public
MonitorRules
getMonitorRules
()
{
...
...
@@ -43,27 +47,29 @@ public abstract class BaseRuleConfigManager {
}
}
public
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
queryConfigs
(
String
metricKey
,
MetricType
type
)
{
public
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
queryConfigs
(
String
product
,
String
metricKey
,
MetricType
type
)
{
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
configs
=
new
ArrayList
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>();
for
(
Rule
rule
:
m_config
.
getRules
().
values
())
{
List
<
MetricItem
>
items
=
rule
.
getMetricItems
();
for
(
MetricItem
item
:
items
)
{
String
checkType
=
item
.
getType
();
String
context
=
item
.
get
Text
();
String
productText
=
item
.
getProductText
();
String
metricItemText
=
item
.
getMetricItem
Text
();
boolean
validate
=
false
;
if
(
type
==
MetricType
.
COUNT
&&
item
.
isMonitorCount
())
{
validate
=
validate
(
checkType
,
contex
t
,
metricKey
);
validate
=
validate
(
productText
,
metricItemText
,
produc
t
,
metricKey
);
}
else
if
(
type
==
MetricType
.
AVG
&&
item
.
isMonitorAvg
())
{
validate
=
validate
(
checkType
,
contex
t
,
metricKey
);
validate
=
validate
(
productText
,
metricItemText
,
produc
t
,
metricKey
);
}
else
if
(
type
==
MetricType
.
SUM
&&
item
.
isMonitorSum
())
{
validate
=
validate
(
checkType
,
contex
t
,
metricKey
);
validate
=
validate
(
productText
,
metricItemText
,
produc
t
,
metricKey
);
}
if
(
validate
)
{
configs
.
addAll
(
rule
.
getConfigs
());
Cat
.
logEvent
(
"FindRule"
,
getCategoryName
(),
Event
.
SUCCESS
,
"find rule for "
+
metricKey
+
": "
+
rule
.
toString
());
break
;
}
}
...
...
@@ -89,24 +95,27 @@ public abstract class BaseRuleConfigManager {
return
true
;
}
public
boolean
validate
(
String
type
,
String
context
,
String
metricKey
)
{
if
(
type
.
equals
(
"id"
))
{
if
(
context
.
equals
(
metricKey
))
{
return
true
;
public
boolean
validate
(
String
productText
,
String
metricKeyText
,
String
product
,
String
metricKey
)
{
if
(
StringUtils
.
isEmpty
(
productText
))
{
return
validateRegex
(
metricKeyText
,
metricKey
);
}
else
{
if
(
validateRegex
(
productText
,
product
))
{
return
validateRegex
(
metricKeyText
,
metricKey
);
}
else
{
return
false
;
}
}
else
if
(
type
.
equals
(
"regex"
))
{
Pattern
p
=
Pattern
.
compile
(
context
);
Matcher
matcher
=
p
.
matcher
(
metricKey
);
}
}
if
(
matcher
.
find
())
{
return
true
;
}
else
{
return
false
;
}
public
boolean
validateRegex
(
String
regexText
,
String
text
)
{
Pattern
p
=
Pattern
.
compile
(
regexText
);
Matcher
m
=
p
.
matcher
(
text
);
if
(
m
.
find
())
{
return
true
;
}
else
{
return
false
;
}
return
false
;
}
}
cat-home/src/main/java/com/dianping/cat/system/config/BusinessRuleConfigManager.java
浏览文件 @
94f52e0a
...
...
@@ -19,10 +19,13 @@ import com.dianping.cat.home.rule.entity.MonitorRules;
import
com.dianping.cat.home.rule.entity.Rule
;
import
com.dianping.cat.home.rule.entity.SubCondition
;
import
com.dianping.cat.home.rule.transform.DefaultSaxParser
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.report.task.alert.MetricType
;
public
class
BusinessRuleConfigManager
extends
BaseRuleConfigManager
implements
Initializable
{
private
static
final
String
CATEGORY_NAME
=
"business"
;
private
static
final
String
CONFIG_NAME
=
"businessRuleConfig"
;
public
String
updateRule
(
String
ruleContent
)
throws
SAXException
,
IOException
{
...
...
@@ -47,18 +50,23 @@ public class BusinessRuleConfigManager extends BaseRuleConfigManager implements
return
config
;
}
private
Rule
buildDefaultRule
(
String
metricKey
)
{
private
Rule
buildDefaultRule
(
String
product
,
String
metricKey
)
{
Rule
rule
=
new
Rule
(
metricKey
);
MetricItem
item
=
new
MetricItem
();
item
.
set
Type
(
"id"
);
item
.
setText
(
metricKey
);
item
.
set
ProductText
(
product
);
item
.
set
MetricItem
Text
(
metricKey
);
rule
.
addMetricItem
(
item
);
rule
.
addConfig
(
buildDefaultConfig
());
return
rule
;
}
@Override
protected
String
getCategoryName
()
{
return
CATEGORY_NAME
;
}
@Override
protected
String
getConfigName
()
{
return
CONFIG_NAME
;
...
...
@@ -96,7 +104,7 @@ public class BusinessRuleConfigManager extends BaseRuleConfigManager implements
}
@Override
public
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
queryConfigs
(
String
metricKey
,
MetricType
type
)
{
public
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
queryConfigs
(
String
product
,
String
metricKey
,
MetricType
type
)
{
Rule
rule
=
m_config
.
getRules
().
get
(
metricKey
);
List
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>
configs
=
new
ArrayList
<
com
.
dianping
.
cat
.
home
.
rule
.
entity
.
Config
>();
...
...
@@ -120,17 +128,20 @@ public class BusinessRuleConfigManager extends BaseRuleConfigManager implements
if
(
configs
.
size
()
==
0
)
{
configs
.
add
(
buildDefaultConfig
());
}
Cat
.
logEvent
(
"FindRule"
,
getCategoryName
(),
Event
.
SUCCESS
,
"find rule for "
+
metricKey
+
": "
+
rule
.
toString
());
return
configs
;
}
}
public
Rule
queryRule
(
String
metricKey
)
{
public
Rule
queryRule
(
String
product
,
String
metricKey
)
{
Rule
rule
=
m_config
.
getRules
().
get
(
metricKey
);
if
(
rule
!=
null
)
{
return
rule
;
}
else
{
return
buildDefaultRule
(
metricKey
);
return
buildDefaultRule
(
product
,
metricKey
);
}
}
...
...
cat-home/src/main/java/com/dianping/cat/system/config/NetworkRuleConfigManager.java
浏览文件 @
94f52e0a
...
...
@@ -15,8 +15,15 @@ import com.dianping.cat.home.rule.transform.DefaultSaxParser;
public
class
NetworkRuleConfigManager
extends
BaseRuleConfigManager
implements
Initializable
{
private
static
final
String
CATEGORY_NAME
=
"network"
;
private
static
final
String
CONFIG_NAME
=
"networkRuleConfig"
;
@Override
protected
String
getCategoryName
()
{
return
CATEGORY_NAME
;
}
@Override
protected
String
getConfigName
()
{
return
CONFIG_NAME
;
...
...
cat-home/src/main/java/com/dianping/cat/system/config/SystemRuleConfigManager.java
浏览文件 @
94f52e0a
...
...
@@ -13,12 +13,19 @@ import com.dianping.cat.home.rule.transform.DefaultSaxParser;
public
class
SystemRuleConfigManager
extends
BaseRuleConfigManager
implements
Initializable
{
private
static
final
String
CATEGORY_NAME
=
"system"
;
private
static
final
String
CONFIG_NAME
=
"systemRuleConfig"
;
@Override
protected
String
getConfigName
()
{
return
CONFIG_NAME
;
}
protected
String
getCategoryName
()
{
return
CATEGORY_NAME
;
}
@Override
protected
String
getConfigName
()
{
return
CONFIG_NAME
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
...
...
cat-home/src/main/java/com/dianping/cat/system/page/config/Handler.java
浏览文件 @
94f52e0a
...
...
@@ -524,7 +524,7 @@ public class Handler implements PageHandler<Context> {
private
void
metricRuleAdd
(
Payload
payload
,
Model
model
)
{
String
key
=
m_metricConfigManager
.
buildMetricKey
(
payload
.
getDomain
(),
payload
.
getType
(),
payload
.
getMetricKey
());
model
.
setMetricItemConfigRule
(
m_businessRuleConfigManager
.
queryRule
(
key
).
toString
());
model
.
setMetricItemConfigRule
(
m_businessRuleConfigManager
.
queryRule
(
payload
.
getProductLineName
(),
key
).
toString
());
}
private
boolean
metricRuleAddSubmit
(
Payload
payload
,
Model
model
)
{
...
...
cat-home/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
浏览文件 @
94f52e0a
<?xml version="1.0" encoding="UTF-8"?>
<entities>
<entity
name=
"alert"
table=
"alert"
alias=
"a"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"128"
nullable=
"false"
/>
<member
name=
"alert-time"
field=
"alert_time"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"category"
field=
"category"
value-type=
"String"
length=
"64"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"String"
length=
"64"
nullable=
"false"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"65535"
nullable=
"false"
/>
<member
name=
"metric"
field=
"metric"
value-type=
"String"
length=
"128"
nullable=
"false"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
<readsets>
<readset
name=
"FULL"
all=
"true"
/>
</readsets>
<updatesets>
<updateset
name=
"FULL"
all=
"true"
/>
</updatesets>
<query-defs>
<query
name=
"find-by-PK"
type=
"SELECT"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"insert"
type=
"INSERT"
>
<statement>
<![CDATA[INSERT INTO <TABLE/>
(
<FIELDS/>
)
VALUES(
<VALUES/>
)]]>
</statement>
</query>
<query
name=
"update-by-PK"
type=
"UPDATE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[UPDATE <TABLE/>
SET
<FIELDS/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"delete-by-PK"
type=
"DELETE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[DELETE FROM <TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
</query-defs>
</entity>
<entity
name=
"alteration"
table=
"alteration"
alias=
"a"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"type"
field=
"type"
value-type=
"String"
length=
"64"
nullable=
"false"
/>
...
...
cat-home/src/main/resources/META-INF/dal/jdbc/report-dal.xml
浏览文件 @
94f52e0a
<?xml version="1.0" encoding="UTF-8"?>
<entities
do-package=
"com.dianping.cat.home.dal.report"
gen=
"true"
>
<entity
name=
"alert"
table=
"alert"
alias=
"al"
>
<member
name=
"creation-date"
insert-expr=
"NOW()"
/>
</entity>
<entity
name=
"alteration"
table=
"alteration"
alias=
"a"
>
<member
name=
"creation-date"
insert-expr=
"NOW()"
/>
<var
name=
"start-time"
value-type=
"Date"
/>
...
...
cat-home/src/main/resources/META-INF/dal/model/monitor-rules-codegen.xml
浏览文件 @
94f52e0a
...
...
@@ -9,11 +9,11 @@
<entity-ref
name=
"config"
/>
</entity>
<entity
name=
"metric-item"
>
<attribute
name=
"type"
value-type=
"String"
/>
<attribute
name=
"monitorCount"
value-type=
"boolean"
/>
<attribute
name=
"monitorSum"
value-type=
"boolean"
/>
<attribute
name=
"monitorAvg"
value-type=
"boolean"
/>
<attribute
name=
"text"
value-type=
"String"
/>
<attribute
name=
"productText"
value-type=
"String"
/>
<attribute
name=
"metricItemText"
value-type=
"String"
/>
</entity>
<entity
name=
"config"
>
<attribute
name=
"starttime"
value-type=
"String"
/>
...
...
cat-home/src/main/resources/META-INF/dal/model/monitor-rules-model.xml
浏览文件 @
94f52e0a
...
...
@@ -10,11 +10,11 @@
<entity-ref
name=
"config"
type=
"list"
names=
"configs"
/>
</entity>
<entity
name=
"metric-item"
>
<attribute
name=
"type"
value-type=
"String"
/>
<attribute
name=
"monitorCount"
value-type=
"boolean"
/>
<attribute
name=
"monitorSum"
value-type=
"boolean"
/>
<attribute
name=
"monitorAvg"
value-type=
"boolean"
/>
<attribute
name=
"text"
value-type=
"String"
/>
<attribute
name=
"productText"
value-type=
"String"
/>
<attribute
name=
"metricItemText"
value-type=
"String"
/>
</entity>
<entity
name=
"config"
>
<attribute
name=
"starttime"
value-type=
"String"
/>
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
94f52e0a
...
...
@@ -1814,6 +1814,9 @@
<requirement>
<role>
com.dianping.cat.report.task.alert.AlertInfo
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.RemoteMetricReportService
</role>
</requirement>
...
...
@@ -1847,6 +1850,9 @@
<requirement>
<role>
com.dianping.cat.report.task.alert.AlertInfo
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.RemoteMetricReportService
</role>
</requirement>
...
...
@@ -1880,6 +1886,9 @@
<requirement>
<role>
com.dianping.cat.report.task.alert.AlertInfo
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.RemoteMetricReportService
</role>
</requirement>
...
...
@@ -1919,6 +1928,9 @@
<requirement>
<role>
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
top
</role-hint>
...
...
@@ -1941,6 +1953,16 @@
<datasourceFile>
/data/appdatas/cat/datasources.xml
</datasourceFile>
</configuration>
</component>
<component>
<role>
org.unidal.dal.jdbc.mapping.TableProvider
</role>
<role-hint>
alert
</role-hint>
<implementation>
org.unidal.dal.jdbc.mapping.SimpleTableProvider
</implementation>
<configuration>
<logical-table-name>
alert
</logical-table-name>
<physical-table-name>
alert
</physical-table-name>
<data-source-name>
cat
</data-source-name>
</configuration>
</component>
<component>
<role>
org.unidal.dal.jdbc.mapping.TableProvider
</role>
<role-hint>
alteration
</role-hint>
...
...
@@ -2021,6 +2043,15 @@
<data-source-name>
cat
</data-source-name>
</configuration>
</component>
<component>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
<implementation>
com.dianping.cat.home.dal.report.AlertDao
</implementation>
<requirements>
<requirement>
<role>
org.unidal.dal.jdbc.QueryEngine
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.home.dal.report.AlterationDao
</role>
<implementation>
com.dianping.cat.home.dal.report.AlterationDao
</implementation>
...
...
cat-home/src/main/resources/META-INF/wizard/jdbc/wizard.xml
浏览文件 @
94f52e0a
...
...
@@ -16,6 +16,7 @@
<table
name=
"daily_report_content"
/>
<table
name=
"monthly_report_content"
/>
<table
name=
"weekly_report_content"
/>
<table
name=
"alert"
/>
</group>
<group
name=
"alarm"
package=
"com.dianping.cat.home.dal.alarm"
>
<table
name=
"mailRecord"
/>
...
...
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
浏览文件 @
94f52e0a
...
...
@@ -9,7 +9,6 @@ import junit.framework.Assert;
import
org.junit.Test
;
import
org.unidal.helper.Files
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.home.rule.entity.Condition
;
...
...
@@ -17,6 +16,7 @@ import com.dianping.cat.home.rule.entity.Config;
import
com.dianping.cat.home.rule.entity.MonitorRules
;
import
com.dianping.cat.home.rule.entity.Rule
;
import
com.dianping.cat.home.rule.transform.DefaultSaxParser
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.DataChecker
;
import
com.dianping.cat.report.task.alert.DefaultDataChecker
;
...
...
@@ -26,13 +26,13 @@ public class RuleConfigTest {
private
List
<
Condition
>
buildConditions
(
List
<
Config
>
configs
)
{
List
<
Condition
>
conditions
=
new
ArrayList
<
Condition
>();
for
(
Config
config
:
configs
)
{
for
(
Config
config
:
configs
)
{
conditions
.
addAll
(
config
.
getConditions
());
}
return
conditions
;
}
}
private
Map
<
String
,
List
<
Condition
>>
buildConfigMap
(
MonitorRules
monitorRules
)
{
if
(
monitorRules
==
null
||
monitorRules
.
getRules
().
size
()
==
0
)
{
...
...
@@ -45,10 +45,10 @@ public class RuleConfigTest {
String
id
=
rule
.
getId
();
List
<
Condition
>
ruleConditions
=
buildConditions
(
rule
.
getConfigs
());
List
<
Condition
>
conditions
=
map
.
get
(
id
);
if
(
conditions
==
null
)
{
map
.
put
(
id
,
ruleConditions
);
}
else
{
}
else
{
conditions
.
addAll
(
ruleConditions
);
}
}
...
...
@@ -69,19 +69,19 @@ public class RuleConfigTest {
@Test
public
void
testCondition
()
{
Map
<
String
,
List
<
Condition
>>
conditionsMap
=
buildConfigMap
(
buildMonitorRuleFromFile
(
"/config/demo-rule-monitor.xml"
));
Triple
<
Boolean
,
String
,
String
>
result
;
AlertResultEntity
result
;
Assert
.
assertNotNull
(
conditionsMap
);
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value7
,
baseline7
,
conditionsMap
.
get
(
"conditionCombination"
));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline8
=
{
200
,
200
};
double
[]
value8
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value8
,
baseline8
,
conditionsMap
.
get
(
"subconditionCombination"
));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
}
@Test
...
...
@@ -92,8 +92,8 @@ public class RuleConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
Triple
<
Boolean
,
String
,
String
>
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
@Test
...
...
@@ -104,7 +104,7 @@ public class RuleConfigTest {
double
baseline
[]
=
{
200
,
350
};
double
value
[]
=
{
100
,
50
};
Triple
<
Boolean
,
String
,
String
>
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
}
cat-home/src/test/java/com/dianping/cat/report/task/alert/MetricIdAndRuleMappingTest.java
浏览文件 @
94f52e0a
...
...
@@ -24,6 +24,11 @@ public class MetricIdAndRuleMappingTest {
protected
String
getConfigName
()
{
return
null
;
}
@Override
protected
String
getCategoryName
()
{
return
null
;
}
};
private
List
<
String
>
buildPatternList
(
String
path
)
{
...
...
@@ -39,7 +44,7 @@ public class MetricIdAndRuleMappingTest {
boolean
tmpResult
=
false
;
for
(
String
pattern
:
patterns
)
{
tmpResult
=
m_manager
.
validate
(
"regex"
,
pattern
,
text
);
tmpResult
=
m_manager
.
validate
(
null
,
pattern
,
null
,
text
);
if
(
tmpResult
)
{
return
tmpResult
;
...
...
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
浏览文件 @
94f52e0a
...
...
@@ -9,7 +9,6 @@ import junit.framework.Assert;
import
org.junit.Test
;
import
org.unidal.helper.Files
;
import
org.unidal.tuple.Triple
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
...
...
@@ -19,6 +18,7 @@ import com.dianping.cat.home.rule.entity.MonitorRules;
import
com.dianping.cat.home.rule.entity.Rule
;
import
com.dianping.cat.home.rule.entity.SubCondition
;
import
com.dianping.cat.home.rule.transform.DefaultSaxParser
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.DataChecker
;
import
com.dianping.cat.report.task.alert.DefaultDataChecker
;
...
...
@@ -39,16 +39,16 @@ public class AlertConfigTest {
return
map
;
}
private
List
<
Condition
>
buildConditions
(
List
<
Config
>
configs
)
{
List
<
Condition
>
conditions
=
new
ArrayList
<
Condition
>();
for
(
Config
config
:
configs
)
{
for
(
Config
config
:
configs
)
{
conditions
.
addAll
(
config
.
getConditions
());
}
return
conditions
;
}
}
private
MonitorRules
buildMonitorRuleFromFile
(
String
path
)
{
try
{
...
...
@@ -59,7 +59,7 @@ public class AlertConfigTest {
return
null
;
}
}
private
List
<
Config
>
convert
(
MetricItemConfig
metricItemConfig
)
{
List
<
Config
>
configs
=
new
ArrayList
<
Config
>();
Config
config
=
new
Config
();
...
...
@@ -86,7 +86,6 @@ public class AlertConfigTest {
return
configs
;
}
@Test
public
void
test
()
{
DataChecker
alertConfig
=
new
DefaultDataChecker
();
...
...
@@ -95,53 +94,53 @@ public class AlertConfigTest {
double
baseline
[]
=
{
100
,
100
};
double
value
[]
=
{
200
,
200
};
Triple
<
Boolean
,
String
,
String
>
result
=
alertConfig
.
checkData
(
value
,
baseline
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
AlertResultEntity
result
=
alertConfig
.
checkData
(
value
,
baseline
,
conditions
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
double
[]
baseline2
=
{
100
,
100
};
double
[]
value2
=
{
49
,
49
};
result
=
alertConfig
.
checkData
(
value2
,
baseline2
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
double
[]
baseline3
=
{
100
,
100
};
double
[]
value3
=
{
51
,
49
};
result
=
alertConfig
.
checkData
(
value3
,
baseline3
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
double
[]
baseline4
=
{
50
,
50
};
double
[]
value4
=
{
10
,
10
};
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
41
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
79
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
double
[]
baseline5
=
{
117
,
118
};
double
[]
value5
=
{
43
,
48
};
...
...
@@ -149,7 +148,7 @@ public class AlertConfigTest {
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value5
,
baseline5
,
conditions
);
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
@Test
...
...
@@ -160,8 +159,8 @@ public class AlertConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
Triple
<
Boolean
,
String
,
String
>
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
@Test
...
...
@@ -172,42 +171,42 @@ public class AlertConfigTest {
double
baseline
[]
=
{
200
,
200
};
double
value
[]
=
{
100
,
100
};
Triple
<
Boolean
,
String
,
String
>
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"decreasePercentage"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"decreasePercentage"
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline2
=
{
200
,
300
};
double
[]
value2
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value2
,
baseline2
,
buildConditions
(
configMap
.
get
(
"decreaseValue"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline3
=
{
200
,
50
};
double
[]
value3
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value3
,
baseline3
,
buildConditions
(
configMap
.
get
(
"increasePercentage"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline4
=
{
200
,
50
};
double
[]
value4
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value4
,
baseline4
,
buildConditions
(
configMap
.
get
(
"increaseValue"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline5
=
{
200
,
200
};
double
[]
value5
=
{
500
,
600
};
result
=
m_checker
.
checkData
(
value5
,
baseline5
,
buildConditions
(
configMap
.
get
(
"absoluteMaxValue"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline6
=
{
200
,
200
};
double
[]
value6
=
{
50
,
40
};
result
=
m_checker
.
checkData
(
value6
,
baseline6
,
buildConditions
(
configMap
.
get
(
"absoluteMinValue"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value7
,
baseline7
,
buildConditions
(
configMap
.
get
(
"conditionCombination"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
true
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline8
=
{
200
,
200
};
double
[]
value8
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value8
,
baseline8
,
buildConditions
(
configMap
.
get
(
"subconditionCombination"
)));
Assert
.
assertEquals
(
result
.
getFirst
().
booleanValue
(),
false
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
}
}
cat-home/src/test/resources/config/demo-rule-monitor.xml
浏览文件 @
94f52e0a
<monitor-rules>
<rule
id=
"demo1"
>
<metric-item
type=
"id"
t
ext=
"f5-2400-1-dianping-com:2400-1-dianping-com:1/1-1-in"
>
<metric-item
metricItemT
ext=
"f5-2400-1-dianping-com:2400-1-dianping-com:1/1-1-in"
>
</metric-item>
<metric-item
type=
"regex"
t
ext=
"switch\w*:\w*:\w*in\w*"
>
<metric-item
metricItemT
ext=
"switch\w*:\w*:\w*in\w*"
>
</metric-item>
<config
starttime=
"00:00"
endtime=
"24:00"
>
...
...
cat-home/src/test/resources/config/monitor-rule.xml
浏览文件 @
94f52e0a
此差异已折叠。
点击以展开。
script/Cat.sql
浏览文件 @
94f52e0a
...
...
@@ -311,3 +311,14 @@ CREATE TABLE `alteration` (
KEY
`ind_date_domain_host`
(
`date`
,
`domain`
,
`hostname`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1241
DEFAULT
CHARSET
=
utf8
COMMENT
=
'变更表'
;
CREATE
TABLE
`alert`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'自增长ID'
,
`domain`
varchar
(
128
)
NOT
NULL
COMMENT
'告警项目'
,
`alert_time`
datetime
NOT
NULL
COMMENT
'告警时间'
,
`category`
varchar
(
64
)
NOT
NULL
COMMENT
'告警分类:network/business/system/exception -alert'
,
`type`
varchar
(
64
)
NOT
NULL
COMMENT
'告警类型:error/warning'
,
`content`
text
NOT
NULL
COMMENT
'告警内容'
,
`metric`
varchar
(
128
)
NOT
NULL
COMMENT
'告警指标'
,
`creation_date`
datetime
NOT
NULL
COMMENT
'数据插入时间'
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
COMMENT
=
'存储告警信息'
;
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录