Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
fd130d69
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,发现更多精彩内容 >>
提交
fd130d69
编写于
7月 04, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mail title when storing alert infos
上级
816b7ece
变更
16
显示空白变更内容
内联
并排
Showing
16 changed file
with
165 addition
and
46 deletion
+165
-46
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
...n/java/com/dianping/cat/build/ComponentsConfigurator.java
+4
-3
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
...com/dianping/cat/report/task/alert/AlertResultEntity.java
+10
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+45
-6
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/business/BusinessAlert.java
...ianping/cat/report/task/alert/business/BusinessAlert.java
+19
-11
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
+10
-4
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/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/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+28
-0
script/Cat.sql
script/Cat.sql
+11
-0
未找到文件。
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
浏览文件 @
fd130d69
...
...
@@ -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
;
...
...
@@ -184,15 +185,15 @@ 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
,
AlertInfo
.
class
)
//
BaselineService
.
class
,
MailSMS
.
class
,
SystemAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
SystemRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
AlertExceptionBuilder
.
class
).
req
(
ExceptionConfigManager
.
class
));
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
浏览文件 @
fd130d69
package
com.dianping.cat.report.task.alert
;
import
java.util.Date
;
public
class
AlertResultEntity
{
private
boolean
m_isTriggered
;
...
...
@@ -7,16 +9,24 @@ public class AlertResultEntity {
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
()
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
fd130d69
...
...
@@ -9,6 +9,7 @@ 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,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
;
...
...
@@ -38,6 +41,9 @@ public abstract class BaseAlert {
@Inject
protected
MailSMS
m_mailSms
;
@Inject
protected
AlertDao
m_alertDao
;
@Inject
protected
AlertInfo
m_alertInfo
;
...
...
@@ -68,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
];
...
...
@@ -86,8 +105,7 @@ public abstract class BaseAlert {
return
result
;
}
protected
AlertResultEntity
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_ruleConfigManager
.
queryConfigs
(
metricKey
,
type
);
...
...
@@ -220,13 +238,16 @@ public abstract class BaseAlert {
private
void
processMetricItem
(
int
minute
,
ProductLine
productLine
,
String
metricKey
)
{
for
(
MetricType
type
:
MetricType
.
values
())
{
AlertResultEntity
alert
=
computeAlertInfo
(
minute
,
productLine
.
getId
(),
metricKey
,
type
);
String
productlineName
=
productLine
.
getId
();
AlertResultEntity
alertResult
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
if
(
alert
!=
null
&&
aler
t
.
isTriggered
())
{
if
(
alert
Result
!=
null
&&
alertResul
t
.
isTriggered
())
{
String
metricTitle
=
buildMetricTitle
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metricTitle
);
m_alertInfo
.
addAlertInfo
(
metricKey
,
new
Date
().
getTime
());
sendAlertInfo
(
productLine
,
metricTitle
,
alert
.
getContent
(),
alert
.
getAlertType
());
storeAlert
(
productlineName
,
metricTitle
,
mailTitle
,
alertResult
);
sendAlertInfo
(
productLine
,
mailTitle
,
alertResult
.
getContent
(),
alertResult
.
getAlertType
());
}
}
}
...
...
@@ -303,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
浏览文件 @
fd130d69
...
...
@@ -69,6 +69,8 @@ public abstract class BaseAlertConfig {
}
}
protected
abstract
String
buildMailTitle
(
String
artifactName
,
String
configTitle
);
public
abstract
String
getId
();
protected
List
<
String
>
split
(
String
str
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
浏览文件 @
fd130d69
...
...
@@ -17,12 +17,13 @@ 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
;
...
...
@@ -36,6 +37,11 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
return
"metric-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
public
boolean
needAlert
(
MetricItemConfig
config
)
{
if
((
config
.
getAlarm
()
||
config
.
isShowAvgDashboard
()
||
config
.
isShowSumDashboard
()
||
config
.
isShowCountDashboard
()))
{
...
...
@@ -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
);
AlertResultEntity
alert
=
null
;
AlertResultEntity
alert
Result
=
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
.
isTriggered
())
{
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
.
getContent
(),
alert
.
getAlertType
());
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
浏览文件 @
fd130d69
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
浏览文件 @
fd130d69
...
...
@@ -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
浏览文件 @
fd130d69
...
...
@@ -132,7 +132,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 +155,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
);
storeAlert
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
List
<
AlertException
>
errorExceptions
=
m_alertBuilder
.
buildErrorException
(
exceptions
);
if
(!
errorExceptions
.
isEmpty
())
{
...
...
@@ -177,6 +179,10 @@ public class ExceptionAlert implements Task, LogEnabled {
}
}
private
void
storeAlert
(
String
domain
,
List
<
AlertException
>
exceptions
,
String
mailContent
)
{
}
@Override
public
void
shutdown
()
{
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
浏览文件 @
fd130d69
...
...
@@ -25,6 +25,14 @@ 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
());
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlert.java
浏览文件 @
fd130d69
...
...
@@ -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
{
...
...
@@ -30,6 +31,11 @@ public class NetworkAlert extends BaseAlert implements Task, LogEnabled {
return
"network-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
@Override
public
void
run
()
{
boolean
active
=
true
;
...
...
@@ -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
浏览文件 @
fd130d69
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
浏览文件 @
fd130d69
...
...
@@ -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
{
...
...
@@ -30,6 +31,11 @@ public class SystemAlert extends BaseAlert implements Task, LogEnabled {
return
"system-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
}
@Override
public
void
run
()
{
boolean
active
=
true
;
...
...
@@ -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
浏览文件 @
fd130d69
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/resources/META-INF/dal/jdbc/report-dal.xml
浏览文件 @
fd130d69
<?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/plexus/components.xml
浏览文件 @
fd130d69
...
...
@@ -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>
...
...
@@ -1941,6 +1950,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 +2040,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>
...
...
script/Cat.sql
浏览文件 @
fd130d69
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录