Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
3e7dc9dd
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,发现更多精彩内容 >>
提交
3e7dc9dd
编写于
10月 17, 2013
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #155 from sunryuan/biz
refactor metric report
上级
8a7a6fd1
ab9b84a8
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
279 addition
and
226 deletion
+279
-226
cat-home/src/main/java/com/dianping/cat/report/page/metric/DataExtractor.java
...va/com/dianping/cat/report/page/metric/DataExtractor.java
+75
-0
cat-home/src/main/java/com/dianping/cat/report/page/metric/Handler.java
...ain/java/com/dianping/cat/report/page/metric/Handler.java
+3
-74
cat-home/src/main/java/com/dianping/cat/report/page/metric/MetricDate.java
.../java/com/dianping/cat/report/page/metric/MetricDate.java
+27
-0
cat-home/src/main/java/com/dianping/cat/report/page/metric/MetricDisplay.java
...va/com/dianping/cat/report/page/metric/MetricDisplay.java
+143
-85
cat-home/src/main/java/com/dianping/cat/report/page/metric/MetricReportMerger.java
...m/dianping/cat/report/page/metric/MetricReportMerger.java
+7
-37
cat-home/src/main/java/com/dianping/cat/report/page/metric/Payload.java
...ain/java/com/dianping/cat/report/page/metric/Payload.java
+22
-22
cat-home/src/main/java/com/dianping/cat/report/page/metric/Range.java
.../main/java/com/dianping/cat/report/page/metric/Range.java
+2
-2
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+0
-3
cat-home/src/main/webapp/jsp/report/metric/metric.jsp
cat-home/src/main/webapp/jsp/report/metric/metric.jsp
+0
-3
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/page/metric/DataExtractor.java
0 → 100644
浏览文件 @
3e7dc9dd
package
com.dianping.cat.report.page.metric
;
import
java.util.List
;
public
class
DataExtractor
{
private
int
m_timeRange
;
private
int
m_interval
;
private
static
final
int
MINUTE
=
60
;
public
DataExtractor
(
int
timeRange
,
int
interval
)
{
super
();
this
.
m_timeRange
=
timeRange
;
this
.
m_interval
=
interval
;
}
public
double
[]
extract
(
List
<
double
[]>
datas
,
int
offset
)
{
int
pointNumber
=
(
m_timeRange
*
MINUTE
)
/
m_interval
;
double
[]
result
=
new
double
[
pointNumber
];
if
(
datas
==
null
)
{
return
result
;
}
int
size
=
datas
.
size
();
double
[]
hourData
=
null
;
int
length
=
0
;
for
(
int
i
=
0
,
j
=
-
1
;
i
<
pointNumber
;
i
++)
{
int
insideOffset
=
i
*
m_interval
+
offset
;
while
(
length
<=
insideOffset
)
{
insideOffset
=
insideOffset
-
length
;
offset
=
offset
-
length
;
j
++;
if
(
j
>=
size
)
{
return
result
;
}
hourData
=
datas
.
get
(
j
);
if
(
hourData
==
null
)
{
length
=
0
;
continue
;
}
length
=
hourData
.
length
;
}
result
[
i
]
=
avgOfArray
(
hourData
,
insideOffset
,
m_interval
);
}
return
result
;
}
private
double
avgOfArray
(
double
[]
values
,
int
index
,
int
interval
)
{
double
result
=
0
;
for
(
int
i
=
index
;
i
<
index
+
interval
;
i
++)
{
if
(
values
[
i
]
>=
0
)
{
result
+=
values
[
i
];
}
}
return
result
/
interval
;
}
// private double sumOfArray(double[] values, int index, int interval) {
//
// double result = 0;
//
// for (int i = index; i < index + interval; i++) {
// if (values[i] >= 0) {
// result += values[i];
// }
// }
// return result;
// }
}
cat-home/src/main/java/com/dianping/cat/report/page/metric/Handler.java
浏览文件 @
3e7dc9dd
...
@@ -5,10 +5,7 @@ import java.util.ArrayList;
...
@@ -5,10 +5,7 @@ import java.util.ArrayList;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
...
@@ -18,7 +15,6 @@ import org.unidal.web.mvc.annotation.InboundActionMeta;
...
@@ -18,7 +15,6 @@ import org.unidal.web.mvc.annotation.InboundActionMeta;
import
org.unidal.web.mvc.annotation.OutboundActionMeta
;
import
org.unidal.web.mvc.annotation.OutboundActionMeta
;
import
org.unidal.web.mvc.annotation.PayloadMeta
;
import
org.unidal.web.mvc.annotation.PayloadMeta
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.consumer.advanced.MetricConfigManager
;
import
com.dianping.cat.consumer.advanced.MetricConfigManager
;
import
com.dianping.cat.consumer.advanced.ProductLineConfigManager
;
import
com.dianping.cat.consumer.advanced.ProductLineConfigManager
;
...
@@ -31,10 +27,6 @@ import com.dianping.cat.report.page.LineChart;
...
@@ -31,10 +27,6 @@ import com.dianping.cat.report.page.LineChart;
import
com.dianping.cat.report.page.PayloadNormalizer
;
import
com.dianping.cat.report.page.PayloadNormalizer
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.report.service.ReportService
;
import
com.dianping.cat.report.service.ReportService
;
import
com.dianping.cat.service.ModelPeriod
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.service.ModelResponse
;
import
com.dianping.cat.system.page.abtest.service.ABTestService
;
public
class
Handler
implements
PageHandler
<
Context
>
{
public
class
Handler
implements
PageHandler
<
Context
>
{
@Inject
@Inject
...
@@ -52,9 +44,6 @@ public class Handler implements PageHandler<Context> {
...
@@ -52,9 +44,6 @@ public class Handler implements PageHandler<Context> {
@Inject
@Inject
private
ProductLineConfigManager
m_productLineConfigManager
;
private
ProductLineConfigManager
m_productLineConfigManager
;
@Inject
private
ABTestService
m_abtestService
;
@Inject
@Inject
private
ReportService
m_reportService
;
private
ReportService
m_reportService
;
...
@@ -63,47 +52,6 @@ public class Handler implements PageHandler<Context> {
...
@@ -63,47 +52,6 @@ public class Handler implements PageHandler<Context> {
private
static
final
String
TUAN
=
"TuanGou"
;
private
static
final
String
TUAN
=
"TuanGou"
;
private
final
Map
<
String
,
MetricReport
>
m_metricReportMap
=
new
LinkedHashMap
<
String
,
MetricReport
>()
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
protected
boolean
removeEldestEntry
(
Entry
<
String
,
MetricReport
>
eldest
)
{
return
size
()
>
1000
;
}
};
private
MetricReport
getReportFromDB
(
String
product
,
long
date
)
{
String
key
=
product
+
date
;
MetricReport
result
=
m_metricReportMap
.
get
(
key
);
if
(
result
==
null
)
{
Date
start
=
new
Date
(
date
);
Date
end
=
new
Date
(
date
+
TimeUtil
.
ONE_HOUR
);
try
{
result
=
m_reportService
.
queryMetricReport
(
product
,
start
,
end
);
m_metricReportMap
.
put
(
key
,
result
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
return
result
;
}
private
MetricReport
getReport
(
ModelPeriod
period
,
String
product
,
long
date
)
{
if
(
period
==
ModelPeriod
.
CURRENT
||
period
==
ModelPeriod
.
LAST
)
{
ModelRequest
request
=
new
ModelRequest
(
product
,
date
);
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
+
"!"
);
}
}
else
{
return
getReportFromDB
(
product
,
date
);
}
}
@Override
@Override
@PayloadMeta
(
Payload
.
class
)
@PayloadMeta
(
Payload
.
class
)
@InboundActionMeta
(
name
=
"metric"
)
@InboundActionMeta
(
name
=
"metric"
)
...
@@ -151,30 +99,11 @@ public class Handler implements PageHandler<Context> {
...
@@ -151,30 +99,11 @@ public class Handler implements PageHandler<Context> {
Date
startTime
=
new
Date
(
date
-
(
timeRange
-
1
)
*
TimeUtil
.
ONE_HOUR
);
Date
startTime
=
new
Date
(
date
-
(
timeRange
-
1
)
*
TimeUtil
.
ONE_HOUR
);
List
<
String
>
domains
=
m_productLineConfigManager
.
queryProductLineDomains
(
product
);
List
<
String
>
domains
=
m_productLineConfigManager
.
queryProductLineDomains
(
product
);
List
<
MetricItemConfig
>
metricConfigs
=
m_configManager
.
queryMetricItemConfigs
(
new
HashSet
<
String
>(
domains
));
List
<
MetricItemConfig
>
metricConfigs
=
m_configManager
.
queryMetricItemConfigs
(
new
HashSet
<
String
>(
domains
));
MetricDisplay
display
=
new
MetricDisplay
(
abtestID
,
startTime
,
isDashboard
,
timeRange
);
MetricDisplay
display
=
new
MetricDisplay
(
product
,
abtestID
,
startTime
,
isDashboard
,
timeRange
);
display
.
initializeLineCharts
(
metricConfigs
);
display
.
initializeLineCharts
(
metricConfigs
);
display
.
setBaselineService
(
m_baselineService
).
setReportService
(
m_reportService
).
setService
(
m_service
);
MetricDisplayMerger
displayMerger
=
new
MetricDisplayMerger
(
abtestID
,
isDashboard
);
display
.
generateAllCharts
();
long
time
=
startTime
.
getTime
();
displayMerger
.
setAbtestService
(
m_abtestService
);
display
.
setBaselineService
(
m_baselineService
);
display
.
setDisplayMerger
(
displayMerger
);
for
(
int
index
=
0
;
index
<
timeRange
;
index
++)
{
ModelPeriod
period
=
ModelPeriod
.
getByTime
(
time
);
MetricReport
report
=
getReport
(
period
,
product
,
time
);
if
(
report
!=
null
)
{
displayMerger
.
visitMetricReport
(
index
,
report
);
}
time
=
time
+
TimeUtil
.
ONE_HOUR
;
}
display
.
generateLineCharts
();
if
(
abtestID
.
equals
(
"-1"
))
{
display
.
generateBaselineChart
();
}
return
display
;
return
display
;
}
}
...
...
cat-home/src/main/java/com/dianping/cat/report/page/metric/MetricDate.java
0 → 100644
浏览文件 @
3e7dc9dd
package
com.dianping.cat.report.page.metric
;
public
enum
MetricDate
{
CURRENT
(
0
,
"当前时段"
),
LAST_DAY
(-
1
,
"前一天相同时段"
),
LAST_WEEK
(-
7
,
"上周相同时段"
);
int
m_index
;
String
m_title
;
private
MetricDate
(
int
index
,
String
title
)
{
m_index
=
index
;
m_title
=
title
;
}
public
int
getIndex
()
{
return
m_index
;
}
public
String
getTitle
()
{
return
m_title
;
}
}
cat-home/src/main/java/com/dianping/cat/report/page/metric/MetricDisplay.java
浏览文件 @
3e7dc9dd
...
@@ -8,14 +8,21 @@ import java.util.List;
...
@@ -8,14 +8,21 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.consumer.metric.model.entity.MetricReport
;
import
com.dianping.cat.consumer.metric.model.transform.BaseVisitor
;
import
com.dianping.cat.consumer.metric.model.transform.BaseVisitor
;
import
com.dianping.cat.helper.Chinese
;
import
com.dianping.cat.helper.Chinese
;
import
com.dianping.cat.helper.TimeUtil
;
import
com.dianping.cat.helper.TimeUtil
;
import
com.dianping.cat.report.baseline.BaselineService
;
import
com.dianping.cat.report.baseline.BaselineService
;
import
com.dianping.cat.report.page.LineChart
;
import
com.dianping.cat.report.page.LineChart
;
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.report.task.TaskHelper
;
import
com.dianping.cat.report.task.metric.MetricType
;
import
com.dianping.cat.report.task.metric.MetricType
;
import
com.dianping.cat.service.ModelPeriod
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.service.ModelResponse
;
public
class
MetricDisplay
extends
BaseVisitor
{
public
class
MetricDisplay
extends
BaseVisitor
{
...
@@ -23,21 +30,25 @@ public class MetricDisplay extends BaseVisitor {
...
@@ -23,21 +30,25 @@ public class MetricDisplay extends BaseVisitor {
private
Map
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>
m_abtests
=
new
HashMap
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>();
private
Map
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>
m_abtests
=
new
HashMap
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>();
private
Date
m_start
;
private
BaselineService
m_baselineService
;
private
BaselineService
m_baselineService
;
private
boolean
m_isDashboard
;
private
DataExtractor
m_dataExtractor
;
private
Date
m_start
;
private
MetricDisplayMerger
m_displayMerger
;
private
boolean
m_isDashboard
;
private
int
m_timeRange
;
private
int
m_timeRange
;
private
int
m_
pointNumber
;
private
int
m_
interval
=
1
;
private
int
m_realPointNumber
;
private
String
m_abtest
;
private
int
m_interval
=
1
;
private
String
m_product
;
private
static
final
int
MIN_POINT_NUMBER
=
60
;
private
static
final
int
MAX_POINT_NUMBER
=
180
;
private
static
final
String
SUM
=
MetricType
.
SUM
.
name
();
private
static
final
String
SUM
=
MetricType
.
SUM
.
name
();
...
@@ -45,19 +56,21 @@ public class MetricDisplay extends BaseVisitor {
...
@@ -45,19 +56,21 @@ public class MetricDisplay extends BaseVisitor {
private
static
final
String
AVG
=
MetricType
.
AVG
.
name
();
private
static
final
String
AVG
=
MetricType
.
AVG
.
name
();
private
static
final
int
HOUR
=
24
;
private
static
final
String
METRIC_STRING
=
"metric"
;
private
static
final
int
MINUTE
=
60
;
private
ReportService
m_reportService
;
private
static
final
String
METRIC_STRING
=
"metric"
;
private
ModelService
<
MetricReport
>
m_service
;
public
MetricDisplayMerger
getDisplayMerger
()
{
private
final
Map
<
String
,
MetricReport
>
m_metricReportMap
=
new
LinkedHashMap
<
String
,
MetricReport
>()
{
return
m_displayMerger
;
}
public
void
setDisplayMerger
(
MetricDisplayMerger
displayMerger
)
{
private
static
final
long
serialVersionUID
=
1L
;
m_displayMerger
=
displayMerger
;
}
@Override
protected
boolean
removeEldestEntry
(
Entry
<
String
,
MetricReport
>
eldest
)
{
return
size
()
>
1000
;
}
};
private
boolean
showAvg
(
MetricItemConfig
config
)
{
private
boolean
showAvg
(
MetricItemConfig
config
)
{
if
(
m_isDashboard
)
{
if
(
m_isDashboard
)
{
...
@@ -83,18 +96,61 @@ public class MetricDisplay extends BaseVisitor {
...
@@ -83,18 +96,61 @@ public class MetricDisplay extends BaseVisitor {
}
}
}
}
public
MetricDisplay
(
String
abtest
,
Date
start
,
boolean
isDashboard
,
int
timeRange
)
{
private
MetricReport
getReportFromDB
(
String
product
,
long
date
)
{
int
minute
=
(
int
)
(
System
.
currentTimeMillis
()
%
TimeUtil
.
ONE_HOUR
/
TimeUtil
.
ONE_MINUTE
);
String
key
=
product
+
date
;
MetricReport
result
=
m_metricReportMap
.
get
(
key
);
if
(
result
==
null
)
{
Date
start
=
new
Date
(
date
);
Date
end
=
new
Date
(
date
+
TimeUtil
.
ONE_HOUR
);
try
{
result
=
m_reportService
.
queryMetricReport
(
product
,
start
,
end
);
m_metricReportMap
.
put
(
key
,
result
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
return
result
;
}
private
MetricReport
getReport
(
ModelPeriod
period
,
String
product
,
long
date
)
{
if
(
period
==
ModelPeriod
.
CURRENT
||
period
==
ModelPeriod
.
LAST
)
{
ModelRequest
request
=
new
ModelRequest
(
product
,
date
);
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
+
"!"
);
}
}
else
{
return
getReportFromDB
(
product
,
date
);
}
}
public
MetricDisplay
(
String
product
,
String
abtest
,
Date
start
,
boolean
isDashboard
,
int
timeRange
)
{
m_product
=
product
;
m_isDashboard
=
isDashboard
;
m_isDashboard
=
isDashboard
;
m_start
=
start
;
m_start
=
start
;
m_timeRange
=
timeRange
;
m_timeRange
=
timeRange
;
if
(
m_timeRange
==
24
)
{
m_abtest
=
abtest
;
m_interval
=
6
;
m_interval
=
intervalCalculate
(
m_timeRange
);
m_dataExtractor
=
new
DataExtractor
(
m_timeRange
,
m_interval
);
}
private
int
intervalCalculate
(
int
timeRange
)
{
int
[]
values
=
{
1
,
2
,
3
,
6
,
10
,
20
,
30
,
60
};
for
(
int
value
:
values
)
{
int
pm
=
timeRange
*
60
/
value
;
if
(
pm
>=
MIN_POINT_NUMBER
&&
pm
<
MAX_POINT_NUMBER
)
{
return
value
;
}
}
int
pm
=
timeRange
*
60
/
60
;
if
(
pm
>
MAX_POINT_NUMBER
)
{
return
60
;
}
else
{
}
else
{
m_interval
=
1
;
return
1
;
}
}
m_pointNumber
=
m_timeRange
*
MINUTE
/
m_interval
;
m_realPointNumber
=
(
m_timeRange
*
MINUTE
-
60
+
minute
)
/
m_interval
;
}
}
public
void
initializeLineCharts
(
List
<
MetricItemConfig
>
configs
)
{
public
void
initializeLineCharts
(
List
<
MetricItemConfig
>
configs
)
{
...
@@ -117,87 +173,99 @@ public class MetricDisplay extends BaseVisitor {
...
@@ -117,87 +173,99 @@ public class MetricDisplay extends BaseVisitor {
private
LineChart
createLineChart
(
String
title
)
{
private
LineChart
createLineChart
(
String
title
)
{
LineChart
lineChart
=
new
LineChart
();
LineChart
lineChart
=
new
LineChart
();
int
pointNumber
=
m_timeRange
*
60
/
m_interval
;
lineChart
.
setTitle
(
title
);
lineChart
.
setTitle
(
title
);
lineChart
.
setStart
(
m_start
);
lineChart
.
setStart
(
m_start
);
lineChart
.
setSize
(
m_
pointNumber
);
lineChart
.
setSize
(
pointNumber
);
lineChart
.
setStep
(
TimeUtil
.
ONE_MINUTE
*
m_interval
);
lineChart
.
setStep
(
TimeUtil
.
ONE_MINUTE
*
m_interval
);
return
lineChart
;
return
lineChart
;
}
}
public
void
generateBaselineChart
()
{
public
void
generateAllCharts
()
{
long
startTime
=
m_start
.
getTime
();
for
(
MetricDate
metricDate
:
MetricDate
.
values
())
{
MetricReportMerger
merger
=
new
MetricReportMerger
(
m_abtest
,
metricDate
.
getTitle
());
long
time
=
startTime
+
metricDate
.
getIndex
()
*
TimeUtil
.
ONE_DAY
;
for
(
int
index
=
0
;
index
<
m_timeRange
;
index
++)
{
ModelPeriod
period
=
ModelPeriod
.
getByTime
(
time
);
MetricReport
report
=
getReport
(
period
,
m_product
,
time
);
if
(
report
!=
null
)
{
merger
.
visitMetricReport
(
index
,
report
);
}
time
=
time
+
TimeUtil
.
ONE_HOUR
;
}
generateLineCharts
(
merger
);
if
(
metricDate
.
equals
(
MetricDate
.
CURRENT
)
&&
m_abtest
.
equals
(
"-1"
))
{
generateBaselineChart
(
merger
);
}
}
}
public
void
generateBaselineChart
(
MetricReportMerger
merger
)
{
long
time
=
m_start
.
getTime
();
for
(
int
index
=
0
;
index
<
m_timeRange
;
index
++)
{
ModelPeriod
period
=
ModelPeriod
.
getByTime
(
time
);
MetricReport
report
=
getReport
(
period
,
m_product
,
time
);
if
(
report
!=
null
)
{
merger
.
visitMetricReport
(
index
,
report
);
}
time
=
time
+
TimeUtil
.
ONE_HOUR
;
}
for
(
String
key
:
m_lineCharts
.
keySet
())
{
for
(
String
key
:
m_lineCharts
.
keySet
())
{
LineChart
lineChart
=
m_lineCharts
.
get
(
key
);
LineChart
lineChart
=
m_lineCharts
.
get
(
key
);
Date
yesterday
=
TaskHelper
.
todayZero
(
m_start
);
Date
yesterday
=
TaskHelper
.
todayZero
(
m_start
);
boolean
isAvg
=
key
.
toUpperCase
().
endsWith
(
AVG
);
int
offset
=
(
int
)
((
m_start
.
getTime
()
+
8
*
TimeUtil
.
ONE_HOUR
)
%
TimeUtil
.
ONE_DAY
/
TimeUtil
.
ONE_MINUTE
);
int
index
=
(
int
)
((
m_start
.
getTime
()
+
8
*
TimeUtil
.
ONE_HOUR
)
%
TimeUtil
.
ONE_DAY
/
TimeUtil
.
ONE_MINUTE
);
double
[]
yesterdayBaseline
=
m_baselineService
.
queryDailyBaseline
(
METRIC_STRING
,
key
,
yesterday
);
double
[]
yesterdayBaseline
=
m_baselineService
.
queryDailyBaseline
(
METRIC_STRING
,
key
,
yesterday
);
Date
today
=
TaskHelper
.
tomorrowZero
(
m_start
);
Date
today
=
TaskHelper
.
tomorrowZero
(
m_start
);
double
[]
todayBaseline
=
m_baselineService
.
queryDailyBaseline
(
METRIC_STRING
,
key
,
today
);
double
[]
todayBaseline
=
m_baselineService
.
queryDailyBaseline
(
METRIC_STRING
,
key
,
today
);
double
[]
value
=
new
double
[
m_realPointNumber
];
List
<
double
[]>
datas
=
new
ArrayList
<
double
[]>();
double
[]
day
=
yesterdayBaseline
;
if
(
yesterdayBaseline
!=
null
)
{
for
(
int
i
=
0
;
i
<
m_realPointNumber
;
i
++)
{
datas
.
add
(
yesterdayBaseline
);
int
j
=
(
index
+
i
*
m_interval
)
%
(
HOUR
*
MINUTE
);
}
else
if
(
todayBaseline
!=
null
)
{
if
(
j
==
0
&&
index
!=
0
)
{
datas
.
add
(
todayBaseline
);
day
=
todayBaseline
;
}
if
(
day
==
null
)
{
continue
;
}
if
(
isAvg
)
{
value
[
i
]
=
avgOfArray
(
day
,
i
*
m_interval
);
}
else
{
value
[
i
]
=
sumOfArray
(
day
,
i
*
m_interval
);
}
}
}
double
[]
value
=
m_dataExtractor
.
extract
(
datas
,
offset
);
lineChart
.
addSubTitle
(
"Baseline"
);
lineChart
.
addSubTitle
(
"Baseline"
);
lineChart
.
addValue
(
value
);
lineChart
.
addValue
(
value
);
}
}
}
}
public
void
generateLineCharts
()
{
public
void
generateLineCharts
(
MetricReportMerger
merger
)
{
Map
<
String
,
Map
<
String
,
double
[][]>>
metricDatas
=
m
_displayM
erger
.
getMetricStatistic
();
Map
<
String
,
Map
<
String
,
double
[][]>>
metricDatas
=
merger
.
getMetricStatistic
();
for
(
Entry
<
String
,
Map
<
String
,
double
[][]>>
entry
:
metricDatas
.
entrySet
())
{
for
(
Entry
<
String
,
Map
<
String
,
double
[][]>>
entry
:
metricDatas
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
key
=
entry
.
getKey
();
Map
<
String
,
double
[][]>
value
=
entry
.
getValue
();
Map
<
String
,
double
[][]>
value
=
entry
.
getValue
();
LineChart
lineChart
=
m_lineCharts
.
get
(
key
);
LineChart
lineChart
=
m_lineCharts
.
get
(
key
);
List
<
double
[]>
resultValues
=
new
ArrayList
<
double
[]>();
List
<
String
>
subTitles
=
new
ArrayList
<
String
>();
boolean
isAvg
=
key
.
toUpperCase
().
endsWith
(
AVG
);
if
(
lineChart
==
null
)
{
if
(
lineChart
==
null
)
{
lineChart
=
createLineChart
(
key
);
lineChart
=
createLineChart
(
key
);
m_lineCharts
.
put
(
key
,
lineChart
);
m_lineCharts
.
put
(
key
,
lineChart
);
}
}
lineChart
.
setSubTitles
(
subTitles
);
lineChart
.
setValues
(
resultValues
);
for
(
Entry
<
String
,
double
[][]>
metricItem
:
value
.
entrySet
())
{
for
(
Entry
<
String
,
double
[][]>
metricItem
:
value
.
entrySet
())
{
String
subTitle
=
metricItem
.
getKey
();
String
subTitle
=
metricItem
.
getKey
();
double
[][]
metricItemData
=
metricItem
.
getValue
();
double
[][]
metricItemData
=
metricItem
.
getValue
();
double
[]
resultValue
=
new
double
[
m_realPointNumber
];
List
<
double
[]>
datas
=
new
ArrayList
<
double
[]>();
for
(
double
[]
data
:
metricItemData
)
{
subTitles
.
add
(
subTitle
);
if
(
data
==
null
)
{
resultValues
.
add
(
resultValue
);
data
=
new
double
[
60
];
for
(
int
hour
=
0
;
hour
<
metricItemData
.
length
;
hour
++)
{
for
(
int
i
=
0
;
i
<
MINUTE
/
m_interval
;
i
++)
{
int
index
=
hour
*
MINUTE
/
m_interval
+
i
;
if
(
metricItemData
[
hour
]
==
null
)
{
continue
;
}
if
(
index
>=
m_realPointNumber
)
{
break
;
}
if
(
isAvg
)
{
resultValue
[
index
]
=
avgOfArray
(
metricItemData
[
hour
],
i
*
m_interval
);
}
else
{
resultValue
[
index
]
=
sumOfArray
(
metricItemData
[
hour
],
i
*
m_interval
);
}
}
}
datas
.
add
(
data
);
}
}
double
[]
resultValue
=
m_dataExtractor
.
extract
(
datas
,
0
);
lineChart
.
addSubTitle
(
subTitle
);
lineChart
.
addValue
(
resultValue
);
}
}
}
}
...
@@ -216,24 +284,14 @@ public class MetricDisplay extends BaseVisitor {
...
@@ -216,24 +284,14 @@ public class MetricDisplay extends BaseVisitor {
return
this
;
return
this
;
}
}
private
double
avgOfArray
(
double
[]
values
,
int
j
)
{
public
MetricDisplay
setReportService
(
ReportService
m_reportService
)
{
double
result
=
0
;
this
.
m_reportService
=
m_reportService
;
for
(
int
i
=
j
;
i
<
j
+
m_interval
;
i
++)
{
return
this
;
if
(
values
[
i
]
>=
0
)
{
result
+=
values
[
i
];
}
}
return
result
/
m_interval
;
}
}
private
double
sumOfArray
(
double
[]
values
,
int
j
)
{
public
MetricDisplay
setService
(
ModelService
<
MetricReport
>
m_service
)
{
double
result
=
0
;
this
.
m_service
=
m_service
;
for
(
int
i
=
j
;
i
<
j
+
m_interval
;
i
++)
{
return
this
;
if
(
values
[
i
]
>=
0
)
{
result
+=
values
[
i
];
}
}
return
result
;
}
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/metric/Metric
Display
Merger.java
→
cat-home/src/main/java/com/dianping/cat/report/page/metric/Metric
Report
Merger.java
浏览文件 @
3e7dc9dd
package
com.dianping.cat.report.page.metric
;
package
com.dianping.cat.report.page.metric
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -11,22 +10,18 @@ import com.dianping.cat.consumer.metric.model.entity.MetricReport;
...
@@ -11,22 +10,18 @@ import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import
com.dianping.cat.consumer.metric.model.entity.Point
;
import
com.dianping.cat.consumer.metric.model.entity.Point
;
import
com.dianping.cat.consumer.metric.model.transform.BaseVisitor
;
import
com.dianping.cat.consumer.metric.model.transform.BaseVisitor
;
import
com.dianping.cat.report.task.metric.MetricType
;
import
com.dianping.cat.report.task.metric.MetricType
;
import
com.dianping.cat.system.page.abtest.service.ABTestService
;
public
class
MetricDisplayMerger
extends
BaseVisitor
{
public
class
MetricReportMerger
extends
BaseVisitor
{
private
Map
<
String
,
Map
<
String
,
double
[][]>>
m_metricStatistic
=
new
LinkedHashMap
<
String
,
Map
<
String
,
double
[][]>>();
private
Map
<
String
,
Map
<
String
,
double
[][]>>
m_metricStatistic
=
new
LinkedHashMap
<
String
,
Map
<
String
,
double
[][]>>();
private
Map
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>
m_abtests
=
new
HashMap
<
Integer
,
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
>();
private
String
m_abtest
;
private
String
m_abtest
;
private
String
m_subtitle
;
private
String
m_metricKey
;
private
String
m_metricKey
;
private
String
m_currentComputeType
;
private
String
m_currentComputeType
;
private
ABTestService
m_abtestService
;
private
int
m_index
;
private
int
m_index
;
private
static
final
String
SUM
=
MetricType
.
SUM
.
name
();
private
static
final
String
SUM
=
MetricType
.
SUM
.
name
();
...
@@ -35,18 +30,16 @@ public class MetricDisplayMerger extends BaseVisitor {
...
@@ -35,18 +30,16 @@ public class MetricDisplayMerger extends BaseVisitor {
private
static
final
String
AVG
=
MetricType
.
AVG
.
name
();
private
static
final
String
AVG
=
MetricType
.
AVG
.
name
();
private
boolean
m_isDashboard
;
public
MetricReportMerger
(
String
abtest
,
String
subtitle
)
{
public
MetricDisplayMerger
(
String
abtest
,
boolean
isDashboard
)
{
m_abtest
=
abtest
;
m_abtest
=
abtest
;
m_
isDashboard
=
isDashboard
;
m_
subtitle
=
subtitle
;
}
}
private
Map
<
String
,
double
[][]>
findOrCreateStatistic
(
String
type
,
String
metricKey
,
String
computeType
)
{
private
Map
<
String
,
double
[][]>
findOrCreateStatistic
(
String
type
,
String
metricKey
,
String
computeType
)
{
String
key
=
metricKey
+
":"
+
computeType
;
String
key
=
metricKey
+
":"
+
computeType
;
Map
<
String
,
double
[][]>
statisticItem
=
m_metricStatistic
.
get
(
key
);
Map
<
String
,
double
[][]>
statisticItem
=
m_metricStatistic
.
get
(
key
);
if
(
statisticItem
==
null
&&
!
m_isDashboard
)
{
if
(
statisticItem
==
null
)
{
if
(
computeType
.
equals
(
COUNT
))
{
if
(
computeType
.
equals
(
COUNT
))
{
if
(
type
.
equals
(
"C"
)
||
type
.
equals
(
"S,C"
))
{
if
(
type
.
equals
(
"C"
)
||
type
.
equals
(
"S,C"
))
{
statisticItem
=
createMetricStatistic
(
key
);
statisticItem
=
createMetricStatistic
(
key
);
...
@@ -66,11 +59,6 @@ public class MetricDisplayMerger extends BaseVisitor {
...
@@ -66,11 +59,6 @@ public class MetricDisplayMerger extends BaseVisitor {
}
}
return
statisticItem
;
return
statisticItem
;
}
}
public
MetricDisplayMerger
setAbtestService
(
ABTestService
service
)
{
m_abtestService
=
service
;
return
this
;
}
private
Map
<
String
,
double
[][]>
createMetricStatistic
(
String
key
)
{
private
Map
<
String
,
double
[][]>
createMetricStatistic
(
String
key
)
{
Map
<
String
,
double
[][]>
value
=
new
LinkedHashMap
<
String
,
double
[][]>();
Map
<
String
,
double
[][]>
value
=
new
LinkedHashMap
<
String
,
double
[][]>();
...
@@ -78,27 +66,9 @@ public class MetricDisplayMerger extends BaseVisitor {
...
@@ -78,27 +66,9 @@ public class MetricDisplayMerger extends BaseVisitor {
return
value
;
return
value
;
}
}
private
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
findAbTest
(
int
id
)
{
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
abtest
=
null
;
if
(
id
>=
0
)
{
abtest
=
m_abtestService
.
getABTestByRunId
(
id
);
}
if
(
abtest
==
null
)
{
abtest
=
new
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
();
abtest
.
setId
(
id
);
abtest
.
setName
(
String
.
valueOf
(
id
));
}
return
abtest
;
}
@Override
@Override
public
void
visitAbtest
(
Abtest
abtest
)
{
public
void
visitAbtest
(
Abtest
abtest
)
{
String
abtestId
=
abtest
.
getRunId
();
String
abtestId
=
abtest
.
getRunId
();
int
id
=
Integer
.
parseInt
(
abtestId
);
com
.
dianping
.
cat
.
home
.
dal
.
abtest
.
Abtest
temp
=
findAbTest
(
id
);
m_abtests
.
put
(
id
,
temp
);
if
(
m_abtest
.
equals
(
abtestId
))
{
if
(
m_abtest
.
equals
(
abtestId
))
{
super
.
visitAbtest
(
abtest
);
super
.
visitAbtest
(
abtest
);
}
}
...
@@ -109,7 +79,7 @@ public class MetricDisplayMerger extends BaseVisitor {
...
@@ -109,7 +79,7 @@ public class MetricDisplayMerger extends BaseVisitor {
String
id
=
group
.
getName
();
String
id
=
group
.
getName
();
if
(
""
.
equals
(
id
))
{
if
(
""
.
equals
(
id
))
{
id
=
"Current"
;
id
=
m_subtitle
;
}
}
double
[]
sum
=
new
double
[
60
];
double
[]
sum
=
new
double
[
60
];
...
...
cat-home/src/main/java/com/dianping/cat/report/page/metric/Payload.java
浏览文件 @
3e7dc9dd
...
@@ -18,17 +18,18 @@ public class Payload extends AbstractReportPayload<Action> {
...
@@ -18,17 +18,18 @@ public class Payload extends AbstractReportPayload<Action> {
@FieldMeta
(
"frequency"
)
@FieldMeta
(
"frequency"
)
private
int
m_frequency
=
10
;
private
int
m_frequency
=
10
;
@FieldMeta
(
"refresh"
)
@FieldMeta
(
"refresh"
)
private
boolean
m_refresh
=
false
;
private
boolean
m_refresh
=
false
;
@FieldMeta
(
"test"
)
@FieldMeta
(
"test"
)
private
String
m_test
=
"-1"
;
private
String
m_test
=
"-1"
;
@FieldMeta
(
"timeRange"
)
@FieldMeta
(
"timeRange"
)
private
int
m_timeRange
=
2
;
private
int
m_timeRange
=
2
;
@FieldMeta
(
"fullScreen"
)
@FieldMeta
(
"fullScreen"
)
private
boolean
m_fullScreen
=
false
;
private
boolean
m_fullScreen
=
false
;
public
Payload
()
{
public
Payload
()
{
super
(
ReportPage
.
METRIC
);
super
(
ReportPage
.
METRIC
);
}
}
...
@@ -67,34 +68,34 @@ public class Payload extends AbstractReportPayload<Action> {
...
@@ -67,34 +68,34 @@ public class Payload extends AbstractReportPayload<Action> {
public
void
setTest
(
String
test
)
{
public
void
setTest
(
String
test
)
{
m_test
=
test
;
m_test
=
test
;
}
}
public
int
getTimeRange
()
{
public
int
getTimeRange
()
{
return
m_timeRange
;
return
m_timeRange
;
}
}
public
int
getFrequency
()
{
public
int
getFrequency
()
{
return
m_frequency
;
return
m_frequency
;
}
}
public
void
setFrequency
(
int
frequency
)
{
public
void
setFrequency
(
int
frequency
)
{
m_frequency
=
frequency
;
m_frequency
=
frequency
;
}
}
public
boolean
isRefresh
()
{
public
boolean
isRefresh
()
{
return
m_refresh
;
return
m_refresh
;
}
}
public
void
setRefresh
(
boolean
refresh
)
{
public
void
setRefresh
(
boolean
refresh
)
{
m_refresh
=
refresh
;
m_refresh
=
refresh
;
}
}
public
boolean
isFullScreen
()
{
public
boolean
isFullScreen
()
{
return
m_fullScreen
;
return
m_fullScreen
;
}
}
public
void
setFullScreen
(
boolean
fullScreen
)
{
public
void
setFullScreen
(
boolean
fullScreen
)
{
m_fullScreen
=
fullScreen
;
m_fullScreen
=
fullScreen
;
}
}
@Override
@Override
public
void
validate
(
ActionContext
<?>
ctx
)
{
public
void
validate
(
ActionContext
<?>
ctx
)
{
...
@@ -102,6 +103,5 @@ public class Payload extends AbstractReportPayload<Action> {
...
@@ -102,6 +103,5 @@ public class Payload extends AbstractReportPayload<Action> {
m_action
=
Action
.
METRIC
;
m_action
=
Action
.
METRIC
;
}
}
}
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/metric/Range.java
浏览文件 @
3e7dc9dd
...
@@ -9,8 +9,8 @@ public enum Range {
...
@@ -9,8 +9,8 @@ public enum Range {
NINE
(
"9小时"
,
9
),
NINE
(
"9小时"
,
9
),
THELVE
(
"12小时"
,
12
),
THELVE
(
"12小时"
,
12
),
ONE_DAY
(
"24小时"
,
24
),
;
ONE_DAY
(
"24小时"
,
24
),
;
private
Range
(
String
title
,
int
duration
)
{
private
Range
(
String
title
,
int
duration
)
{
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
3e7dc9dd
...
@@ -2811,9 +2811,6 @@
...
@@ -2811,9 +2811,6 @@
<requirement>
<requirement>
<role>
com.dianping.cat.consumer.advanced.ProductLineConfigManager
</role>
<role>
com.dianping.cat.consumer.advanced.ProductLineConfigManager
</role>
</requirement>
</requirement>
<requirement>
<role>
com.dianping.cat.system.page.abtest.service.ABTestService
</role>
</requirement>
<requirement>
<requirement>
<role>
com.dianping.cat.report.service.ReportService
</role>
<role>
com.dianping.cat.report.service.ReportService
</role>
</requirement>
</requirement>
...
...
cat-home/src/main/webapp/jsp/report/metric/metric.jsp
浏览文件 @
3e7dc9dd
...
@@ -76,9 +76,6 @@
...
@@ -76,9 +76,6 @@
</div>
<!--/.well -->
</div>
<!--/.well -->
</div>
<!--/span-->
</div>
<!--/span-->
<div
class=
"span10"
>
<div
class=
"span10"
>
<c:if
test=
"
${
payload
.
timeRange
eq
24
}
"
>
<h4
class=
'text-red'
>
说明:图中纵轴数据为10分钟数据之和
</h4>
</c:if>
<c:forEach
var=
"item"
items=
"
${
model
.
lineCharts
}
"
varStatus=
"status"
>
<c:forEach
var=
"item"
items=
"
${
model
.
lineCharts
}
"
varStatus=
"status"
>
<div
style=
"float:left;"
>
<div
style=
"float:left;"
>
<div
id=
"${item.title}"
class=
"metricGraph"
></div>
<div
id=
"${item.title}"
class=
"metricGraph"
></div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录