Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
409a5815
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,发现更多精彩内容 >>
提交
409a5815
编写于
7月 10, 2013
作者:
Y
yong.you
浏览文件
操作
浏览文件
下载
差异文件
merge from upstream
上级
d019a129
bca59c0f
变更
26
展开全部
隐藏空白更改
内联
并排
Showing
26 changed file
with
1070 addition
and
146 deletion
+1070
-146
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/advanced/MetricAnalyzer.java
...va/com/dianping/cat/consumer/advanced/MetricAnalyzer.java
+9
-2
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/build/ComponentsConfigurator.java
...m/dianping/cat/consumer/build/ComponentsConfigurator.java
+1
-1
cat-consumer-advanced/src/main/resources/META-INF/plexus/components.xml
...dvanced/src/main/resources/META-INF/plexus/components.xml
+3
-0
cat-core/src/main/java/com/dianping/cat/task/TaskManager.java
...core/src/main/java/com/dianping/cat/task/TaskManager.java
+38
-15
cat-home/src/main/java/com/dianping/cat/CatHomeModule.java
cat-home/src/main/java/com/dianping/cat/CatHomeModule.java
+3
-1
cat-home/src/main/java/com/dianping/cat/build/TaskComponentConfigurator.java
...ava/com/dianping/cat/build/TaskComponentConfigurator.java
+5
-3
cat-home/src/main/java/com/dianping/cat/report/baseline/BaselineConfig.java
...java/com/dianping/cat/report/baseline/BaselineConfig.java
+6
-6
cat-home/src/main/java/com/dianping/cat/report/baseline/BaselineConfigManager.java
...m/dianping/cat/report/baseline/BaselineConfigManager.java
+4
-4
cat-home/src/main/java/com/dianping/cat/report/baseline/impl/DefaultBaselineCreator.java
...ping/cat/report/baseline/impl/DefaultBaselineCreator.java
+5
-2
cat-home/src/main/java/com/dianping/cat/report/page/metric/Handler.java
...ain/java/com/dianping/cat/report/page/metric/Handler.java
+1
-0
cat-home/src/main/java/com/dianping/cat/report/page/problem/LongConfig.java
...java/com/dianping/cat/report/page/problem/LongConfig.java
+5
-5
cat-home/src/main/java/com/dianping/cat/report/page/problem/ProblemStatistics.java
...m/dianping/cat/report/page/problem/ProblemStatistics.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricAlert.java
...java/com/dianping/cat/report/task/metric/MetricAlert.java
+95
-45
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricBaselineReportBuilder.java
...g/cat/report/task/metric/MetricBaselineReportBuilder.java
+9
-4
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricPointParser.java
...om/dianping/cat/report/task/metric/MetricPointParser.java
+2
-2
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
-3
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+4
-3
cat-home/src/main/webapp/css/body.css
cat-home/src/main/webapp/css/body.css
+5
-0
cat-home/src/main/webapp/jsp/report/metric.jsp
cat-home/src/main/webapp/jsp/report/metric.jsp
+1
-1
cat-home/src/main/webapp/jsp/report/problem/problemQuery.jsp
cat-home/src/main/webapp/jsp/report/problem/problemQuery.jsp
+14
-15
cat-home/src/test/java/com/dianping/cat/AllTests.java
cat-home/src/test/java/com/dianping/cat/AllTests.java
+6
-0
cat-home/src/test/java/com/dianping/cat/report/analyzer/OpDataCollectTest.java
...a/com/dianping/cat/report/analyzer/OpDataCollectTest.java
+2
-2
cat-home/src/test/java/com/dianping/cat/report/baseline/BaselineCreatorTest.java
...com/dianping/cat/report/baseline/BaselineCreatorTest.java
+33
-10
cat-home/src/test/java/com/dianping/cat/report/task/metric/MetricAlertTest.java
.../com/dianping/cat/report/task/metric/MetricAlertTest.java
+64
-0
cat-home/src/test/java/com/dianping/cat/report/task/metric/MetricBaselineReportBuilderTest.java
...t/report/task/metric/MetricBaselineReportBuilderTest.java
+44
-21
cat-home/src/test/resources/com/dianping/cat/report/task/metric/metricReport.xml
...rces/com/dianping/cat/report/task/metric/metricReport.xml
+707
-0
未找到文件。
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/advanced/MetricAnalyzer.java
浏览文件 @
409a5815
...
...
@@ -31,8 +31,11 @@ import com.dianping.cat.message.Message;
import
com.dianping.cat.message.Metric
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.service.ReportConstants
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.BucketManager
;
import
com.dianping.cat.task.TaskManager
;
import
com.dianping.cat.task.TaskManager.TaskProlicy
;
public
class
MetricAnalyzer
extends
AbstractMessageAnalyzer
<
MetricReport
>
implements
LogEnabled
{
public
static
final
String
ID
=
"metric"
;
...
...
@@ -52,9 +55,12 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
@Inject
private
ABTestCodec
m_codec
;
@Inject
private
TaskManager
m_taskManager
;
// key is project line,such as tuangou
private
Map
<
String
,
MetricReport
>
m_reports
=
new
HashMap
<
String
,
MetricReport
>();
@Override
public
void
doCheckpoint
(
boolean
atEnd
)
{
storeReports
(
atEnd
);
...
...
@@ -65,7 +71,6 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
m_logger
=
logger
;
}
public
MetricReport
getReport
(
String
product
)
{
MetricReport
report
=
m_reports
.
get
(
product
);
...
...
@@ -300,6 +305,8 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
Cat
.
getProducer
().
logError
(
e
);
}
}
//for create baseline for metric
m_taskManager
.
createTask
(
period
,
ReportConstants
.
CAT
,
ID
,
TaskProlicy
.
DAILY
);
}
}
catch
(
Exception
e
)
{
Cat
.
getProducer
().
logError
(
e
);
...
...
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/build/ComponentsConfigurator.java
浏览文件 @
409a5815
...
...
@@ -58,7 +58,7 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
MessageAnalyzer
.
class
,
MetricAnalyzer
.
ID
,
MetricAnalyzer
.
class
).
is
(
PER_LOOKUP
)
//
.
req
(
BucketManager
.
class
,
BusinessReportDao
.
class
,
MetricConfigManager
.
class
)
//
.
req
(
ProductLineConfigManager
.
class
,
ABTestCodec
.
class
));
.
req
(
ProductLineConfigManager
.
class
,
ABTestCodec
.
class
,
TaskManager
.
class
));
all
.
add
(
C
(
Module
.
class
,
CatConsumerAdvancedModule
.
ID
,
CatConsumerAdvancedModule
.
class
));
...
...
cat-consumer-advanced/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
409a5815
...
...
@@ -135,6 +135,9 @@
<requirement>
<role>
com.dianping.cat.abtest.spi.internal.ABTestCodec
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.task.TaskManager
</role>
</requirement>
</requirements>
</component>
<component>
...
...
cat-core/src/main/java/com/dianping/cat/task/TaskManager.java
浏览文件 @
409a5815
...
...
@@ -128,29 +128,29 @@ public class TaskManager {
}
},
HOULY
{
HOULY
{
@Override
public
boolean
shouldCreateHourlyTask
()
{
return
true
;
}
public
boolean
shouldCreateHourlyTask
()
{
return
true
;
}
@Override
public
boolean
shouldCreateDailyTask
()
{
return
false
;
}
public
boolean
shouldCreateDailyTask
()
{
return
false
;
}
@Override
public
boolean
shouldCreateWeeklyTask
()
{
return
false
;
}
public
boolean
shouldCreateWeeklyTask
()
{
return
false
;
}
@Override
public
boolean
shouldCreateMonthTask
()
{
return
false
;
}
public
boolean
shouldCreateMonthTask
()
{
return
false
;
}
},
ALL_EXCLUED_HOURLY
{
...
...
@@ -174,6 +174,29 @@ public class TaskManager {
public
boolean
shouldCreateMonthTask
()
{
return
true
;
}
},
DAILY
{
@Override
public
boolean
shouldCreateHourlyTask
()
{
return
false
;
}
@Override
public
boolean
shouldCreateDailyTask
()
{
return
true
;
}
@Override
public
boolean
shouldCreateWeeklyTask
()
{
return
false
;
}
@Override
public
boolean
shouldCreateMonthTask
()
{
return
false
;
}
};
}
...
...
cat-home/src/main/java/com/dianping/cat/CatHomeModule.java
浏览文件 @
409a5815
...
...
@@ -13,6 +13,7 @@ import com.dianping.cat.consumer.core.aggregation.AggregationConfigManager;
import
com.dianping.cat.message.spi.core.MessageConsumer
;
import
com.dianping.cat.message.spi.core.TcpSocketReceiver
;
import
com.dianping.cat.report.task.DefaultTaskConsumer
;
import
com.dianping.cat.report.task.metric.MetricAlert
;
import
com.dianping.cat.report.view.DomainNavManager
;
import
com.dianping.cat.system.alarm.AlarmRuleCreator
;
import
com.dianping.cat.system.alarm.AlarmTask
;
...
...
@@ -37,7 +38,8 @@ public class CatHomeModule extends AbstractModule {
// MetricAlert metricAlert = ctx.lookup(MetricAlert.class);
// Threads.forGroup("Cat").start(metricAlert);
DefaultTaskConsumer
taskConsumer
=
ctx
.
lookup
(
DefaultTaskConsumer
.
class
);
MetricAlert
metricAlert
=
ctx
.
lookup
(
MetricAlert
.
class
);
Threads
.
forGroup
(
"Cat"
).
start
(
metricAlert
);
Threads
.
forGroup
(
"Cat"
).
start
(
taskConsumer
);
}
...
...
cat-home/src/main/java/com/dianping/cat/build/TaskComponentConfigurator.java
浏览文件 @
409a5815
...
...
@@ -20,6 +20,7 @@ import com.dianping.cat.report.baseline.BaselineService;
import
com.dianping.cat.report.baseline.impl.DefaultBaselineCreator
;
import
com.dianping.cat.report.baseline.impl.DefaultBaselineService
;
import
com.dianping.cat.report.page.dependency.graph.TopologyGraphBuilder
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.report.service.ReportService
;
import
com.dianping.cat.report.task.DefaultTaskConsumer
;
import
com.dianping.cat.report.task.cross.CrossReportBuilder
;
...
...
@@ -68,14 +69,15 @@ public class TaskComponentConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
BaselineConfigManager
.
class
,
BaselineConfigManager
.
class
));
all
.
add
(
C
(
MetricBaselineReportBuilder
.
class
)
.
req
(
com
.
dianping
.
cat
.
report
.
service
.
ReportService
.
class
)
//
.
req
(
ReportService
.
class
)
//
.
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
)
//
.
req
(
BaselineCreator
.
class
,
BaselineService
.
class
,
BaselineConfigManager
.
class
));
all
.
add
(
C
(
MetricAlert
.
class
)
.
req
(
com
.
dianping
.
cat
.
report
.
service
.
ReportService
.
class
,
ServerConfigManager
.
class
)
//
.
req
(
ReportService
.
class
,
ServerConfigManager
.
class
)
//
.
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
)
//
.
req
(
BaselineCreator
.
class
,
BaselineService
.
class
,
BaselineConfigManager
.
class
));
.
req
(
BaselineService
.
class
,
BaselineConfigManager
.
class
)
.
req
(
ModelService
.
class
,
"metric"
));
all
.
add
(
C
(
TransactionReportBuilder
.
class
)
//
.
req
(
GraphDao
.
class
,
DailyGraphDao
.
class
,
ReportService
.
class
)
//
...
...
cat-home/src/main/java/com/dianping/cat/report/baseline/BaselineConfig.java
浏览文件 @
409a5815
...
...
@@ -14,9 +14,9 @@ public class BaselineConfig {
private
List
<
Integer
>
m_days
;
private
int
m_upperLimit
;
private
double
m_upperLimit
;
private
int
m_lowerLimit
;
private
double
m_lowerLimit
;
private
double
m_minValue
;
...
...
@@ -40,11 +40,11 @@ public class BaselineConfig {
return
m_days
;
}
public
int
getUpperLimit
()
{
public
double
getUpperLimit
()
{
return
m_upperLimit
;
}
public
int
getLowerLimit
()
{
public
double
getLowerLimit
()
{
return
m_lowerLimit
;
}
...
...
@@ -72,11 +72,11 @@ public class BaselineConfig {
m_days
=
days
;
}
public
void
setUpperLimit
(
int
upperLimit
)
{
public
void
setUpperLimit
(
double
upperLimit
)
{
m_upperLimit
=
upperLimit
;
}
public
void
setLowerLimit
(
int
lowerLimit
)
{
public
void
setLowerLimit
(
double
lowerLimit
)
{
m_lowerLimit
=
lowerLimit
;
}
...
...
cat-home/src/main/java/com/dianping/cat/report/baseline/BaselineConfigManager.java
浏览文件 @
409a5815
...
...
@@ -6,15 +6,15 @@ public class BaselineConfigManager {
public
BaselineConfig
queryBaseLineConfig
(
String
key
)
{
BaselineConfig
config
=
new
BaselineConfig
();
Integer
[]
days
=
{
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
};
Integer
[]
days
=
{
-
6
,
-
13
,
-
1
,
-
2
,
-
3
};
Double
[]
weights
=
{
1.0
,
1.0
,
1.0
,
1.0
,
1.0
};
config
.
setDays
(
Arrays
.
asList
(
days
));
config
.
setId
(
1
);
config
.
setKey
(
key
);
config
.
setLowerLimit
(
100
);
config
.
setMinValue
(
0.2
);
config
.
setTargetDate
(
7
);
config
.
setLowerLimit
(
0.2
);
config
.
setMinValue
(
100
);
config
.
setTargetDate
(
1
);
config
.
setUpperLimit
(
5
);
config
.
setWeights
(
Arrays
.
asList
(
weights
));
return
config
;
...
...
cat-home/src/main/java/com/dianping/cat/report/baseline/impl/DefaultBaselineCreator.java
浏览文件 @
409a5815
...
...
@@ -74,13 +74,16 @@ public class DefaultBaselineCreator implements BaselineCreator {
Collections
.
sort
(
oneMinuteDataList
);
double
middleValue
=
0
;
if
(
oneMinuteDataList
.
size
()
%
2
==
1
)
{
int
size
=
oneMinuteDataList
.
size
();
if
(
size
==
0
)
{
middleValue
=
-
1
;
}
else
if
(
size
%
2
==
1
)
{
middleValue
=
oneMinuteDataList
.
get
((
oneMinuteDataList
.
size
()
-
1
)
/
2
);
}
else
{
middleValue
=
oneMinuteDataList
.
get
(
oneMinuteDataList
.
size
()
/
2
)
/
2
+
oneMinuteDataList
.
get
(
oneMinuteDataList
.
size
()
/
2
-
1
)
/
2
;
}
if
(
data
>
MIN_NOISY_DATA
if
(
middleValue
>
MIN_NOISY_DATA
&&
(
data
/
middleValue
>
NORMAL_DATA_UPPER_LIMIT
||
data
/
middleValue
<
NORMAL_DATA_LOWER_LIMIT
))
{
return
false
;
}
...
...
cat-home/src/main/java/com/dianping/cat/report/page/metric/Handler.java
浏览文件 @
409a5815
...
...
@@ -51,6 +51,7 @@ public class Handler implements PageHandler<Context> {
if
(
m_service
.
isEligable
(
request
))
{
ModelResponse
<
MetricReport
>
response
=
m_service
.
invoke
(
request
);
MetricReport
report
=
response
.
getModel
();
System
.
out
.
println
(
report
);
return
report
;
}
else
{
throw
new
RuntimeException
(
"Internal error: no eligable metric service registered for "
+
request
+
"!"
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/problem/LongConfig.java
浏览文件 @
409a5815
package
com.dianping.cat.report.page.problem
;
public
class
LongConfig
{
private
int
m_sqlThreshold
;
private
int
m_sqlThreshold
=
50
;
private
int
m_urlThreshold
;
private
int
m_urlThreshold
=
1000
;
private
int
m_serviceThreshold
;
private
int
m_serviceThreshold
=
50
;
private
int
m_cacheThreshold
;
private
int
m_cacheThreshold
=
10
;
private
int
m_callThreshold
;
private
int
m_callThreshold
=
50
;
public
int
getCacheThreshold
()
{
return
m_cacheThreshold
;
...
...
cat-home/src/main/java/com/dianping/cat/report/page/problem/ProblemStatistics.java
浏览文件 @
409a5815
...
...
@@ -27,7 +27,7 @@ public class ProblemStatistics extends BaseVisitor {
private
List
<
String
>
m_ips
;
private
LongConfig
m_longConfig
;
private
LongConfig
m_longConfig
=
new
LongConfig
()
;
private
List
<
Duration
>
getDurationsByType
(
String
type
,
Entry
entry
)
{
List
<
Duration
>
durations
=
new
ArrayList
<
Duration
>();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricAlert.java
浏览文件 @
409a5815
...
...
@@ -3,6 +3,7 @@ package com.dianping.cat.report.task.metric;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -23,8 +24,12 @@ import com.dianping.cat.message.Transaction;
import
com.dianping.cat.report.baseline.BaselineConfig
;
import
com.dianping.cat.report.baseline.BaselineConfigManager
;
import
com.dianping.cat.report.baseline.BaselineService
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.report.service.ReportService
;
import
com.dianping.cat.report.task.TaskHelper
;
import
com.dianping.cat.service.ModelPeriod
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.service.ModelResponse
;
public
class
MetricAlert
implements
Task
,
LogEnabled
{
...
...
@@ -32,10 +37,10 @@ public class MetricAlert implements Task, LogEnabled {
protected
MetricConfigManager
m_metricConfigManager
;
@Inject
protected
BaselineService
m_baselineService
;
protected
ProductLineConfigManager
m_productLineConfigManager
;
@Inject
protected
ProductLineConfigManager
m_productLineConfigManager
;
protected
BaselineService
m_baselineService
;
@Inject
protected
BaselineConfigManager
m_baselineConfigManager
;
...
...
@@ -46,26 +51,19 @@ public class MetricAlert implements Task, LogEnabled {
@Inject
protected
ReportService
m_reportService
;
@Inject
(
type
=
ModelService
.
class
,
value
=
"metric"
)
protected
ModelService
<
MetricReport
>
m_service
;
private
Logger
m_logger
;
private
static
final
int
DURATION_IN_MINUTE
=
1
0
;
private
static
final
int
DURATION_IN_MINUTE
=
1
;
private
static
final
long
DURATION
=
TimeUtil
.
ONE_MINUTE
;
private
static
final
long
DURATION
=
DURATION_IN_MINUTE
*
TimeUtil
.
ONE_MINUTE
;
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
String
getName
()
{
return
"MetricAlertRedo"
;
}
private
List
<
Integer
>
metricAlarm
(
double
[]
baseline
,
double
[]
datas
,
int
minute
,
BaselineConfig
config
)
{
private
List
<
Integer
>
checkData
(
double
[]
baseline
,
double
[]
datas
,
int
minute
,
BaselineConfig
config
)
{
List
<
Integer
>
result
=
new
ArrayList
<
Integer
>();
int
start
=
minute
/
DURATION_IN_MINUTE
;
int
end
=
minute
/
DURATION_IN_MINUTE
+
10
;
int
end
=
minute
/
DURATION_IN_MINUTE
+
DURATION_IN_MINUTE
;
double
minValue
=
config
.
getMinValue
();
double
lowerLimit
=
config
.
getLowerLimit
();
double
upperLimit
=
config
.
getUpperLimit
();
...
...
@@ -87,44 +85,96 @@ public class MetricAlert implements Task, LogEnabled {
}
@Override
public
void
run
()
{
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
boolean
active
=
true
;
private
double
[]
extractDatasFromReport
(
MetricReport
report
,
MetricItemConfig
metricConfig
,
MetricType
type
)
{
try
{
MetricItem
reportItem
=
report
.
getMetricItems
().
get
(
metricConfig
.
getMetricKey
());
double
[]
datas
=
MetricPointParser
.
getOneHourData
(
reportItem
,
type
);
return
datas
;
}
catch
(
NullPointerException
e
)
{
return
null
;
}
}
@Override
public
String
getName
()
{
return
"MetricAlertRedo"
;
}
protected
void
metricAlert
(
Date
reportPeriod
)
{
Map
<
String
,
MetricItemConfig
>
metricConfigMap
=
m_metricConfigManager
.
getMetricConfig
().
getMetricItemConfigs
();
Map
<
String
,
double
[]>
baselineMap
=
new
HashMap
<
String
,
double
[]>();
Date
hourStart
=
TaskHelper
.
thisHour
(
reportPeriod
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
reportPeriod
);
int
minute
=
calendar
.
get
(
Calendar
.
MINUTE
);
for
(
String
metricID
:
metricConfigMap
.
keySet
())
{
MetricItemConfig
metricConfig
=
metricConfigMap
.
get
(
metricID
);
String
domain
=
metricConfig
.
getDomain
();
String
productLine
=
m_productLineConfigManager
.
queryProductLineByDomain
(
domain
);
for
(
MetricType
type
:
MetricType
.
values
())
{
String
key
=
metricID
+
":"
+
type
;
BaselineConfig
baselineConfig
=
m_baselineConfigManager
.
queryBaseLineConfig
(
key
);
String
baselineKey
=
key
+
"+"
+
reportPeriod
.
getTime
();
double
[]
baseline
=
queryBaseline
(
baselineMap
,
baselineKey
,
key
,
reportPeriod
);
if
(
baseline
==
null
)
{
continue
;
}
MetricReport
report
=
queryMetricReport
(
productLine
,
hourStart
.
getTime
());
double
[]
datas
=
extractDatasFromReport
(
report
,
metricConfig
,
type
);
if
(
datas
==
null
)
{
continue
;
}
List
<
Integer
>
alertList
=
checkData
(
baseline
,
datas
,
minute
,
baselineConfig
);
for
(
int
alertItem
:
alertList
)
{
m_logger
.
info
(
"ALERT:"
+
key
+
","
+
reportPeriod
+
", minute:"
+
alertItem
);
}
}
}
}
private
double
[]
queryBaseline
(
Map
<
String
,
double
[]>
baselineMap
,
String
baselineKey
,
String
key
,
Date
reportPeriod
)
{
double
[]
result
=
baselineMap
.
get
(
baselineKey
);
if
(
result
==
null
)
{
try
{
result
=
m_baselineService
.
queryHourlyBaseline
(
"metric"
,
key
,
reportPeriod
);
baselineMap
.
put
(
baselineKey
,
result
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
return
result
;
}
private
MetricReport
queryMetricReport
(
String
product
,
long
dateTime
)
{
ModelRequest
request
=
new
ModelRequest
(
product
,
ModelPeriod
.
CURRENT
.
getStartTime
());
if
(
m_service
.
isEligable
(
request
))
{
ModelResponse
<
MetricReport
>
response
=
m_service
.
invoke
(
request
);
MetricReport
report
=
response
.
getModel
();
return
report
;
}
else
{
throw
new
RuntimeException
(
"Internal error: no eligable metric service registered for "
+
request
+
"!"
);
}
}
@Override
public
void
run
()
{
boolean
active
=
true
;
while
(
active
)
{
Transaction
t
=
Cat
.
newTransaction
(
"MetricAlert"
,
"Redo"
);
long
current
=
System
.
currentTimeMillis
();
try
{
Map
<
String
,
MetricItemConfig
>
configMap
=
m_metricConfigManager
.
getMetricConfig
().
getMetricItemConfigs
();
for
(
String
metricID
:
configMap
.
keySet
())
{
MetricItemConfig
metricConfig
=
configMap
.
get
(
metricID
);
String
domain
=
metricConfig
.
getDomain
();
for
(
MetricType
type
:
MetricType
.
values
())
{
String
key
=
metricID
+
":"
+
type
;
Date
reportPeriod
=
new
Date
(
new
Date
().
getTime
()
-
DURATION
);
double
[]
baseline
=
m_baselineService
.
queryHourlyBaseline
(
"metricBaseline"
,
key
,
reportPeriod
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
reportPeriod
);
int
minute
=
calendar
.
get
(
Calendar
.
MINUTE
);
Date
start
=
TaskHelper
.
thisHour
(
reportPeriod
);
Date
end
=
new
Date
(
start
.
getTime
()
+
TimeUtil
.
ONE_HOUR
);
MetricReport
report
=
m_reportService
.
queryMetricReport
(
domain
,
start
,
end
);
BaselineConfig
baselineConfig
=
m_baselineConfigManager
.
queryBaseLineConfig
(
key
);
MetricItem
reportItem
=
report
.
getMetricItems
().
get
(
metricConfig
.
getMetricKey
());
double
[]
datas
=
MetricPointParser
.
getOneHourData
(
reportItem
,
type
);
List
<
Integer
>
alertList
=
metricAlarm
(
baseline
,
datas
,
minute
,
baselineConfig
);
String
alert
=
""
;
for
(
int
alertItem
:
alertList
)
{
alert
=
alert
+
alertItem
+
","
;
}
m_logger
.
info
(
"ALERT:"
+
alert
);
}
}
Date
reportPeriod
=
new
Date
(
new
Date
().
getTime
()
-
DURATION
);
metricAlert
(
reportPeriod
);
t
.
setStatus
(
Transaction
.
SUCCESS
);
}
catch
(
Exception
e
)
{
t
.
setStatus
(
e
);
Cat
.
logError
(
e
);
}
finally
{
t
.
complete
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricBaselineReportBuilder.java
浏览文件 @
409a5815
...
...
@@ -24,7 +24,7 @@ import com.dianping.cat.report.task.spi.ReportTaskBuilder;
public
class
MetricBaselineReportBuilder
implements
ReportTaskBuilder
{
@Inject
protected
ReportService
m_reportService
;
@Inject
protected
MetricConfigManager
m_configManager
;
...
...
@@ -43,7 +43,14 @@ public class MetricBaselineReportBuilder implements ReportTaskBuilder {
private
static
final
int
POINT_NUMBER
=
60
*
24
;
@Override
public
boolean
buildDailyTask
(
String
reportName
,
String
metricID
,
Date
reportPeriod
)
{
public
boolean
buildDailyTask
(
String
reportName
,
String
domain
,
Date
reportPeriod
)
{
for
(
String
metricID
:
m_configManager
.
getMetricConfig
().
getMetricItemConfigs
().
keySet
())
{
buildDailyReportInternal
(
reportName
,
metricID
,
reportPeriod
);
}
return
true
;
}
protected
void
buildDailyReportInternal
(
String
reportName
,
String
metricID
,
Date
reportPeriod
)
{
MetricItemConfig
metricConfig
=
m_configManager
.
getMetricConfig
().
getMetricItemConfigs
().
get
(
metricID
);
String
metricKey
=
metricConfig
.
getMetricKey
();
String
metricDomain
=
metricConfig
.
getDomain
();
...
...
@@ -77,8 +84,6 @@ public class MetricBaselineReportBuilder implements ReportTaskBuilder {
baseline
.
setReportPeriod
(
targetDate
);
m_baselineService
.
insertBaseline
(
baseline
);
}
return
true
;
}
@Override
...
...
cat-home/src/main/java/com/dianping/cat/report/task/metric/MetricPointParser.java
浏览文件 @
409a5815
...
...
@@ -11,8 +11,8 @@ public class MetricPointParser {
private
static
final
int
POINT_NUMBER
=
60
;
public
static
double
[]
getOneDayData
(
List
<
MetricItem
>
reports
,
MetricType
type
)
{
double
[]
values
=
new
double
[
POINT_NUMBER
];
for
(
int
i
=
0
;
i
<
POINT_NUMBER
;
i
++)
{
double
[]
values
=
new
double
[
24
*
POINT_NUMBER
];
for
(
int
i
=
0
;
i
<
24
*
POINT_NUMBER
;
i
++)
{
values
[
i
]
=
-
1
;
}
int
hour
=
0
;
...
...
cat-home/src/main/resources/META-INF/dal/jdbc/report-dal.xml
浏览文件 @
409a5815
...
...
@@ -41,9 +41,9 @@
<statement>
<![CDATA[
SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'report
_
period'
/>
= ${report-period}
AND
<FIELD
name=
'report
_
name'
/>
= ${report-name}
AND
<FIELD
name=
'index
_
key'
/>
= ${index-key}
WHERE
<FIELD
name=
'report
-
period'
/>
= ${report-period}
AND
<FIELD
name=
'report
-
name'
/>
= ${report-name}
AND
<FIELD
name=
'index
-
key'
/>
= ${index-key}
]]>
</statement>
</query>
</query-defs>
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
409a5815
...
...
@@ -326,15 +326,16 @@
<requirement>
<role>
com.dianping.cat.consumer.core.ProductLineConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.baseline.BaselineCreator
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.baseline.BaselineService
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.baseline.BaselineConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
metric
</role-hint>
</requirement>
</requirements>
</component>
<component>
...
...
cat-home/src/main/webapp/css/body.css
浏览文件 @
409a5815
...
...
@@ -393,6 +393,11 @@ a.abtest-heartbeat{
margin
:
4px
auto
;
}
.metricGraph
{
width
:
560px
;
height
:
300px
;
}
.pieChart
{
text-align
:
left
;
width
:
700px
;
...
...
cat-home/src/main/webapp/jsp/report/metric.jsp
浏览文件 @
409a5815
...
...
@@ -64,7 +64,7 @@
<c:forEach
var=
"item"
items=
"
${
model
.
display
.
lineCharts
}
"
varStatus=
"status"
>
<div
style=
"float:left;"
>
<h5
class=
"text-center text-error"
>
${item.title}
</h5>
<div
id=
"${item.title}"
class=
"
g
raph"
></div>
<div
id=
"${item.title}"
class=
"
metricG
raph"
></div>
</div>
</c:forEach>
</div>
...
...
cat-home/src/main/webapp/jsp/report/problem/problemQuery.jsp
浏览文件 @
409a5815
...
...
@@ -44,19 +44,18 @@
type=
"submit"
></div>
<script>
var
urlThreshold
=
'
${payload.urlThreshold}
'
;
$
(
"
#p_longUrl
"
).
val
(
urlThreshold
)
;
var
sqlThreshold
=
'
${payload.sqlThreshold}
'
;
$
(
"
#p_longSql
"
).
val
(
sqlThreshold
)
;
var
serviceThreshold
=
'
${payload.serviceThreshold}
'
;
$
(
"
#p_longService
"
).
val
(
serviceThreshold
)
;
var
cacheThreshold
=
'
${payload.cacheThreshold}
'
;
$
(
"
#p_longCache
"
).
val
(
cacheThreshold
)
;
var
callThreshold
=
'
${payload.callThreshold}
'
;
$
(
"
#p_longCall
"
).
val
(
callThreshold
)
;
var
urlThreshold
=
'
${payload.urlThreshold}
'
;
$
(
"
#p_longUrl
"
).
val
(
urlThreshold
)
;
var
sqlThreshold
=
'
${payload.sqlThreshold}
'
;
$
(
"
#p_longSql
"
).
val
(
sqlThreshold
)
;
var
serviceThreshold
=
'
${payload.serviceThreshold}
'
;
$
(
"
#p_longService
"
).
val
(
serviceThreshold
)
;
var
cacheThreshold
=
'
${payload.cacheThreshold}
'
;
$
(
"
#p_longCache
"
).
val
(
cacheThreshold
)
;
var
callThreshold
=
'
${payload.callThreshold}
'
;
$
(
"
#p_longCall
"
).
val
(
callThreshold
)
;
</script>
cat-home/src/test/java/com/dianping/cat/AllTests.java
浏览文件 @
409a5815
...
...
@@ -4,6 +4,7 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
com.dianping.cat.report.baseline.BaselineCreatorTest
;
import
com.dianping.cat.report.graph.ValueTranslaterTest
;
import
com.dianping.cat.report.page.cross.CMDBTest
;
import
com.dianping.cat.report.page.cross.CrossReportMergerTest
;
...
...
@@ -97,6 +98,11 @@ DependencyReportMergerTest.class, GraphConfigManagerTest.class,
/* CMDB */
CMDBTest
.
class
,
/* BaseLine */
BaselineCreatorTest
.
class
,
MetricReportParseTest
.
class
,
/* jsError */
ParseTest
.
class
})
public
class
AllTests
{
...
...
cat-home/src/test/java/com/dianping/cat/report/analyzer/OpDataCollectTest.java
浏览文件 @
409a5815
...
...
@@ -50,12 +50,12 @@ public class OpDataCollectTest extends ComponentTestCase {
buildHeartbeatData
(
domain
,
dateStr3
);
}
buildMetricData
(
"TuanGou"
,
"2013-07-0
2
00:00:00"
);
buildMetricData
(
"TuanGou"
,
"2013-07-0
1
00:00:00"
);
}
private
void
buildMetricData
(
String
group
,
String
str
)
throws
Exception
{
Date
start
=
m_sdf
.
parse
(
str
);
Date
end
=
new
Date
(
start
.
getTime
()
+
TimeUtil
.
ONE_
DAY
);
Date
end
=
new
Date
(
start
.
getTime
()
+
TimeUtil
.
ONE_
HOUR
);
MetricReport
report
=
m_hourlyReportService
.
queryMetricReport
(
group
,
start
,
end
);
System
.
out
.
println
(
report
);
}
...
...
cat-home/src/test/java/com/dianping/cat/report/baseline/BaselineCreatorTest.java
浏览文件 @
409a5815
...
...
@@ -15,20 +15,43 @@ public class BaselineCreatorTest {
@Test
public
void
testCreateBaseLine
(){
BaselineCreator
creator
=
new
DefaultBaselineCreator
();
List
<
double
[]>
valueList
=
new
ArrayList
<
double
[]>();
double
[]
values1
=
{
1
};
valueList
.
add
(
values1
);
double
[]
values2
=
{
2
};
valueList
.
add
(
values2
);
double
[]
values3
=
{
3
};
valueList
.
add
(
values3
);
double
[]
values4
=
{
12.6
};
valueList
.
add
(
values4
);
double
[]
values1
=
{
1
,
2
,
3
,
20
};
List
<
double
[]>
valueList
=
getListFromArray
(
values1
);
Double
[]
weights
=
{
1.0
,
1.0
,
1.0
,
1.0
};
List
<
Double
>
weightList
=
Arrays
.
asList
(
weights
);
Set
<
Integer
>
omittedPoints
=
new
HashSet
<
Integer
>();
double
[]
result
=
creator
.
createBaseLine
(
valueList
,
weightList
,
omittedPoints
,
1
);
double
[]
expectedResult
=
{
2.0
};
double
[]
expectedResult
=
{
6.5
};
Assert
.
assertArrayEquals
(
expectedResult
,
result
,
0.0001
);
double
[]
values2
=
{
97
,
99
,
101
,
103
};
valueList
=
getListFromArray
(
values2
);
result
=
creator
.
createBaseLine
(
valueList
,
weightList
,
omittedPoints
,
1
);
expectedResult
[
0
]
=
100
;
Assert
.
assertArrayEquals
(
expectedResult
,
result
,
0.0001
);
double
[]
values3
=
{
97
,
99
,
101
,
600
};
valueList
=
getListFromArray
(
values3
);
result
=
creator
.
createBaseLine
(
valueList
,
weightList
,
omittedPoints
,
1
);
expectedResult
[
0
]
=
99
;
Assert
.
assertArrayEquals
(
expectedResult
,
result
,
0.0001
);
double
[]
values4
=
{
19
,
99
,
101
,
600
};
valueList
=
getListFromArray
(
values4
);
result
=
creator
.
createBaseLine
(
valueList
,
weightList
,
omittedPoints
,
1
);
expectedResult
[
0
]
=
100
;
Assert
.
assertArrayEquals
(
expectedResult
,
result
,
0.0001
);
}
private
List
<
double
[]>
getListFromArray
(
double
[]
values
){
List
<
double
[]>
result
=
new
ArrayList
<
double
[]>();
for
(
double
value:
values
){
double
[]
valueItem
=
new
double
[
1
];
valueItem
[
0
]
=
value
;
result
.
add
(
valueItem
);
}
return
result
;
}
}
cat-home/src/test/java/com/dianping/cat/report/task/metric/MetricAlertTest.java
0 → 100644
浏览文件 @
409a5815
package
com.dianping.cat.report.task.metric
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
org.junit.Test
;
import
org.unidal.helper.Files
;
import
org.unidal.lookup.ComponentTestCase
;
import
org.xml.sax.SAXException
;
import
com.dianping.cat.consumer.metric.model.entity.MetricReport
;
import
com.dianping.cat.consumer.metric.model.transform.DefaultSaxParser
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.service.ModelResponse
;
public
class
MetricAlertTest
extends
ComponentTestCase
{
@Test
public
void
testMetricAlert
()
{
try
{
MetricAlert
alert
=
lookup
(
MetricAlert
.
class
);
ModelService
<
MetricReport
>
modelService
=
new
MyModelService
();
alert
.
m_service
=
modelService
;
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
alert
.
metricAlert
(
format
.
parse
(
"2013-07-10 10:00:00"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
class
MyModelService
implements
ModelService
<
MetricReport
>
{
@Override
public
String
getName
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
ModelResponse
<
MetricReport
>
invoke
(
ModelRequest
request
)
{
ModelResponse
<
MetricReport
>
response
=
new
ModelResponse
<
MetricReport
>();
String
xml
;
try
{
xml
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"metricReport.xml"
),
"utf-8"
);
MetricReport
report
=
DefaultSaxParser
.
parse
(
xml
);
response
.
setModel
(
report
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
SAXException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
response
;
}
@Override
public
boolean
isEligable
(
ModelRequest
request
)
{
return
true
;
}
}
}
cat-home/src/test/java/com/dianping/cat/report/task/metric/MetricBaselineReportBuilderTest.java
浏览文件 @
409a5815
package
com.dianping.cat.report.task.metric
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Date
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.unidal.lookup.ComponentTestCase
;
import
com.dianping.cat.home.dal.report.Baseline
;
import
com.dianping.cat.report.baseline.BaselineConfig
;
import
com.dianping.cat.report.baseline.BaselineConfigManager
;
import
com.dianping.cat.report.baseline.BaselineService
;
public
class
MetricBaselineReportBuilderTest
extends
ComponentTestCase
{
private
MetricBaselineReportBuilder
getReportBuilder
()
throws
Exception
{
public
class
MetricBaselineReportBuilderTest
extends
ComponentTestCase
{
private
MetricBaselineReportBuilder
getReportBuilder
()
throws
Exception
{
MetricBaselineReportBuilder
builder
=
lookup
(
MetricBaselineReportBuilder
.
class
);
builder
.
m_baselineConfigManager
=
new
MyBaselineConfigManager
();
builder
.
m_baselineService
=
new
MyBaselineService
();
return
builder
;
}
private
class
MyBaselineService
implements
BaselineService
{
private
class
MyBaselineConfigManager
extends
BaselineConfigManager
{
@Override
public
double
[]
queryDailyBaseline
(
String
reportName
,
String
key
,
Date
reportPeriod
)
{
return
null
;
}
public
BaselineConfig
queryBaseLineConfig
(
String
key
)
{
BaselineConfig
config
=
new
BaselineConfig
();
Integer
[]
days
=
{
0
,
-
1
,
-
2
,
-
3
,
-
4
};
Double
[]
weights
=
{
1.0
,
1.0
,
1.0
,
1.0
,
1.0
};
config
.
setDays
(
Arrays
.
asList
(
days
));
config
.
setId
(
1
);
config
.
setKey
(
key
);
config
.
setLowerLimit
(
100
);
config
.
setMinValue
(
0.2
);
config
.
setTargetDate
(
1
);
config
.
setUpperLimit
(
5
);
config
.
setWeights
(
Arrays
.
asList
(
weights
));
return
config
;
}
}
private
class
MyBaselineService
implements
BaselineService
{
@Override
public
double
[]
queryHour
lyBaseline
(
String
reportName
,
String
key
,
Date
reportPeriod
)
{
return
null
;
}
public
double
[]
queryDai
lyBaseline
(
String
reportName
,
String
key
,
Date
reportPeriod
)
{
return
null
;
}
@Override
public
void
insertBaseline
(
Baseline
baseline
)
{
System
.
out
.
println
(
baseline
.
toString
())
;
System
.
out
.
print
(
baseline
.
getDataInDoubleArray
().
length
+
":"
);
public
double
[]
queryHourlyBaseline
(
String
reportName
,
String
key
,
Date
reportPeriod
)
{
return
null
;
}
for
(
double
item:
baseline
.
getDataInDoubleArray
()){
System
.
out
.
print
(
item
+
","
);
@Override
public
void
insertBaseline
(
Baseline
baseline
)
{
if
(
baseline
.
getIndexKey
().
equals
(
"TuanGouWeb:URL:/index:COUNT"
))
{
Assert
.
assertEquals
(
2157.2
,
baseline
.
getDataInDoubleArray
()[
0
],
0.001
);
}
else
if
(
baseline
.
getIndexKey
().
equals
(
"TuanGouWeb:URL:/index:SUM"
))
{
Assert
.
assertEquals
(
5.02429914E8
,
baseline
.
getDataInDoubleArray
()[
0
],
0.001
);
}
else
if
(
baseline
.
getIndexKey
().
equals
(
"TuanGouWeb:URL:/index:AVG"
))
{
Assert
.
assertEquals
(
235669.78113
,
baseline
.
getDataInDoubleArray
()[
0
],
0.001
);
}
System
.
out
.
println
();
}
}
}
@Test
public
void
testBuildDailyReport
()
throws
Exception
{
public
void
testBuildDailyReport
()
throws
Exception
{
MetricBaselineReportBuilder
builder
=
getReportBuilder
();
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
builder
.
buildDaily
Task
(
"metir
c"
,
"TuanGouWeb:URL:/index"
,
format
.
parse
(
"2013-07-01 00:00:00"
));
builder
.
buildDaily
ReportInternal
(
"metri
c"
,
"TuanGouWeb:URL:/index"
,
format
.
parse
(
"2013-07-01 00:00:00"
));
}
}
cat-home/src/test/resources/com/dianping/cat/report/task/metric/metricReport.xml
0 → 100644
浏览文件 @
409a5815
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录