Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
e93d41ee
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,发现更多精彩内容 >>
提交
e93d41ee
编写于
7月 23, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add postman, alertmanater
上级
019a31fc
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
132 addition
and
132 deletion
+132
-132
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertManager.java
...java/com/dianping/cat/report/task/alert/AlertManager.java
+43
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+7
-116
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
...a/com/dianping/cat/report/task/alert/BaseAlertConfig.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
...g/cat/report/task/alert/business/BusinessAlertConfig.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
...cat/report/task/alert/exception/ExceptionAlertConfig.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
...ing/cat/report/task/alert/network/NetworkAlertConfig.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/Postman.java
...va/com/dianping/cat/report/task/alert/sender/Postman.java
+74
-8
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
...nping/cat/report/task/alert/system/SystemAlertConfig.java
+2
-2
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertManager.java
0 → 100644
浏览文件 @
e93d41ee
package
com.dianping.cat.report.task.alert
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.home.dal.report.Alert
;
import
com.dianping.cat.home.dal.report.AlertDao
;
public
class
AlertManager
{
@Inject
protected
AlertDao
m_alertDao
;
private
Alert
buildAlert
(
String
categoryName
,
String
domainName
,
String
metricName
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
alertResult
.
getAlertTime
());
alert
.
setCategory
(
categoryName
);
alert
.
setType
(
alertResult
.
getAlertType
());
alert
.
setContent
(
mailTitle
+
"<br/>"
+
alertResult
.
getContent
());
alert
.
setMetric
(
metricName
);
return
alert
;
}
protected
void
storeAlert
(
String
categoryName
,
String
domainName
,
String
metricName
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
buildAlert
(
categoryName
,
domainName
,
metricName
,
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
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
e93d41ee
...
...
@@ -9,7 +9,6 @@ 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
;
...
...
@@ -22,27 +21,15 @@ import com.dianping.cat.consumer.metric.ProductLineConfigManager;
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.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.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
;
public
abstract
class
BaseAlert
{
...
...
@@ -52,9 +39,6 @@ public abstract class BaseAlert {
@Inject
protected
MailSMS
m_mailSms
;
@Inject
protected
AlertDao
m_alertDao
;
@Inject
protected
AlertInfo
m_alertInfo
;
...
...
@@ -74,22 +58,10 @@ public abstract class BaseAlert {
protected
RemoteMetricReportService
m_service
;
@Inject
private
ProjectDao
m_projectDao
;
@Inject
protected
MailSender
m_mailSender
;
@Inject
protected
SmsSender
m_smsSender
;
@Inject
protected
WeixinSender
m_weixinSender
;
@Inject
protected
AlertTypeManager
m_alertTypeManager
;
protected
Postman
m_postman
;
@Inject
protected
Postman
m_postman
;
protected
AlertManager
m_alertManager
;
protected
static
final
int
DATA_AREADY_MINUTE
=
1
;
...
...
@@ -103,19 +75,6 @@ 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
buildMetricName
(
String
metricKey
)
{
try
{
return
metricKey
.
split
(
":"
)[
2
];
...
...
@@ -134,28 +93,6 @@ public abstract class BaseAlert {
}
}
protected
String
buildContactInfo
(
String
domainName
)
{
try
{
Project
project
=
m_projectDao
.
findByDomain
(
domainName
,
ProjectEntity
.
READSET_FULL
);
String
owners
=
project
.
getOwner
();
String
phones
=
project
.
getPhone
();
StringBuilder
builder
=
new
StringBuilder
();
if
(!
StringUtils
.
isEmpty
(
owners
))
{
builder
.
append
(
"[业务负责人: "
).
append
(
owners
).
append
(
" ]"
);
}
if
(!
StringUtils
.
isEmpty
(
phones
))
{
builder
.
append
(
"[负责人手机号码: "
).
append
(
phones
).
append
(
" ]"
);
}
return
builder
.
toString
();
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"build contact info error for doamin: "
+
domainName
,
ex
);
}
return
null
;
}
private
Long
buildMillsByString
(
String
time
)
throws
Exception
{
String
[]
times
=
time
.
split
(
":"
);
int
hour
=
Integer
.
parseInt
(
times
[
0
]);
...
...
@@ -302,18 +239,15 @@ public abstract class BaseAlert {
List
<
AlertResultEntity
>
alertResults
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
m_alertInfo
.
addAlertInfo
(
productlineName
,
metricKey
,
new
Date
().
getTime
());
String
metricName
=
buildMetricName
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metricName
);
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
());
m_alertManager
.
storeAlert
(
getName
(),
productlineName
,
metricName
,
mailTitle
,
alertResult
);
storeAlert
(
productlineName
,
metricName
,
mailTitle
,
alertResult
);
String
domain
=
extractDomain
(
metricKey
);
String
configId
=
getAlertConfig
().
getId
();
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
productlineName
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
m_postman
.
sendAlert
(
getAlertConfig
(),
alertResult
,
productLine
,
domain
,
mailTitle
,
configId
);
}
}
}
...
...
@@ -333,35 +267,6 @@ 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
;
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
;
}
}
if
(
type
.
isSendSms
())
{
List
<
String
>
receivers
=
getAlertConfig
().
buildSMSReceivers
(
productLine
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
))
{
sendResult
=
false
;
}
}
return
sendResult
;
}
private
double
[]
queryBaseLine
(
int
start
,
int
end
,
String
baseLineKey
,
Date
date
,
MetricType
type
)
{
double
[]
baseline
=
m_baselineService
.
queryHourlyBaseline
(
MetricAnalyzer
.
ID
,
baseLineKey
+
":"
+
type
,
date
);
int
length
=
end
-
start
+
1
;
...
...
@@ -419,20 +324,6 @@ public abstract class BaseAlert {
return
result
;
}
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
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
浏览文件 @
e93d41ee
...
...
@@ -83,7 +83,7 @@ public abstract class BaseAlertConfig {
}
}
p
rotected
abstract
String
buildMailTitle
(
String
artifactName
,
String
configTitl
e
);
p
ublic
abstract
String
buildMailTitle
(
String
artifactName
,
String
metricNam
e
);
public
abstract
String
getId
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
浏览文件 @
e93d41ee
...
...
@@ -7,11 +7,11 @@ public class BusinessAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"business"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[业务告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[业务指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[业务指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
浏览文件 @
e93d41ee
...
...
@@ -58,7 +58,7 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
}
@Override
public
String
buildMailTitle
(
String
domain
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
domain
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"]"
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
浏览文件 @
e93d41ee
...
...
@@ -7,11 +7,11 @@ public class NetworkAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"network"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[网络告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[网络指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[网络指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/Postman.java
浏览文件 @
e93d41ee
...
...
@@ -2,17 +2,55 @@ package com.dianping.cat.report.task.alert.sender;
import
java.util.List
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
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.home.alert.type.entity.Type
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
import
com.dianping.cat.system.config.AlertTypeManager
;
import
com.site.lookup.util.StringUtils
;
public
class
Postman
{
protected
String
generateMailTitle
()
{
@Inject
private
ProjectDao
m_projectDao
;
return
null
;
}
@Inject
protected
MailSender
m_mailSender
;
@Inject
protected
SmsSender
m_smsSender
;
@Inject
protected
WeixinSender
m_weixinSender
;
@Inject
protected
AlertTypeManager
m_alertTypeManager
;
protected
String
generateMailContent
()
{
protected
String
buildContactInfo
(
String
domainName
)
{
try
{
Project
project
=
m_projectDao
.
findByDomain
(
domainName
,
ProjectEntity
.
READSET_FULL
);
String
owners
=
project
.
getOwner
();
String
phones
=
project
.
getPhone
();
StringBuilder
builder
=
new
StringBuilder
();
if
(!
StringUtils
.
isEmpty
(
owners
))
{
builder
.
append
(
"[业务负责人: "
).
append
(
owners
).
append
(
" ]"
);
}
if
(!
StringUtils
.
isEmpty
(
phones
))
{
builder
.
append
(
"[负责人手机号码: "
).
append
(
phones
).
append
(
" ]"
);
}
return
builder
.
toString
();
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"build contact info error for doamin: "
+
domainName
,
ex
);
}
return
null
;
}
...
...
@@ -22,11 +60,39 @@ public class Postman {
return
null
;
}
public
boolean
storeAndSendAlert
(
BaseAlertConfig
alertConfig
,
ProductLine
productline
,
String
domain
)
{
public
boolean
sendAlert
(
BaseAlertConfig
alertConfig
,
AlertResultEntity
alertResult
,
ProductLine
productline
,
String
domain
,
String
mailTitle
,
String
configId
)
{
String
content
=
alertResult
.
getContent
();
String
contactInfo
=
buildContactInfo
(
domain
);
Type
type
=
m_alertTypeManager
.
getType
(
configId
,
domain
,
alertResult
.
getAlertType
());
boolean
sendResult
=
true
;
if
(
type
.
isSendMail
())
{
String
mailContent
=
content
+
"<br/>"
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildMailReceivers
(
productline
);
if
(!
m_mailSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
mailContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendWeixin
())
{
String
weixinContent
=
content
+
"\n"
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildMailReceivers
(
productline
);
if
(!
m_weixinSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
weixinContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendSms
())
{
String
smsContent
=
content
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildSMSReceivers
(
productline
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
smsContent
))
{
sendResult
=
false
;
}
}
return
false
;
Cat
.
logEvent
(
configId
,
productline
.
getId
(),
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
return
sendResult
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
浏览文件 @
e93d41ee
...
...
@@ -7,11 +7,11 @@ public class SystemAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"system"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[系统告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[系统指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[系统指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录