Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
72bba79d
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,发现更多精彩内容 >>
提交
72bba79d
编写于
7月 23, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change apis
上级
10a48e0a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
112 addition
and
62 deletion
+112
-62
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
...com/dianping/cat/report/task/alert/AlertResultEntity.java
+0
-7
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
.../java/com/dianping/cat/report/task/alert/DataChecker.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
...om/dianping/cat/report/task/alert/DefaultDataChecker.java
+5
-8
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
...com/dianping/cat/report/task/alert/sender/BaseSender.java
+1
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/MailSender.java
...com/dianping/cat/report/task/alert/sender/MailSender.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/SmsSender.java
.../com/dianping/cat/report/task/alert/sender/SmsSender.java
+2
-6
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/WeixinSender.java
...m/dianping/cat/report/task/alert/sender/WeixinSender.java
+1
-5
cat-home/src/main/java/com/dianping/cat/system/config/AlertTypeManager.java
...java/com/dianping/cat/system/config/AlertTypeManager.java
+34
-0
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
...st/java/com/dianping/cat/report/alert/RuleConfigTest.java
+20
-5
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
.../com/dianping/cat/report/task/metric/AlertConfigTest.java
+47
-27
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
浏览文件 @
72bba79d
...
...
@@ -11,13 +11,6 @@ public class AlertResultEntity {
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
;
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
浏览文件 @
72bba79d
...
...
@@ -5,6 +5,6 @@ import java.util.List;
import
com.dianping.cat.home.rule.entity.Condition
;
public
interface
DataChecker
{
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
public
List
<
AlertResultEntity
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
浏览文件 @
72bba79d
package
com.dianping.cat.report.task.alert
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.unidal.tuple.Pair
;
...
...
@@ -25,8 +26,8 @@ public class DefaultDataChecker implements DataChecker {
return
result
;
}
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
AlertResultEntity
result
=
new
AlertResultEntity
();
public
List
<
AlertResultEntity
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
List
<
AlertResultEntity
>
alertResults
=
new
ArrayList
<
AlertResultEntity
>
();
for
(
Condition
condition
:
conditions
)
{
int
conditionMinute
=
condition
.
getMinute
();
...
...
@@ -37,15 +38,11 @@ public class DefaultDataChecker implements DataChecker {
if
(
condResult
.
getKey
()
==
true
)
{
String
alertType
=
condition
.
getAlertType
();
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
return
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
else
{
result
=
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
alertResults
.
add
(
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
));
}
}
return
result
;
return
alertResults
;
}
private
Pair
<
Boolean
,
String
>
checkDataByCondition
(
double
[]
value
,
double
[]
baseline
,
Condition
condition
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
浏览文件 @
72bba79d
...
...
@@ -17,8 +17,7 @@ public abstract class BaseSender implements LogEnabled {
protected
abstract
void
sendLog
(
String
title
,
String
content
,
List
<
String
>
receivers
);
public
abstract
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
);
public
abstract
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
);
@Override
public
void
enableLogging
(
Logger
logger
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/MailSender.java
浏览文件 @
72bba79d
...
...
@@ -20,7 +20,7 @@ public class MailSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
m_mailSms
.
sendEmail
(
title
,
content
,
receivers
);
sendLog
(
title
,
content
,
receivers
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/SmsSender.java
浏览文件 @
72bba79d
...
...
@@ -5,7 +5,7 @@ import java.util.List;
import
com.dianping.cat.Cat
;
public
class
SmsSender
extends
BaseSender
{
@Override
protected
void
sendLog
(
String
title
,
String
content
,
List
<
String
>
receivers
)
{
StringBuilder
builder
=
new
StringBuilder
();
...
...
@@ -20,11 +20,7 @@ public class SmsSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
m_mailSms
.
sendSms
(
title
,
content
,
receivers
);
sendLog
(
title
,
content
,
receivers
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/WeixinSender.java
浏览文件 @
72bba79d
...
...
@@ -19,11 +19,7 @@ public class WeixinSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
content
=
content
.
replaceAll
(
"<br/>"
,
"\n"
);
m_mailSms
.
sendWeiXin
(
title
,
content
,
domain
,
mergeList
(
receivers
));
...
...
cat-home/src/main/java/com/dianping/cat/system/config/AlertTypeManager.java
浏览文件 @
72bba79d
...
...
@@ -11,6 +11,9 @@ import com.dianping.cat.core.config.Config;
import
com.dianping.cat.core.config.ConfigDao
;
import
com.dianping.cat.core.config.ConfigEntity
;
import
com.dianping.cat.home.alert.type.entity.AlertType
;
import
com.dianping.cat.home.alert.type.entity.Category
;
import
com.dianping.cat.home.alert.type.entity.Domain
;
import
com.dianping.cat.home.alert.type.entity.Type
;
import
com.dianping.cat.home.alert.type.transform.DefaultSaxParser
;
public
class
AlertTypeManager
implements
Initializable
{
...
...
@@ -24,10 +27,41 @@ public class AlertTypeManager implements Initializable {
private
static
final
String
CONFIG_NAME
=
"alertType"
;
private
static
final
String
DEFAULT_TYPE
=
"default"
;
public
AlertType
getAlertType
()
{
return
m_config
;
}
public
Type
getType
(
String
categoryName
,
String
domainName
,
String
typeName
)
{
try
{
Category
category
=
m_config
.
findCategory
(
categoryName
);
Domain
domain
=
category
.
findDomain
(
domainName
);
if
(
domain
==
null
)
{
domain
=
category
.
findDomain
(
DEFAULT_TYPE
);
}
Type
type
=
domain
.
findType
(
typeName
);
if
(
type
==
null
)
{
type
=
generateDefaultType
();
}
return
type
;
}
catch
(
Exception
ex
)
{
return
generateDefaultType
();
}
}
private
Type
generateDefaultType
()
{
Type
type
=
new
Type
();
type
.
setSendMail
(
true
);
type
.
setSendWeixin
(
true
);
type
.
setSendSms
(
false
);
return
type
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
try
{
...
...
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
浏览文件 @
72bba79d
...
...
@@ -75,13 +75,13 @@ public class RuleConfigTest {
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value7
,
baseline7
,
conditionsMap
.
get
(
"conditionCombination"
));
result
=
extractError
(
m_check
.
checkData
(
value7
,
baseline7
,
conditionsMap
.
get
(
"conditionCombination"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline8
=
{
200
,
200
};
double
[]
value8
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value8
,
baseline8
,
conditionsMap
.
get
(
"subconditionCombination"
));
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
m_check
.
checkData
(
value8
,
baseline8
,
conditionsMap
.
get
(
"subconditionCombination"
)
));
Assert
.
assert
Null
(
result
);
}
@Test
...
...
@@ -92,7 +92,7 @@ public class RuleConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
));
AlertResultEntity
result
=
extractError
(
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -104,7 +104,22 @@ public class RuleConfigTest {
double
baseline
[]
=
{
200
,
350
};
double
value
[]
=
{
100
,
50
};
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
));
AlertResultEntity
result
=
extractError
(
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
private
AlertResultEntity
extractError
(
List
<
AlertResultEntity
>
alertResults
)
{
int
length
=
alertResults
.
size
();
if
(
length
==
0
)
{
return
null
;
}
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
if
(
alertResult
.
getAlertType
().
equals
(
"error"
))
{
return
alertResult
;
}
}
return
alertResults
.
get
(
length
-
1
);
}
}
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
浏览文件 @
72bba79d
...
...
@@ -94,60 +94,60 @@ public class AlertConfigTest {
double
baseline
[]
=
{
100
,
100
};
double
value
[]
=
{
200
,
200
};
AlertResultEntity
result
=
alertConfig
.
checkData
(
value
,
baseline
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
AlertResultEntity
result
=
extractError
(
alertConfig
.
checkData
(
value
,
baseline
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline2
=
{
100
,
100
};
double
[]
value2
=
{
49
,
49
};
result
=
alertConfig
.
checkData
(
value2
,
baseline2
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value2
,
baseline2
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline3
=
{
100
,
100
};
double
[]
value3
=
{
51
,
49
};
result
=
alertConfig
.
checkData
(
value3
,
baseline3
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value3
,
baseline3
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline4
=
{
50
,
50
};
double
[]
value4
=
{
10
,
10
};
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
41
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
79
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline5
=
{
117
,
118
};
double
[]
value5
=
{
43
,
48
};
itemConfig
.
setDecreasePercentage
(
50
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value5
,
baseline5
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value5
,
baseline5
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -159,7 +159,8 @@ public class AlertConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
)));
AlertResultEntity
result
=
extractError
(
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -171,42 +172,61 @@ public class AlertConfigTest {
double
baseline
[]
=
{
200
,
200
};
double
value
[]
=
{
100
,
100
};
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"decreasePercentage"
)));
AlertResultEntity
result
=
extractError
(
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"
)));
result
=
extractError
(
m_checker
.
checkData
(
value2
,
baseline2
,
buildConditions
(
configMap
.
get
(
"decreaseValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline3
=
{
200
,
50
};
double
[]
value3
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value3
,
baseline3
,
buildConditions
(
configMap
.
get
(
"increasePercentage"
)));
result
=
extractError
(
m_checker
.
checkData
(
value3
,
baseline3
,
buildConditions
(
configMap
.
get
(
"increasePercentage"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline4
=
{
200
,
50
};
double
[]
value4
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value4
,
baseline4
,
buildConditions
(
configMap
.
get
(
"increaseValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value4
,
baseline4
,
buildConditions
(
configMap
.
get
(
"increaseValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline5
=
{
200
,
200
};
double
[]
value5
=
{
500
,
600
};
result
=
m_checker
.
checkData
(
value5
,
baseline5
,
buildConditions
(
configMap
.
get
(
"absoluteMaxValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value5
,
baseline5
,
buildConditions
(
configMap
.
get
(
"absoluteMaxValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline6
=
{
200
,
200
};
double
[]
value6
=
{
50
,
40
};
result
=
m_checker
.
checkData
(
value6
,
baseline6
,
buildConditions
(
configMap
.
get
(
"absoluteMinValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value6
,
baseline6
,
buildConditions
(
configMap
.
get
(
"absoluteMinValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value7
,
baseline7
,
buildConditions
(
configMap
.
get
(
"conditionCombination"
)));
result
=
extractError
(
m_checker
.
checkData
(
value7
,
baseline7
,
buildConditions
(
configMap
.
get
(
"conditionCombination"
))));
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
.
isTriggered
(),
false
);
result
=
extractError
(
m_checker
.
checkData
(
value8
,
baseline8
,
buildConditions
(
configMap
.
get
(
"subconditionCombination"
))));
Assert
.
assertNull
(
result
);
}
private
AlertResultEntity
extractError
(
List
<
AlertResultEntity
>
alertResults
)
{
int
length
=
alertResults
.
size
();
if
(
length
==
0
)
{
return
null
;
}
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
if
(
alertResult
.
getAlertType
().
equals
(
"error"
))
{
return
alertResult
;
}
}
return
alertResults
.
get
(
length
-
1
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录