Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
eaf3de7d
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,发现更多精彩内容 >>
提交
eaf3de7d
编写于
6月 12, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor RuleType
上级
2c6c1ced
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
232 addition
and
68 deletion
+232
-68
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
...om/dianping/cat/report/task/alert/DefaultDataChecker.java
+17
-47
cat-home/src/main/java/com/dianping/cat/report/task/alert/RuleType.java
...ain/java/com/dianping/cat/report/task/alert/RuleType.java
+215
-21
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
浏览文件 @
eaf3de7d
package
com.dianping.cat.report.task.alert
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.List
;
import
org.unidal.tuple.Pair
;
...
...
@@ -14,8 +11,6 @@ import com.dianping.cat.home.rule.entity.SubCondition;
public
class
DefaultDataChecker
implements
DataChecker
{
private
DecimalFormat
m_df
=
new
DecimalFormat
(
"0.0"
);
private
static
final
Long
ONE_MINUTE_MILLSEC
=
60000L
;
private
double
[]
buildLastMinutesDoubleArray
(
double
[]
doubleList
,
int
remainCount
)
{
...
...
@@ -54,32 +49,27 @@ public class DefaultDataChecker implements DataChecker {
}
private
Pair
<
Boolean
,
String
>
checkDataByCondition
(
double
[]
value
,
double
[]
baseline
,
Condition
condition
)
{
int
length
=
value
.
length
;
StringBuilder
baselines
=
new
StringBuilder
();
StringBuilder
values
=
new
StringBuilder
();
double
valueSum
=
0
;
double
baselineSum
=
0
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
baselines
.
append
(
m_df
.
format
(
baseline
[
i
])).
append
(
" "
);
values
.
append
(
m_df
.
format
(
value
[
i
])).
append
(
" "
);
valueSum
=
valueSum
+
value
[
i
];
baselineSum
=
baselineSum
+
baseline
[
i
];
if
(!
checkDataByMinute
(
condition
,
value
[
i
],
baseline
[
i
]))
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
SubCondition
subCondition
:
condition
.
getSubConditions
())
{
try
{
String
ruleType
=
subCondition
.
getType
();
double
ruleValue
=
parseSubConditionText
(
subCondition
.
getText
());
RuleType
rule
=
RuleType
.
getByTypeId
(
ruleType
);
Pair
<
Boolean
,
String
>
subResult
=
rule
.
executeRule
(
value
,
baseline
,
ruleValue
);
if
(!
subResult
.
getKey
())
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
builder
.
append
(
subResult
.
getValue
()).
append
(
"\n"
);
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
condition
.
toString
(),
ex
);
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
double
percent
=
(
1
-
valueSum
/
baselineSum
)
*
100
;
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[基线值:"
).
append
(
baselines
.
toString
()).
append
(
"] "
);
sb
.
append
(
"[实际值:"
).
append
(
values
.
toString
()).
append
(
"] "
);
sb
.
append
(
"[下降:"
).
append
(
m_df
.
format
(
percent
)).
append
(
"%"
).
append
(
"]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
new
Pair
<
Boolean
,
String
>(
true
,
sb
.
toString
());
return
new
Pair
<
Boolean
,
String
>(
true
,
builder
.
toString
());
}
private
Pair
<
Boolean
,
String
>
checkDataByConfig
(
double
[]
value
,
double
[]
baseline
,
Config
config
)
{
...
...
@@ -102,26 +92,6 @@ public class DefaultDataChecker implements DataChecker {
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
private
boolean
checkDataByMinute
(
Condition
condition
,
double
value
,
double
baseline
)
{
for
(
SubCondition
subCondition
:
condition
.
getSubConditions
())
{
try
{
String
ruleType
=
subCondition
.
getType
();
double
ruleValue
=
parseSubConditionText
(
subCondition
.
getText
());
RuleType
rule
=
RuleType
.
getByTypeId
(
ruleType
);
boolean
isSubRuleTriggered
=
rule
.
executeRule
(
value
,
baseline
,
ruleValue
);
if
(!
isSubRuleTriggered
)
{
return
false
;
}
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
condition
.
toString
(),
ex
);
return
false
;
}
}
return
true
;
}
private
double
parseSubConditionText
(
String
text
)
{
if
(
text
.
contains
(
"Mb"
))
{
double
value
=
Double
.
parseDouble
(
text
.
replaceAll
(
"Mb"
,
""
));
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/RuleType.java
浏览文件 @
eaf3de7d
package
com.dianping.cat.report.task.alert
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.unidal.tuple.Pair
;
public
enum
RuleType
{
DecreasePercentage
{
private
double
[]
buildDescPers
(
double
[]
values
,
double
[]
baselines
)
{
int
length
=
values
.
length
;
double
[]
descPers
=
new
double
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
descPers
[
i
]
=
(
1
-
values
[
i
]
/
baselines
[
i
])
*
100
;
}
return
descPers
;
}
@Override
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[基线值:"
).
append
(
convertDoublesToString
(
baselines
)).
append
(
"] "
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[下降比:"
).
append
(
convertPercentsToString
(
buildDescPers
(
values
,
baselines
))).
append
(
"]"
);
sb
.
append
(
"[下降百分比阈值: "
+
m_df
.
format
(
ruleValue
)
+
"% ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
if
(
baseline
>
0
)
{
return
value
/
baseline
<=
(
1
-
ruleValue
/
100
);
}
else
{
return
false
;
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
baselines
[
i
]
<=
0
||
values
[
i
]
/
baselines
[
i
]
>
(
1
-
ruleValue
/
100
))
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
public
String
getId
()
{
return
"DescPer"
;
}
},
DecreaseValue
{
private
double
[]
buildDescVals
(
double
[]
values
,
double
[]
baselines
)
{
int
length
=
values
.
length
;
double
[]
descVals
=
new
double
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
descVals
[
i
]
=
baselines
[
i
]
-
values
[
i
];
}
return
descVals
;
}
@Override
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[基线值:"
).
append
(
convertDoublesToString
(
baselines
)).
append
(
"] "
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[下降值:"
).
append
(
convertDoublesToString
(
buildDescVals
(
values
,
baselines
))).
append
(
"]"
);
sb
.
append
(
"[下降阈值: "
+
m_df
.
format
(
ruleValue
)
+
" ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
return
baseline
-
value
>=
ruleValue
;
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
baselines
[
i
]
-
values
[
i
]
<
ruleValue
)
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
...
...
@@ -34,13 +102,42 @@ public enum RuleType {
},
IncreasePercentage
{
private
double
[]
buildAscPers
(
double
[]
values
,
double
[]
baselines
)
{
int
length
=
values
.
length
;
double
[]
ascPers
=
new
double
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
ascPers
[
i
]
=
(
values
[
i
]
/
baselines
[
i
]
-
1
)
*
100
;
}
return
ascPers
;
}
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
if
(
baseline
>
0
)
{
return
value
/
baseline
>=
(
1
+
ruleValue
/
100
);
}
else
{
return
false
;
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[基线值:"
).
append
(
convertDoublesToString
(
baselines
)).
append
(
"] "
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[上升比:"
).
append
(
convertPercentsToString
(
buildAscPers
(
values
,
baselines
))).
append
(
"]"
);
sb
.
append
(
"[上升百分比阈值: "
+
m_df
.
format
(
ruleValue
)
+
"% ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
baselines
[
i
]
<=
0
||
values
[
i
]
/
baselines
[
i
]
<
(
1
+
ruleValue
/
100
))
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
...
...
@@ -50,9 +147,42 @@ public enum RuleType {
},
IncreaseValue
{
private
double
[]
buildAscVals
(
double
[]
values
,
double
[]
baselines
)
{
int
length
=
values
.
length
;
double
[]
ascVals
=
new
double
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
ascVals
[
i
]
=
values
[
i
]
-
baselines
[
i
];
}
return
ascVals
;
}
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
return
value
-
baseline
>=
ruleValue
;
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[基线值:"
).
append
(
convertDoublesToString
(
baselines
)).
append
(
"] "
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[上升值:"
).
append
(
convertDoublesToString
(
buildAscVals
(
values
,
baselines
))).
append
(
"]"
);
sb
.
append
(
"[上升阈值: "
+
m_df
.
format
(
ruleValue
)
+
" ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
values
[
i
]
-
baselines
[
i
]
<
ruleValue
)
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
...
...
@@ -63,8 +193,28 @@ public enum RuleType {
absoluteMaxValue
{
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
return
value
>=
ruleValue
;
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[最大阈值: "
+
m_df
.
format
(
ruleValue
)
+
" ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
values
[
i
]
<
ruleValue
)
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
...
...
@@ -75,8 +225,28 @@ public enum RuleType {
absoluteMinValue
{
@Override
public
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
)
{
return
value
<=
ruleValue
;
protected
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
sb
.
append
(
"[实际值:"
).
append
(
convertDoublesToString
(
values
)).
append
(
"] "
);
sb
.
append
(
"[最小阈值: "
+
m_df
.
format
(
ruleValue
)
+
" ]"
);
sb
.
append
(
"[告警时间:"
).
append
(
sdf
.
format
(
new
Date
())
+
"]"
);
return
sb
.
toString
();
}
@Override
public
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
)
{
int
length
=
values
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
values
[
i
]
>
ruleValue
)
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
return
new
Pair
<
Boolean
,
String
>(
true
,
buildRuleMessage
(
values
,
baselines
,
ruleValue
));
}
@Override
...
...
@@ -93,12 +263,36 @@ public enum RuleType {
}
}
public
static
RuleType
getByTypeId
(
String
typeId
)
{
return
s_map
.
get
(
typeId
);
protected
DecimalFormat
m_df
=
new
DecimalFormat
(
"0.0"
);
protected
abstract
String
buildRuleMessage
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
);
protected
String
convertDoublesToString
(
double
[]
values
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
double
value
:
values
)
{
builder
.
append
(
m_df
.
format
(
value
)).
append
(
" "
);
}
return
builder
.
toString
();
}
protected
String
convertPercentsToString
(
double
[]
values
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
double
value
:
values
)
{
builder
.
append
(
m_df
.
format
(
value
)).
append
(
"% "
);
}
return
builder
.
toString
();
}
public
abstract
boolean
executeRule
(
double
value
,
double
baseline
,
double
ruleValue
);
public
abstract
Pair
<
Boolean
,
String
>
executeRule
(
double
[]
values
,
double
[]
baselines
,
double
ruleValue
);
public
abstract
String
getId
();
public
static
RuleType
getByTypeId
(
String
typeId
)
{
return
s_map
.
get
(
typeId
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录