Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
019a31fc
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,发现更多精彩内容 >>
提交
019a31fc
编写于
7月 23, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stage changes
上级
808acd40
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
16 deletion
+33
-16
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+33
-16
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
019a31fc
...
...
@@ -26,18 +26,20 @@ 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.alert.type.entity.Type
;
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.message.Event
;
import
com.dianping.cat.report.baseline.BaselineService
;
import
com.dianping.cat.report.task.alert.sender.BaseSender
;
import
com.dianping.cat.report.task.alert.sender.MailSender
;
import
com.dianping.cat.report.task.alert.sender.Postman
;
import
com.dianping.cat.report.task.alert.sender.SmsSender
;
import
com.dianping.cat.report.task.alert.sender.WeixinSender
;
import
com.dianping.cat.service.ModelPeriod
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.system.config.AlertTypeManager
;
import
com.dianping.cat.system.config.BaseRuleConfigManager
;
import
com.dianping.cat.system.tool.MailSMS
;
import
com.site.lookup.util.StringUtils
;
...
...
@@ -83,6 +85,12 @@ public abstract class BaseAlert {
@Inject
protected
WeixinSender
m_weixinSender
;
@Inject
protected
AlertTypeManager
m_alertTypeManager
;
@Inject
protected
Postman
m_postman
;
protected
static
final
int
DATA_AREADY_MINUTE
=
1
;
protected
static
final
long
DURATION
=
TimeUtil
.
ONE_MINUTE
;
...
...
@@ -108,11 +116,11 @@ public abstract class BaseAlert {
return
alert
;
}
private
String
buildMetric
Titl
e
(
String
metricKey
)
{
private
String
buildMetric
Nam
e
(
String
metricKey
)
{
try
{
return
metricKey
.
split
(
":"
)[
2
];
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"get metric
titl
e error:"
+
metricKey
,
ex
);
Cat
.
logError
(
"get metric
nam
e error:"
+
metricKey
,
ex
);
return
null
;
}
}
...
...
@@ -157,7 +165,7 @@ public abstract class BaseAlert {
return
result
;
}
protected
AlertResultEntity
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
protected
List
<
AlertResultEntity
>
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
double
[]
value
=
null
;
double
[]
baseline
=
null
;
List
<
Config
>
configs
=
m_ruleConfigManager
.
queryConfigs
(
product
,
metricKey
,
type
);
...
...
@@ -291,18 +299,18 @@ public abstract class BaseAlert {
private
void
processMetricItem
(
int
minute
,
ProductLine
productLine
,
String
metricKey
)
{
for
(
MetricType
type
:
MetricType
.
values
())
{
String
productlineName
=
productLine
.
getId
();
AlertResultEntity
alertResult
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
List
<
AlertResultEntity
>
alertResults
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
if
(
alertResult
!=
null
&&
alertResult
.
isTriggered
()
)
{
String
metric
Title
=
buildMetricTitl
e
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metric
Titl
e
);
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
String
metric
Name
=
buildMetricNam
e
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metric
Nam
e
);
String
domain
=
extractDomain
(
metricKey
);
String
contactInfo
=
buildContactInfo
(
domain
);
alertResult
.
setContent
(
alertResult
.
getContent
()
+
contactInfo
);
String
content
=
alertResult
.
getContent
();
m_alertInfo
.
addAlertInfo
(
productlineName
,
metricKey
,
new
Date
().
getTime
());
storeAlert
(
productlineName
,
metric
Titl
e
,
mailTitle
,
alertResult
);
storeAlert
(
productlineName
,
metric
Nam
e
,
mailTitle
,
alertResult
);
String
configId
=
getAlertConfig
().
getId
();
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
productlineName
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
...
...
@@ -327,19 +335,28 @@ public abstract class BaseAlert {
protected
boolean
sendAllAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
Type
type
=
m_alertTypeManager
.
getType
(
configId
,
domain
,
alertType
);
boolean
sendResult
=
true
;
BaseSender
[]
senders
=
{
m_mailSender
,
m_weixinSender
};
List
<
String
>
receivers
=
getAlertConfig
().
buildMailReceivers
(
productLine
);
for
(
BaseSender
sender
:
senders
)
{
if
(!
sender
.
sendAlert
(
receivers
,
domain
,
title
,
content
,
alertType
))
{
if
(
type
.
isSendMail
())
{
List
<
String
>
receivers
=
getAlertConfig
().
buildMailReceivers
(
productLine
);
if
(!
m_mailSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendWeixin
())
{
List
<
String
>
receivers
=
getAlertConfig
().
buildMailReceivers
(
productLine
);
if
(!
m_weixinSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
))
{
sendResult
=
false
;
}
}
receivers
=
getAlertConfig
().
buildSMSReceivers
(
productLine
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
,
alertType
))
{
sendResult
=
false
;
if
(
type
.
isSendSms
())
{
List
<
String
>
receivers
=
getAlertConfig
().
buildSMSReceivers
(
productLine
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
))
{
sendResult
=
false
;
}
}
return
sendResult
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录