Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
a45a9bbc
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,发现更多精彩内容 >>
提交
a45a9bbc
编写于
12月 18, 2013
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refator the graph creator
上级
3690430d
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
596 addition
and
712 deletion
+596
-712
cat-consumer-advanced/src/main/resources/META-INF/plexus/components.xml
...dvanced/src/main/resources/META-INF/plexus/components.xml
+8
-20
cat-home/src/main/java/com/dianping/cat/report/task/event/EventGraphCreator.java
...com/dianping/cat/report/task/event/EventGraphCreator.java
+135
-170
cat-home/src/main/java/com/dianping/cat/report/task/event/EventMerger.java
.../java/com/dianping/cat/report/task/event/EventMerger.java
+0
-11
cat-home/src/main/java/com/dianping/cat/report/task/event/EventReportBuilder.java
...om/dianping/cat/report/task/event/EventReportBuilder.java
+5
-6
cat-home/src/main/java/com/dianping/cat/report/task/heartbeat/HeartbeatGraphCreator.java
...ping/cat/report/task/heartbeat/HeartbeatGraphCreator.java
+103
-126
cat-home/src/main/java/com/dianping/cat/report/task/heartbeat/HeartbeatReportBuilder.java
...ing/cat/report/task/heartbeat/HeartbeatReportBuilder.java
+4
-2
cat-home/src/main/java/com/dianping/cat/report/task/problem/ProblemGraphCreator.java
...dianping/cat/report/task/problem/ProblemGraphCreator.java
+106
-137
cat-home/src/main/java/com/dianping/cat/report/task/problem/ProblemReportBuilder.java
...ianping/cat/report/task/problem/ProblemReportBuilder.java
+2
-5
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionGraphCreator.java
.../cat/report/task/transaction/TransactionGraphCreator.java
+205
-189
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionMerger.java
...anping/cat/report/task/transaction/TransactionMerger.java
+0
-11
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionReportBuilder.java
...cat/report/task/transaction/TransactionReportBuilder.java
+3
-6
cat-home/src/main/webapp/jsp/report/event/eventHistoryGraphs.jsp
...e/src/main/webapp/jsp/report/event/eventHistoryGraphs.jsp
+0
-1
cat-home/src/test/java/com/dianping/cat/report/page/heartbeat/HeartbeatGraphDataTest.java
...ing/cat/report/page/heartbeat/HeartbeatGraphDataTest.java
+1
-1
cat-home/src/test/java/com/dianping/cat/report/task/event/BuilderTest.java
.../java/com/dianping/cat/report/task/event/BuilderTest.java
+10
-0
cat-home/src/test/java/com/dianping/cat/report/task/event/EventDailyGraphMergerTest.java
...ping/cat/report/task/event/EventDailyGraphMergerTest.java
+0
-8
cat-home/src/test/java/com/dianping/cat/report/task/event/EventGraphCreatorTest.java
...dianping/cat/report/task/event/EventGraphCreatorTest.java
+3
-1
cat-home/src/test/java/com/dianping/cat/report/task/problem/ProblemCreateGraphDataTest.java
...g/cat/report/task/problem/ProblemCreateGraphDataTest.java
+1
-1
cat-home/src/test/java/com/dianping/cat/report/task/problem/ProblemGraphCreatorTest.java
...ping/cat/report/task/problem/ProblemGraphCreatorTest.java
+1
-1
cat-home/src/test/java/com/dianping/cat/report/task/transaction/TransactionDailyGraphMergerTest.java
...ort/task/transaction/TransactionDailyGraphMergerTest.java
+0
-9
cat-home/src/test/java/com/dianping/cat/report/task/transaction/TransactionGraphCreatorTest.java
.../report/task/transaction/TransactionGraphCreatorTest.java
+9
-7
未找到文件。
cat-consumer-advanced/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
a45a9bbc
...
...
@@ -267,39 +267,27 @@
</component>
<component>
<role>
com.dianping.cat.analysis.MessageAnalyzer
</role>
<role-hint>
browser
</role-hint>
<implementation>
com.dianping.cat.consumer.browser.BrowserAnalyzer
</implementation>
<role-hint>
browser
Meta
</role-hint>
<implementation>
com.dianping.cat.consumer.browser.Browser
Meta
Analyzer
</implementation>
<instantiation-strategy>
per-lookup
</instantiation-strategy>
<requirements>
<requirement>
<role>
com.dianping.cat.service.ReportManager
</role>
<role-hint>
browser
</role-hint>
</requirement>
<requirement>
<role>
com.dianping.cat.consumer.browser.UserAgentManager
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.consumer.browser.UserAgentManager
</role>
<implementation>
com.dianping.cat.consumer.browser.DefaultUserAgentManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.consumer.advanced.dal.UserAgentDao
</role>
<role-hint>
browserMeta
</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.service.ReportManager
</role>
<role-hint>
browser
</role-hint>
<role-hint>
browser
Meta
</role-hint>
<implementation>
com.dianping.cat.service.DefaultReportManager
</implementation>
<configuration>
<name>
browser
</name>
<name>
browser
Meta
</name>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.service.ReportDelegate
</role>
<role-hint>
browser
</role-hint>
<role-hint>
browser
Meta
</role-hint>
</requirement>
<requirement>
<role>
com.dianping.cat.storage.BucketManager
</role>
...
...
@@ -314,8 +302,8 @@
</component>
<component>
<role>
com.dianping.cat.service.ReportDelegate
</role>
<role-hint>
browser
</role-hint>
<implementation>
com.dianping.cat.consumer.browser.BrowserDelegate
</implementation>
<role-hint>
browser
Meta
</role-hint>
<implementation>
com.dianping.cat.consumer.browser.Browser
Meta
Delegate
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.task.TaskManager
</role>
...
...
cat-home/src/main/java/com/dianping/cat/report/task/event/EventGraphCreator.java
浏览文件 @
a45a9bbc
/**
*
*/
package
com.dianping.cat.report.task.event
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
com.dianping.cat.consumer.event.EventAnalyzer
;
import
com.dianping.cat.consumer.event.model.entity.EventName
;
import
com.dianping.cat.consumer.event.model.entity.EventReport
;
import
com.dianping.cat.consumer.event.model.entity.EventType
;
import
com.dianping.cat.consumer.event.model.entity.Machine
;
import
com.dianping.cat.consumer.event.model.entity.Range
;
import
com.dianping.cat.consumer.event.model.transform.BaseVisitor
;
import
com.dianping.cat.core.dal.Graph
;
import
com.dianping.cat.report.task.spi.GraphLine
;
public
class
EventGraphCreator
{
private
List
<
Graph
>
m_graphs
=
new
ArrayList
<
Graph
>();
private
EventReport
m_report
;
public
List
<
Graph
>
buildGraph
(
EventReport
report
)
{
m_report
=
report
;
new
EventReportVisitor
().
visitEventReport
(
report
);
return
m_graphs
;
}
private
class
EventReportVisitor
extends
BaseVisitor
{
String
m_currentIp
;
String
m_currentType
;
int
m_currentIndex
;
GraphLine
m_currentDetail
;
GraphLine
m_currentSummary
;
GraphLine
m_allDetail
;
GraphLine
m_allSummary
;
Map
<
String
,
GraphLine
>
m_allDetails
=
new
HashMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
m_allSummaries
=
new
HashMap
<
String
,
GraphLine
>();
StringBuilder
m_summaryContent
;
StringBuilder
m_detailContent
;
StringBuilder
m_allSummaryContent
;
StringBuilder
m_allDetailContent
;
private
void
addRange
(
GraphLine
graphLine
,
int
index
,
Range
range
)
{
graphLine
.
totalCounts
[
index
]
+=
range
.
getCount
();
graphLine
.
failCounts
[
index
]
+=
range
.
getFails
();
private
long
[]
arrayAdd
(
long
[]
src
,
long
added
[])
{
int
size
=
added
.
length
;
if
(
src
==
null
)
{
src
=
new
long
[
size
];
}
private
String
arrayToString
(
long
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
11
)
{
sb
.
append
(
','
);
}
}
return
sb
.
toString
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
src
[
i
]
=
src
[
i
]
+
added
[
i
];
}
return
src
;
}
private
void
buildContent
(
StringBuilder
content
,
EventType
type
,
GraphLine
graphLine
)
{
content
.
append
(
type
.
getId
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\n'
);
private
String
arrayToString
(
long
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
11
)
{
sb
.
append
(
','
);
}
}
return
sb
.
toString
();
}
private
void
buildContent
(
StringBuilder
content
,
String
type
,
EventName
name
,
GraphLine
graphLine
)
{
content
.
append
(
type
).
append
(
'\t'
)
;
content
.
append
(
name
.
getId
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\n'
);
private
long
[]
getFailsCount
(
List
<
Range
>
ranges
)
{
long
[]
value
=
new
long
[
12
]
;
for
(
Range
range
:
ranges
)
{
int
minute
=
range
.
getValue
(
);
value
[
minute
/
5
]
=
range
.
getFails
(
);
}
return
value
;
}
private
void
buildContent
(
StringBuilder
content
,
String
key
,
GraphLine
graphLine
)
{
content
.
append
(
key
).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\n'
);
private
long
[]
getTotalCount
(
List
<
Range
>
ranges
)
{
long
[]
value
=
new
long
[
12
];
for
(
Range
range
:
ranges
)
{
int
minute
=
range
.
getValue
();
value
[
minute
/
5
]
=
range
.
getCount
();
}
return
value
;
}
private
Graph
buildGraph
(
String
ip
)
{
public
List
<
Graph
>
splitReportToGraphs
(
Date
reportPeriod
,
String
domainName
,
String
reportName
,
EventReport
eventReport
)
{
Set
<
String
>
ips
=
eventReport
.
getIps
();
List
<
Graph
>
graphs
=
new
ArrayList
<
Graph
>(
ips
.
size
()
+
1
);
Map
<
String
,
GraphLine
>
allDetailCache
=
new
TreeMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
allSummaryCache
=
new
TreeMap
<
String
,
GraphLine
>();
Date
creationDate
=
new
Date
();
for
(
String
ip
:
ips
)
{
Graph
graph
=
new
Graph
();
graph
.
setIp
(
ip
);
graph
.
setDomain
(
m_report
.
getDomain
()
);
graph
.
setName
(
EventAnalyzer
.
ID
);
graph
.
setPeriod
(
m_report
.
getStartTime
()
);
graph
.
setDomain
(
domainName
);
graph
.
setName
(
reportName
);
graph
.
setPeriod
(
reportPeriod
);
graph
.
setType
(
3
);
graph
.
setCreationDate
(
new
Date
());
return
graph
;
}
private
void
buildGraphLine
(
GraphLine
graphLine
,
EventName
name
,
boolean
isNew
)
{
if
(
isNew
)
{
graphLine
.
totalCounts
=
new
long
[
12
];
graphLine
.
failCounts
=
new
long
[
12
];
graphLine
.
sums
=
new
double
[
12
];
}
}
private
void
buildGraphLine
(
GraphLine
graphLine
,
EventType
type
,
boolean
isNew
)
{
if
(
isNew
)
{
graphLine
.
totalCounts
=
new
long
[
12
];
graphLine
.
failCounts
=
new
long
[
12
];
}
}
@Override
public
void
visitEventReport
(
EventReport
eventReport
)
{
Graph
allGraph
=
buildGraph
(
"all"
);
m_graphs
.
add
(
allGraph
);
m_allDetailContent
=
new
StringBuilder
();
m_allSummaryContent
=
new
StringBuilder
();
super
.
visitEventReport
(
eventReport
);
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_allDetails
.
entrySet
())
{
buildContent
(
m_allDetailContent
,
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_allSummaries
.
entrySet
())
{
buildContent
(
m_allSummaryContent
,
entry
.
getKey
(),
entry
.
getValue
());
}
allGraph
.
setDetailContent
(
m_allDetailContent
.
toString
());
allGraph
.
setSummaryContent
(
m_allSummaryContent
.
toString
());
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
m_currentIp
=
machine
.
getIp
();
Graph
graph
=
buildGraph
(
m_currentIp
);
m_graphs
.
add
(
graph
);
m_summaryContent
=
new
StringBuilder
();
m_detailContent
=
new
StringBuilder
();
super
.
visitMachine
(
machine
);
graph
.
setDetailContent
(
m_detailContent
.
toString
());
graph
.
setSummaryContent
(
m_summaryContent
.
toString
());
}
graph
.
setCreationDate
(
creationDate
);
Machine
machine
=
eventReport
.
getMachines
().
get
(
ip
);
Map
<
String
,
EventType
>
types
=
machine
.
getTypes
();
StringBuilder
detailBuilder
=
new
StringBuilder
();
StringBuilder
summaryBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
EventType
>
eventEntry
:
types
.
entrySet
())
{
EventType
eventType
=
eventEntry
.
getValue
();
long
[]
typeCounts
=
new
long
[
12
];
long
[]
typeFails
=
new
long
[
12
];
Map
<
String
,
EventName
>
names
=
eventType
.
getNames
();
for
(
Entry
<
String
,
EventName
>
nameEntry
:
names
.
entrySet
())
{
EventName
eventName
=
nameEntry
.
getValue
();
List
<
Range
>
ranges
=
new
ArrayList
<
Range
>(
eventName
.
getRanges
().
values
());
detailBuilder
.
append
(
eventType
.
getId
());
detailBuilder
.
append
(
'\t'
);
detailBuilder
.
append
(
eventName
.
getId
());
detailBuilder
.
append
(
'\t'
);
long
[]
totalCount
=
getTotalCount
(
ranges
);
detailBuilder
.
append
(
arrayToString
(
totalCount
));
detailBuilder
.
append
(
'\t'
);
long
[]
failCount
=
getFailsCount
(
ranges
);
detailBuilder
.
append
(
arrayToString
(
failCount
));
detailBuilder
.
append
(
'\n'
);
String
key
=
eventType
.
getId
()
+
"\t"
+
eventName
.
getId
();
GraphLine
detailLine
=
allDetailCache
.
get
(
key
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
allDetailCache
.
put
(
key
,
detailLine
);
}
detailLine
.
totalCounts
=
arrayAdd
(
detailLine
.
totalCounts
,
totalCount
);
detailLine
.
failCounts
=
arrayAdd
(
detailLine
.
failCounts
,
failCount
);
typeCounts
=
arrayAdd
(
typeCounts
,
totalCount
);
typeFails
=
arrayAdd
(
typeFails
,
failCount
);
}
@Override
public
void
visitName
(
EventName
name
)
{
String
key
=
m_currentType
+
"\t"
+
name
.
getId
();
m_allDetail
=
m_allDetails
.
get
(
key
);
if
(
m_allDetail
==
null
)
{
m_allDetail
=
new
GraphLine
();
m_allDetails
.
put
(
key
,
m_allDetail
);
buildGraphLine
(
m_allDetail
,
name
,
true
);
}
else
{
buildGraphLine
(
m_allDetail
,
name
,
false
);
String
summaryKey
=
eventType
.
getId
();
GraphLine
summaryLine
=
allSummaryCache
.
get
(
summaryKey
);
if
(
summaryLine
==
null
)
{
summaryLine
=
new
GraphLine
();
allSummaryCache
.
put
(
summaryKey
,
summaryLine
);
}
summaryLine
.
totalCounts
=
arrayAdd
(
summaryLine
.
totalCounts
,
typeCounts
);
summaryLine
.
failCounts
=
arrayAdd
(
summaryLine
.
failCounts
,
typeFails
);
summaryBuilder
.
append
(
eventType
.
getId
());
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
arrayToString
(
typeCounts
));
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
arrayToString
(
typeFails
));
summaryBuilder
.
append
(
'\n'
);
}
m_currentDetail
=
new
GraphLine
();
buildGraphLine
(
m_currentDetail
,
name
,
true
);
m_currentIndex
=
0
;
super
.
visitName
(
name
);
buildContent
(
m_detailContent
,
m_currentType
,
name
,
m_currentDetail
);
graph
.
setDetailContent
(
detailBuilder
.
toString
());
graph
.
setSummaryContent
(
summaryBuilder
.
toString
());
graphs
.
add
(
graph
);
}
@Override
public
void
visitRange
(
Range
range
)
{
addRange
(
m_currentDetail
,
m_currentIndex
,
range
);
addRange
(
m_currentSummary
,
m_currentIndex
,
range
);
addRange
(
m_allDetail
,
m_currentIndex
,
range
);
addRange
(
m_allSummary
,
m_currentIndex
,
range
);
m_currentIndex
++;
Graph
allGraph
=
new
Graph
();
allGraph
.
setIp
(
"all"
);
allGraph
.
setDomain
(
domainName
);
allGraph
.
setName
(
reportName
);
allGraph
.
setPeriod
(
reportPeriod
);
allGraph
.
setType
(
3
);
allGraph
.
setCreationDate
(
creationDate
);
StringBuilder
detailSb
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
entry
:
allDetailCache
.
entrySet
())
{
detailSb
.
append
(
entry
.
getKey
());
detailSb
.
append
(
'\t'
);
GraphLine
value
=
entry
.
getValue
();
detailSb
.
append
(
arrayToString
(
value
.
totalCounts
));
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
arrayToString
(
value
.
failCounts
));
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
'\n'
);
}
@Override
public
void
visitType
(
EventType
type
)
{
// TYPE, TOTAL_COUNT, FAILURE_COUNT, MIN, MAX, SUM, SUM2
m_currentType
=
type
.
getId
();
String
key
=
m_currentType
;
m_allSummary
=
m_allSummaries
.
get
(
key
);
if
(
m_allSummary
==
null
)
{
m_allSummary
=
new
GraphLine
();
m_allSummaries
.
put
(
key
,
m_allSummary
);
buildGraphLine
(
m_allSummary
,
type
,
true
);
}
else
{
buildGraphLine
(
m_allSummary
,
type
,
false
);
}
m_currentSummary
=
new
GraphLine
();
buildGraphLine
(
m_currentSummary
,
type
,
true
);
super
.
visitType
(
type
);
buildContent
(
m_summaryContent
,
type
,
m_currentSummary
);
allGraph
.
setDetailContent
(
detailSb
.
toString
());
StringBuilder
summarySb
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
entry
:
allSummaryCache
.
entrySet
())
{
summarySb
.
append
(
entry
.
getKey
());
summarySb
.
append
(
'\t'
);
GraphLine
value
=
entry
.
getValue
();
summarySb
.
append
(
arrayToString
(
value
.
totalCounts
));
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
arrayToString
(
value
.
failCounts
));
summarySb
.
append
(
'\n'
);
}
allGraph
.
setSummaryContent
(
summarySb
.
toString
());
graphs
.
add
(
allGraph
);
return
graphs
;
}
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/task/event/EventMerger.java
浏览文件 @
a45a9bbc
...
...
@@ -45,15 +45,4 @@ public class EventMerger {
return
eventReport
;
}
public
EventReport
mergeForGraph
(
String
reportDomain
,
List
<
EventReport
>
reports
)
{
EventReport
eventReport
=
merge
(
reportDomain
,
reports
,
false
);
EventReportMerger
merger
=
new
EventReportMerger
(
new
EventReport
(
reportDomain
));
EventReport
eventReport2
=
merge
(
reportDomain
,
reports
,
false
);
Machine
allMachines
=
merger
.
mergesForAllMachine
(
eventReport2
);
eventReport
.
addMachine
(
allMachines
);
eventReport
.
getIps
().
add
(
"All"
);
return
eventReport
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/event/EventReportBuilder.java
浏览文件 @
a45a9bbc
...
...
@@ -82,16 +82,11 @@ public class EventReportBuilder implements ReportTaskBuilder {
}
private
List
<
Graph
>
buildHourlyGraphs
(
String
name
,
String
domain
,
Date
period
)
throws
DalException
{
List
<
EventReport
>
reports
=
new
ArrayList
<
EventReport
>();
long
startTime
=
period
.
getTime
();
EventReport
report
=
m_reportService
.
queryEventReport
(
domain
,
new
Date
(
startTime
),
new
Date
(
startTime
+
TimeUtil
.
ONE_HOUR
));
reports
.
add
(
report
);
EventReport
eventReport
=
m_eventMerger
.
mergeForGraph
(
domain
,
reports
);
return
m_eventGraphCreator
.
buildGraph
(
eventReport
);
return
m_eventGraphCreator
.
splitReportToGraphs
(
period
,
domain
,
EventAnalyzer
.
ID
,
report
);
}
@Override
...
...
@@ -100,6 +95,10 @@ public class EventReportBuilder implements ReportTaskBuilder {
List
<
Graph
>
graphs
=
buildHourlyGraphs
(
name
,
domain
,
period
);
if
(
graphs
!=
null
)
{
for
(
Graph
graph
:
graphs
)
{
if
(
graph
.
getIp
().
equalsIgnoreCase
(
"all"
))
{
System
.
out
.
println
(
graph
.
getSummaryContent
());
}
this
.
m_graphDao
.
insert
(
graph
);
}
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/heartbeat/HeartbeatGraphCreator.java
浏览文件 @
a45a9bbc
...
...
@@ -8,62 +8,120 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer
;
import
com.dianping.cat.consumer.heartbeat.model.entity.Disk
;
import
com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport
;
import
com.dianping.cat.consumer.heartbeat.model.entity.Machine
;
import
com.dianping.cat.consumer.heartbeat.model.entity.Period
;
import
com.dianping.cat.consumer.heartbeat.model.transform.BaseVisitor
;
import
com.dianping.cat.core.dal.Graph
;
import
com.dianping.cat.report.task.TaskHelper
;
import
com.dianping.cat.report.task.spi.GraphLine
;
public
class
HeartbeatGraphCreator
{
public
class
HeartbeatGraphCreator
{
private
List
<
Graph
>
m_graphs
=
new
ArrayList
<
Graph
>();
private
void
cacheHeartbeatColumn
(
Map
<
String
,
GraphLine
>
detailCache
,
int
minute
,
Number
value
,
String
key
)
{
GraphLine
detailLine
=
detailCache
.
get
(
key
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
detailLine
.
minuteNumbers
=
new
double
[
60
];
detailCache
.
put
(
key
,
detailLine
);
}
detailLine
.
minuteNumbers
[
minute
]
=
value
.
doubleValue
();
}
private
HeartbeatReport
m_report
;
public
List
<
Graph
>
splitReportToGraphs
(
Date
reportPeriod
,
String
domainName
,
String
reportName
,
HeartbeatReport
heartbeatReport
)
{
Set
<
String
>
ips
=
heartbeatReport
.
getIps
();
List
<
Graph
>
graphs
=
new
ArrayList
<
Graph
>(
ips
.
size
());
public
List
<
Graph
>
buildGraph
(
HeartbeatReport
report
)
{
m_report
=
report
;
new
HeartbeatReportVisitor
().
visitHeartbeatReport
(
report
);
return
m_graphs
;
}
for
(
String
ip
:
ips
)
{
Graph
graph
=
new
Graph
();
graph
.
setIp
(
ip
);
graph
.
setDomain
(
domainName
);
graph
.
setName
(
reportName
);
graph
.
setPeriod
(
reportPeriod
);
graph
.
setType
(
3
);
com
.
dianping
.
cat
.
consumer
.
heartbeat
.
model
.
entity
.
Machine
machine
=
heartbeatReport
.
getMachines
().
get
(
ip
);
private
class
HeartbeatReportVisitor
extends
BaseVisitor
{
if
(
machine
==
null
)
{
continue
;
}
List
<
Period
>
periods
=
machine
.
getPeriods
();
Map
<
String
,
GraphLine
>
detailCache
=
new
TreeMap
<
String
,
GraphLine
>();
private
int
m_currentMinute
;
for
(
Period
period
:
periods
)
{
int
minute
=
period
.
getMinute
();
private
Map
<
String
,
GraphLine
>
m_detailCache
=
new
TreeMap
<
String
,
GraphLine
>();
String
key
=
"CatMessageSize"
;
Number
value
=
period
.
getCatMessageSize
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
private
void
cacheHeartbeatColumn
(
String
key
,
Number
value
)
{
GraphLine
detailLine
=
m_detailCache
.
get
(
key
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
detailLine
.
minuteNumbers
=
new
double
[
60
];
m_detailCache
.
put
(
key
,
detailLine
);
}
detailLine
.
minuteNumbers
[
m_currentMinute
]
=
value
.
doubleValue
();
}
key
=
"CatMessageOverflow"
;
value
=
period
.
getCatMessageOverflow
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
private
Graph
buildGraph
(
String
ip
)
{
Graph
graph
=
new
Graph
();
graph
.
setIp
(
ip
);
graph
.
setDomain
(
m_report
.
getDomain
());
graph
.
setName
(
HeartbeatAnalyzer
.
ID
);
graph
.
setPeriod
(
m_report
.
getStartTime
());
graph
.
setType
(
3
);
graph
.
setCreationDate
(
new
Date
());
return
graph
;
}
key
=
"CatMessageProduced"
;
value
=
period
.
getCatMessageProduced
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
List
<
Disk
>
disks
=
period
.
getDisks
();
for
(
Disk
d
:
disks
)
{
key
=
"Disk "
+
d
.
getPath
();
value
=
d
.
getFree
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
}
key
=
"MemoryFree"
;
value
=
period
.
getMemoryFree
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"HeapUsage"
;
value
=
period
.
getHeapUsage
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"NoneHeapUsage"
;
value
=
period
.
getNoneHeapUsage
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"SystemLoadAverage"
;
value
=
period
.
getSystemLoadAverage
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"OldGcCount"
;
value
=
period
.
getOldGcCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"NewGcCount"
;
value
=
period
.
getNewGcCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"PigeonStartedThread"
;
value
=
period
.
getPigeonThreadCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"CatThreadCount"
;
value
=
period
.
getCatThreadCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"TotalStartedThread"
;
value
=
period
.
getTotalStartedCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"DaemonThread"
;
value
=
period
.
getDaemonCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"ActiveThread"
;
value
=
period
.
getThreadCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
key
=
"HttpThread"
;
value
=
period
.
getHttpThreadCount
();
cacheHeartbeatColumn
(
detailCache
,
minute
,
value
,
key
);
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
super
.
visitMachine
(
machine
);
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_detailCache
.
entrySet
())
{
for
(
Entry
<
String
,
GraphLine
>
entry
:
detailCache
.
entrySet
())
{
GraphLine
line
=
entry
.
getValue
();
double
[]
numbers
=
line
.
minuteNumbers
;
double
minValue
=
numbers
[
0
];
...
...
@@ -89,8 +147,8 @@ public class HeartbeatGraphCreator {
line
.
sum2
=
sum2
;
}
StringBuilder
sb
=
new
StringBuilder
(
64
*
m_
detailCache
.
size
());
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_
detailCache
.
entrySet
())
{
StringBuilder
sb
=
new
StringBuilder
(
64
*
detailCache
.
size
());
for
(
Entry
<
String
,
GraphLine
>
entry
:
detailCache
.
entrySet
())
{
GraphLine
value
=
entry
.
getValue
();
sb
.
append
(
entry
.
getKey
());
sb
.
append
(
'\t'
);
...
...
@@ -105,92 +163,11 @@ public class HeartbeatGraphCreator {
sb
.
append
(
TaskHelper
.
join
(
value
.
minuteNumbers
,
','
));
sb
.
append
(
'\n'
);
}
Graph
graph
=
buildGraph
(
machine
.
getIp
());
graph
.
setDetailContent
(
sb
.
toString
());
m_graphs
.
add
(
graph
);
}
@Override
public
void
visitHeartbeatReport
(
HeartbeatReport
heartbeatReport
)
{
super
.
visitHeartbeatReport
(
heartbeatReport
);
}
@Override
public
void
visitPeriod
(
Period
period
)
{
m_currentMinute
=
period
.
getMinute
();
String
key
=
"CatMessageSize"
;
Number
value
=
period
.
getCatMessageSize
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"CatMessageOverflow"
;
value
=
period
.
getCatMessageOverflow
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"CatMessageProduced"
;
value
=
period
.
getCatMessageProduced
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"MemoryFree"
;
value
=
period
.
getMemoryFree
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"HeapUsage"
;
value
=
period
.
getHeapUsage
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"NoneHeapUsage"
;
value
=
period
.
getNoneHeapUsage
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"SystemLoadAverage"
;
value
=
period
.
getSystemLoadAverage
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"OldGcCount"
;
value
=
period
.
getOldGcCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"NewGcCount"
;
value
=
period
.
getNewGcCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"PigeonStartedThread"
;
value
=
period
.
getPigeonThreadCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"CatThreadCount"
;
value
=
period
.
getCatThreadCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"TotalStartedThread"
;
value
=
period
.
getTotalStartedCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"DaemonThread"
;
value
=
period
.
getDaemonCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"ActiveThread"
;
value
=
period
.
getThreadCount
();
cacheHeartbeatColumn
(
key
,
value
);
key
=
"HttpThread"
;
value
=
period
.
getHttpThreadCount
();
cacheHeartbeatColumn
(
key
,
value
);
super
.
visitPeriod
(
period
);
}
@Override
public
void
visitDisk
(
Disk
disk
)
{
String
key
=
"Disk "
+
disk
.
getPath
();
Number
value
=
disk
.
getFree
();
cacheHeartbeatColumn
(
key
,
value
);
super
.
visitDisk
(
disk
);
graph
.
setDetailContent
(
sb
.
toString
());
graph
.
setCreationDate
(
new
Date
());
graphs
.
add
(
graph
);
}
return
graphs
;
}
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/task/heartbeat/HeartbeatReportBuilder.java
浏览文件 @
a45a9bbc
...
...
@@ -7,6 +7,7 @@ import org.unidal.dal.jdbc.DalException;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer
;
import
com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport
;
import
com.dianping.cat.core.dal.Graph
;
import
com.dianping.cat.core.dal.GraphDao
;
...
...
@@ -57,8 +58,9 @@ public class HeartbeatReportBuilder implements ReportTaskBuilder {
}
private
List
<
Graph
>
qeueryHourlyGraphs
(
String
name
,
String
domain
,
Date
period
)
throws
DalException
{
HeartbeatReport
heartbeatR
eport
=
m_reportService
.
queryHeartbeatReport
(
domain
,
period
,
new
Date
(
period
.
getTime
()
HeartbeatReport
r
eport
=
m_reportService
.
queryHeartbeatReport
(
domain
,
period
,
new
Date
(
period
.
getTime
()
+
TimeUtil
.
ONE_HOUR
));
return
m_heartbeatGraphCreator
.
buildGraph
(
heartbeatReport
);
return
m_heartbeatGraphCreator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
HeartbeatAnalyzer
.
ID
,
report
);
}
}
cat-home/src/main/java/com/dianping/cat/report/task/problem/ProblemGraphCreator.java
浏览文件 @
a45a9bbc
...
...
@@ -8,72 +8,93 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer
;
import
com.dianping.cat.consumer.problem.model.entity.JavaThread
;
import
com.dianping.cat.consumer.problem.model.entity.Machine
;
import
com.dianping.cat.consumer.problem.model.entity.ProblemReport
;
import
com.dianping.cat.consumer.problem.model.entity.Segment
;
import
com.dianping.cat.consumer.problem.model.transform.BaseVisitor
;
import
com.dianping.cat.core.dal.Graph
;
import
com.dianping.cat.report.task.TaskHelper
;
import
com.dianping.cat.report.task.spi.GraphLine
;
public
class
ProblemGraphCreator
{
public
class
ProblemGraphCreator
{
private
List
<
Graph
>
m_graphs
=
new
ArrayList
<
Graph
>();
public
List
<
Graph
>
splitReportToGraphs
(
Date
reportPeriod
,
String
reportDomain
,
String
reportName
,
ProblemReport
report
)
{
Set
<
String
>
ips
=
report
.
getIps
();
List
<
Graph
>
graphs
=
new
ArrayList
<
Graph
>(
ips
.
size
()
+
1
);
private
ProblemReport
m_report
;
Map
<
String
,
GraphLine
>
allDetailCache
=
new
TreeMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
allSummaryCache
=
new
TreeMap
<
String
,
GraphLine
>();
public
List
<
Graph
>
buildGraph
(
ProblemReport
report
)
{
m_report
=
report
;
new
ProblemReportVisitor
().
visitProblemReport
(
report
);
return
m_graphs
;
}
public
class
ProblemReportVisitor
extends
BaseVisitor
{
private
Map
<
String
,
GraphLine
>
m_allDetailCache
=
new
TreeMap
<
String
,
GraphLine
>();
private
Map
<
String
,
GraphLine
>
m_allSummaryCache
=
new
TreeMap
<
String
,
GraphLine
>();
private
Map
<
String
,
GraphLine
>
m_detailCache
;
private
Map
<
String
,
GraphLine
>
m_summaryCache
;
private
String
m_status
;
private
String
m_type
;
private
Graph
buildGraph
(
String
ip
)
{
for
(
String
ip
:
ips
)
{
Map
<
String
,
GraphLine
>
detailCache
=
new
TreeMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
summaryCache
=
new
TreeMap
<
String
,
GraphLine
>();
Graph
graph
=
new
Graph
();
graph
.
setIp
(
ip
);
graph
.
setDomain
(
m_report
.
getDomain
()
);
graph
.
setName
(
HeartbeatAnalyzer
.
ID
);
graph
.
setPeriod
(
m_report
.
getStartTime
()
);
graph
.
setDomain
(
reportDomain
);
graph
.
setName
(
reportName
);
graph
.
setPeriod
(
reportPeriod
);
graph
.
setType
(
3
);
graph
.
setCreationDate
(
new
Date
());
return
graph
;
}
@Override
public
void
visitEntry
(
com
.
dianping
.
cat
.
consumer
.
problem
.
model
.
entity
.
Entry
entry
)
{
m_type
=
entry
.
getType
();
m_status
=
entry
.
getStatus
();
super
.
visitEntry
(
entry
);
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
m_detailCache
=
new
TreeMap
<
String
,
GraphLine
>();
m_summaryCache
=
new
TreeMap
<
String
,
GraphLine
>();
super
.
visitMachine
(
machine
);
com
.
dianping
.
cat
.
consumer
.
problem
.
model
.
entity
.
Machine
machine
=
report
.
findOrCreateMachine
(
ip
);
for
(
com
.
dianping
.
cat
.
consumer
.
problem
.
model
.
entity
.
Entry
entry
:
machine
.
getEntries
())
{
Map
<
String
,
JavaThread
>
threads
=
entry
.
getThreads
();
String
type
=
entry
.
getType
();
String
status
=
entry
.
getStatus
();
for
(
Entry
<
String
,
JavaThread
>
problemEntry
:
threads
.
entrySet
())
{
JavaThread
thread
=
problemEntry
.
getValue
();
for
(
Entry
<
Integer
,
Segment
>
segmentEntry
:
thread
.
getSegments
().
entrySet
())
{
Segment
segment
=
segmentEntry
.
getValue
();
int
minute
=
segment
.
getId
();
int
count
=
segment
.
getMessages
().
size
();
String
summaryKey
=
type
;
GraphLine
summaryLine
=
summaryCache
.
get
(
summaryKey
);
if
(
summaryLine
==
null
)
{
summaryLine
=
new
GraphLine
();
summaryLine
.
minuteCounts
=
new
int
[
60
];
summaryCache
.
put
(
summaryKey
,
summaryLine
);
}
summaryLine
.
totalCount
=
summaryLine
.
totalCount
+
count
;
summaryLine
.
minuteCounts
[
minute
]
=
summaryLine
.
minuteCounts
[
minute
]
+
count
;
GraphLine
allSummaryLine
=
allSummaryCache
.
get
(
summaryKey
);
if
(
allSummaryLine
==
null
)
{
allSummaryLine
=
new
GraphLine
();
allSummaryLine
.
minuteCounts
=
new
int
[
60
];
allSummaryCache
.
put
(
summaryKey
,
allSummaryLine
);
}
allSummaryLine
.
totalCount
=
allSummaryLine
.
totalCount
+
count
;
allSummaryLine
.
minuteCounts
[
minute
]
=
allSummaryLine
.
minuteCounts
[
minute
]
+
count
;
String
detailKey
=
type
+
"\t"
+
status
;
GraphLine
detailLine
=
detailCache
.
get
(
detailKey
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
detailLine
.
minuteCounts
=
new
int
[
60
];
detailCache
.
put
(
detailKey
,
detailLine
);
}
detailLine
.
totalCount
=
detailLine
.
totalCount
+
count
;
detailLine
.
minuteCounts
[
minute
]
=
detailLine
.
minuteCounts
[
minute
]
+
count
;
GraphLine
allDetailLine
=
allDetailCache
.
get
(
detailKey
);
if
(
allDetailLine
==
null
)
{
allDetailLine
=
new
GraphLine
();
allDetailLine
.
minuteCounts
=
new
int
[
60
];
allDetailCache
.
put
(
detailKey
,
allDetailLine
);
}
allDetailLine
.
totalCount
=
allDetailLine
.
totalCount
+
count
;
allDetailLine
.
minuteCounts
[
minute
]
=
allDetailLine
.
minuteCounts
[
minute
]
+
count
;
}
}
}
Graph
graph
=
buildGraph
(
machine
.
getIp
());
StringBuilder
summaryBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
summaryEntry
:
m_summaryCache
.
entrySet
())
{
for
(
Entry
<
String
,
GraphLine
>
summaryEntry
:
summaryCache
.
entrySet
())
{
GraphLine
summaryLine
=
summaryEntry
.
getValue
();
summaryBuilder
.
append
(
summaryEntry
.
getKey
());
summaryBuilder
.
append
(
"\t"
);
...
...
@@ -83,10 +104,9 @@ public class ProblemGraphCreator {
summaryBuilder
.
append
(
"\n"
);
}
graph
.
setSummaryContent
(
summaryBuilder
.
toString
());
StringBuilder
detailBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
detailEntry
:
m_detailCache
.
entrySet
())
{
for
(
Entry
<
String
,
GraphLine
>
detailEntry
:
detailCache
.
entrySet
())
{
GraphLine
detailLine
=
detailEntry
.
getValue
();
detailBuilder
.
append
(
detailEntry
.
getKey
());
detailBuilder
.
append
(
"\t"
);
...
...
@@ -96,95 +116,44 @@ public class ProblemGraphCreator {
detailBuilder
.
append
(
"\n"
);
}
graph
.
setDetailContent
(
detailBuilder
.
toString
());
graph
.
setCreationDate
(
new
Date
());
m_
graphs
.
add
(
graph
);
graphs
.
add
(
graph
);
}
@Override
public
void
visitProblemReport
(
ProblemReport
problemReport
)
{
super
.
visitProblemReport
(
problemReport
);
Graph
allGraph
=
buildGraph
(
"all"
);
StringBuilder
summaryBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
summaryEntry
:
m_allSummaryCache
.
entrySet
())
{
GraphLine
summaryLine
=
summaryEntry
.
getValue
();
summaryBuilder
.
append
(
summaryEntry
.
getKey
());
summaryBuilder
.
append
(
"\t"
);
summaryBuilder
.
append
(
summaryLine
.
totalCount
);
summaryBuilder
.
append
(
"\t"
);
summaryBuilder
.
append
(
TaskHelper
.
join
(
summaryLine
.
minuteCounts
,
','
));
summaryBuilder
.
append
(
"\n"
);
}
allGraph
.
setSummaryContent
(
summaryBuilder
.
toString
());
StringBuilder
detailBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
detailEntry
:
m_allDetailCache
.
entrySet
())
{
GraphLine
detailLine
=
detailEntry
.
getValue
();
detailBuilder
.
append
(
detailEntry
.
getKey
());
detailBuilder
.
append
(
"\t"
);
detailBuilder
.
append
(
detailLine
.
totalCount
);
detailBuilder
.
append
(
"\t"
);
detailBuilder
.
append
(
TaskHelper
.
join
(
detailLine
.
minuteCounts
,
','
));
detailBuilder
.
append
(
"\n"
);
}
allGraph
.
setDetailContent
(
detailBuilder
.
toString
());
allGraph
.
setCreationDate
(
new
Date
());
m_graphs
.
add
(
allGraph
);
Graph
allGraph
=
new
Graph
();
allGraph
.
setIp
(
"all"
);
allGraph
.
setDomain
(
reportDomain
);
allGraph
.
setName
(
reportName
);
allGraph
.
setPeriod
(
reportPeriod
);
allGraph
.
setType
(
3
);
StringBuilder
summaryBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
summaryEntry
:
allSummaryCache
.
entrySet
())
{
GraphLine
summaryLine
=
summaryEntry
.
getValue
();
summaryBuilder
.
append
(
summaryEntry
.
getKey
());
summaryBuilder
.
append
(
"\t"
);
summaryBuilder
.
append
(
summaryLine
.
totalCount
);
summaryBuilder
.
append
(
"\t"
);
summaryBuilder
.
append
(
TaskHelper
.
join
(
summaryLine
.
minuteCounts
,
','
));
summaryBuilder
.
append
(
"\n"
);
}
@Override
public
void
visitSegment
(
Segment
segment
)
{
int
minute
=
segment
.
getId
();
int
count
=
segment
.
getMessages
().
size
();
String
summaryKey
=
m_type
;
GraphLine
summaryLine
=
m_summaryCache
.
get
(
summaryKey
);
if
(
summaryLine
==
null
)
{
summaryLine
=
new
GraphLine
();
summaryLine
.
minuteCounts
=
new
int
[
60
];
m_summaryCache
.
put
(
summaryKey
,
summaryLine
);
}
summaryLine
.
totalCount
=
summaryLine
.
totalCount
+
count
;
summaryLine
.
minuteCounts
[
minute
]
=
summaryLine
.
minuteCounts
[
minute
]
+
count
;
GraphLine
allSummaryLine
=
m_allSummaryCache
.
get
(
summaryKey
);
if
(
allSummaryLine
==
null
)
{
allSummaryLine
=
new
GraphLine
();
allSummaryLine
.
minuteCounts
=
new
int
[
60
];
m_allSummaryCache
.
put
(
summaryKey
,
allSummaryLine
);
}
allSummaryLine
.
totalCount
=
allSummaryLine
.
totalCount
+
count
;
allSummaryLine
.
minuteCounts
[
minute
]
=
allSummaryLine
.
minuteCounts
[
minute
]
+
count
;
String
detailKey
=
m_type
+
"\t"
+
m_status
;
GraphLine
detailLine
=
m_detailCache
.
get
(
detailKey
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
detailLine
.
minuteCounts
=
new
int
[
60
];
m_detailCache
.
put
(
detailKey
,
detailLine
);
}
detailLine
.
totalCount
=
detailLine
.
totalCount
+
count
;
detailLine
.
minuteCounts
[
minute
]
=
detailLine
.
minuteCounts
[
minute
]
+
count
;
GraphLine
allDetailLine
=
m_allDetailCache
.
get
(
detailKey
);
if
(
allDetailLine
==
null
)
{
allDetailLine
=
new
GraphLine
();
allDetailLine
.
minuteCounts
=
new
int
[
60
];
m_allDetailCache
.
put
(
detailKey
,
allDetailLine
);
}
allDetailLine
.
totalCount
=
allDetailLine
.
totalCount
+
count
;
allDetailLine
.
minuteCounts
[
minute
]
=
allDetailLine
.
minuteCounts
[
minute
]
+
count
;
super
.
visitSegment
(
segment
);
allGraph
.
setSummaryContent
(
summaryBuilder
.
toString
());
StringBuilder
detailBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
detailEntry
:
allDetailCache
.
entrySet
())
{
GraphLine
detailLine
=
detailEntry
.
getValue
();
detailBuilder
.
append
(
detailEntry
.
getKey
());
detailBuilder
.
append
(
"\t"
);
detailBuilder
.
append
(
detailLine
.
totalCount
);
detailBuilder
.
append
(
"\t"
);
detailBuilder
.
append
(
TaskHelper
.
join
(
detailLine
.
minuteCounts
,
','
));
detailBuilder
.
append
(
"\n"
);
}
allGraph
.
setDetailContent
(
detailBuilder
.
toString
());
allGraph
.
setCreationDate
(
new
Date
());
@Override
public
void
visitThread
(
JavaThread
thread
)
{
super
.
visitThread
(
thread
);
}
graphs
.
add
(
allGraph
);
return
graphs
;
}
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/task/problem/ProblemReportBuilder.java
浏览文件 @
a45a9bbc
...
...
@@ -68,21 +68,18 @@ public class ProblemReportBuilder implements ReportTaskBuilder {
}
private
List
<
Graph
>
buildHourlyGraphs
(
String
name
,
String
domain
,
Date
period
)
throws
DalException
{
List
<
ProblemReport
>
reports
=
new
ArrayList
<
ProblemReport
>();
long
startTime
=
period
.
getTime
();
ProblemReport
report
=
m_reportService
.
queryProblemReport
(
domain
,
new
Date
(
startTime
),
new
Date
(
startTime
+
TimeUtil
.
ONE_HOUR
));
reports
.
add
(
report
);
ProblemReport
problemReport
=
m_problemMerger
.
mergeForGraph
(
domain
,
reports
);
return
m_problemGraphCreator
.
buildGraph
(
problemReport
);
return
m_problemGraphCreator
.
splitReportToGraphs
(
period
,
domain
,
ProblemAnalyzer
.
ID
,
report
);
}
@Override
public
boolean
buildHourlyTask
(
String
name
,
String
domain
,
Date
period
)
{
try
{
List
<
Graph
>
graphs
=
buildHourlyGraphs
(
name
,
domain
,
period
);
if
(
graphs
!=
null
)
{
for
(
Graph
graph
:
graphs
)
{
this
.
m_graphDao
.
insert
(
graph
);
// use mysql unique index and
...
...
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionGraphCreator.java
浏览文件 @
a45a9bbc
...
...
@@ -5,234 +5,250 @@ package com.dianping.cat.report.task.transaction;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.
Linked
HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
com.dianping.cat.consumer.transaction.TransactionAnalyzer
;
import
com.dianping.cat.consumer.transaction.model.entity.Machine
;
import
com.dianping.cat.consumer.transaction.model.entity.Range
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionName
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionReport
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionType
;
import
com.dianping.cat.consumer.transaction.model.transform.BaseVisitor
;
import
com.dianping.cat.core.dal.Graph
;
import
com.dianping.cat.report.task.spi.GraphLine
;
public
class
TransactionGraphCreator
{
private
List
<
Graph
>
m_graphs
=
new
ArrayList
<
Graph
>();
private
TransactionReport
m_report
;
public
List
<
Graph
>
buildGraph
(
TransactionReport
report
)
{
m_report
=
report
;
new
TransactionReportVisitor
().
visitTransactionReport
(
report
)
;
return
m_graphs
;
private
double
[]
arrayAdd
(
double
[]
src
,
double
added
[])
{
int
size
=
added
.
length
;
if
(
src
==
null
)
{
src
=
new
double
[
size
];
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
src
[
i
]
=
src
[
i
]
+
added
[
i
]
;
}
return
src
;
}
public
class
TransactionReportVisitor
extends
BaseVisitor
{
String
m_currentIp
;
String
m_currentType
;
int
m_currentIndex
;
GraphLine
m_currentDetail
;
GraphLine
m_currentSummary
;
GraphLine
m_allDetail
;
GraphLine
m_allSummary
;
Map
<
String
,
GraphLine
>
m_allDetails
=
new
HashMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
m_allSummaries
=
new
HashMap
<
String
,
GraphLine
>();
StringBuilder
m_summaryContent
;
StringBuilder
m_detailContent
;
StringBuilder
m_allSummaryContent
;
StringBuilder
m_allDetailContent
;
private
void
addRange
(
GraphLine
graphLine
,
int
index
,
Range
range
)
{
graphLine
.
totalCounts
[
index
]
+=
range
.
getCount
();
graphLine
.
failCounts
[
index
]
+=
range
.
getFails
();
graphLine
.
sums
[
index
]
+=
range
.
getSum
();
private
long
[]
arrayAdd
(
long
[]
src
,
long
added
[])
{
int
size
=
added
.
length
;
if
(
src
==
null
)
{
src
=
new
long
[
size
];
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
src
[
i
]
=
src
[
i
]
+
added
[
i
];
}
return
src
;
}
private
String
arrayToString
(
double
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
12
)
{
sb
.
append
(
','
);
}
private
String
arrayToString
(
double
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
12
)
{
sb
.
append
(
','
);
}
return
sb
.
toString
();
}
return
sb
.
toString
();
}
private
String
arrayToString
(
long
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
11
)
{
sb
.
append
(
','
);
}
private
String
arrayToString
(
long
[]
array
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
size
=
12
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
sb
.
append
(
array
[
i
]);
if
(
i
<
11
)
{
sb
.
append
(
','
);
}
return
sb
.
toString
();
}
return
sb
.
toString
();
}
private
void
buildContent
(
StringBuilder
content
,
String
key
,
GraphLine
graphLine
)
{
content
.
append
(
key
).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\t'
);
content
.
append
(
graphLine
.
min
).
append
(
'\t'
);
content
.
append
(
graphLine
.
max
).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
sums
)).
append
(
'\t'
);
content
.
append
(
graphLine
.
sum2
).
append
(
'\t'
).
append
(
'\n'
);
private
long
[]
getFailsCount
(
List
<
Range
>
ranges
)
{
long
[]
value
=
new
long
[
12
];
for
(
Range
range
:
ranges
)
{
int
minute
=
range
.
getValue
();
value
[
minute
/
5
]
=
range
.
getFails
();
}
return
value
;
}
private
void
buildContent
(
StringBuilder
content
,
String
type
,
TransactionName
name
,
GraphLine
graphLine
)
{
content
.
append
(
type
).
append
(
'\t'
);
content
.
append
(
name
.
getId
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\t'
);
content
.
append
(
name
.
getMin
()).
append
(
'\t'
);
content
.
append
(
name
.
getMax
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
sums
)).
append
(
'\t'
);
content
.
append
(
name
.
getSum2
()).
append
(
'\t'
).
append
(
'\n'
);
private
double
[]
getSumCount
(
List
<
Range
>
ranges
)
{
double
[]
value
=
new
double
[
12
];
for
(
Range
range
:
ranges
)
{
int
minute
=
range
.
getValue
();
value
[
minute
/
5
]
=
range
.
getSum
();
}
return
value
;
}
private
void
buildContent
(
StringBuilder
content
,
TransactionType
type
,
GraphLine
graphLine
)
{
content
.
append
(
type
.
getId
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
totalCounts
)).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
failCounts
)).
append
(
'\t'
);
content
.
append
(
type
.
getMin
()).
append
(
'\t'
);
content
.
append
(
type
.
getMax
()).
append
(
'\t'
);
content
.
append
(
arrayToString
(
graphLine
.
sums
)).
append
(
'\t'
);
content
.
append
(
type
.
getSum2
()).
append
(
'\t'
).
append
(
'\n'
);
private
long
[]
getTotalCount
(
List
<
Range
>
ranges
)
{
long
[]
value
=
new
long
[
12
];
for
(
Range
range
:
ranges
)
{
int
minute
=
range
.
getValue
();
value
[
minute
/
5
]
=
range
.
getCount
();
}
return
value
;
}
private
Graph
buildGraph
(
String
ip
)
{
public
List
<
Graph
>
splitReportToGraphs
(
Date
reportPeriod
,
String
reportDomain
,
String
reportName
,
TransactionReport
report
)
{
Set
<
String
>
ips
=
report
.
getIps
();
// all and every minute
List
<
Graph
>
graphs
=
new
ArrayList
<
Graph
>(
ips
.
size
()
+
1
);
Map
<
String
,
GraphLine
>
allDetailCache
=
new
LinkedHashMap
<
String
,
GraphLine
>();
Map
<
String
,
GraphLine
>
allSummaryCache
=
new
LinkedHashMap
<
String
,
GraphLine
>();
Date
creationDate
=
new
Date
();
for
(
String
ip
:
ips
)
{
Graph
graph
=
new
Graph
();
graph
.
setIp
(
ip
);
graph
.
setDomain
(
m_report
.
getDomain
()
);
graph
.
setName
(
TransactionAnalyzer
.
ID
);
graph
.
setPeriod
(
m_report
.
getStartTime
()
);
graph
.
setDomain
(
reportDomain
);
graph
.
setName
(
reportName
);
graph
.
setPeriod
(
reportPeriod
);
graph
.
setType
(
3
);
graph
.
setCreationDate
(
new
Date
());
return
graph
;
}
private
void
buildGraphLine
(
GraphLine
graphLine
,
TransactionName
name
,
boolean
isNew
)
{
if
(
isNew
)
{
graphLine
.
totalCounts
=
new
long
[
12
];
graphLine
.
failCounts
=
new
long
[
12
];
graphLine
.
sums
=
new
double
[
12
];
}
graphLine
.
min
+=
name
.
getMin
();
graphLine
.
max
+=
name
.
getMax
();
graphLine
.
sum2
+=
name
.
getSum2
();
}
private
void
buildGraphLine
(
GraphLine
graphLine
,
TransactionType
type
,
boolean
isNew
)
{
if
(
isNew
)
{
graphLine
.
totalCounts
=
new
long
[
12
];
graphLine
.
failCounts
=
new
long
[
12
];
graphLine
.
sums
=
new
double
[
12
];
}
graphLine
.
min
+=
type
.
getMin
();
graphLine
.
max
+=
type
.
getMax
();
graphLine
.
sum2
+=
type
.
getSum2
();
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
m_currentIp
=
machine
.
getIp
();
Graph
graph
=
buildGraph
(
m_currentIp
);
m_graphs
.
add
(
graph
);
m_summaryContent
=
new
StringBuilder
();
m_detailContent
=
new
StringBuilder
();
super
.
visitMachine
(
machine
);
graph
.
setDetailContent
(
m_detailContent
.
toString
());
graph
.
setSummaryContent
(
m_summaryContent
.
toString
());
}
graph
.
setCreationDate
(
creationDate
);
Machine
machine
=
report
.
findOrCreateMachine
(
ip
);
Map
<
String
,
TransactionType
>
types
=
machine
.
getTypes
();
StringBuilder
detailBuilder
=
new
StringBuilder
();
StringBuilder
summaryBuilder
=
new
StringBuilder
();
for
(
Entry
<
String
,
TransactionType
>
transactionEntry
:
types
.
entrySet
())
{
TransactionType
transactionType
=
transactionEntry
.
getValue
();
long
[]
typeCounts
=
new
long
[
12
];
long
[]
typeFails
=
new
long
[
12
];
double
[]
typeSums
=
new
double
[
12
];
Map
<
String
,
TransactionName
>
names
=
transactionType
.
getNames
();
for
(
Entry
<
String
,
TransactionName
>
nameEntry
:
names
.
entrySet
())
{
TransactionName
transactionName
=
nameEntry
.
getValue
();
List
<
Range
>
ranges
=
new
ArrayList
<
Range
>(
transactionName
.
getRanges
().
values
());
detailBuilder
.
append
(
transactionType
.
getId
());
detailBuilder
.
append
(
'\t'
);
detailBuilder
.
append
(
transactionName
.
getId
());
detailBuilder
.
append
(
'\t'
);
long
[]
totalCount
=
getTotalCount
(
ranges
);
detailBuilder
.
append
(
arrayToString
(
totalCount
));
detailBuilder
.
append
(
'\t'
);
long
[]
failsCount
=
getFailsCount
(
ranges
);
detailBuilder
.
append
(
arrayToString
(
failsCount
));
detailBuilder
.
append
(
'\t'
);
detailBuilder
.
append
(
transactionName
.
getMin
());
detailBuilder
.
append
(
'\t'
);
detailBuilder
.
append
(
transactionName
.
getMax
());
detailBuilder
.
append
(
'\t'
);
double
[]
sumCount
=
getSumCount
(
ranges
);
detailBuilder
.
append
(
arrayToString
(
sumCount
));
detailBuilder
.
append
(
'\t'
);
detailBuilder
.
append
(
transactionName
.
getSum2
());
detailBuilder
.
append
(
'\n'
);
String
key
=
transactionType
.
getId
()
+
"\t"
+
transactionName
.
getId
();
GraphLine
detailLine
=
allDetailCache
.
get
(
key
);
if
(
detailLine
==
null
)
{
detailLine
=
new
GraphLine
();
allDetailCache
.
put
(
key
,
detailLine
);
}
detailLine
.
totalCounts
=
arrayAdd
(
detailLine
.
totalCounts
,
totalCount
);
detailLine
.
failCounts
=
arrayAdd
(
detailLine
.
failCounts
,
failsCount
);
detailLine
.
min
+=
transactionName
.
getMin
();
detailLine
.
max
+=
transactionName
.
getMax
();
detailLine
.
sums
=
arrayAdd
(
detailLine
.
sums
,
sumCount
);
detailLine
.
sum2
+=
transactionName
.
getSum2
();
typeCounts
=
arrayAdd
(
typeCounts
,
totalCount
);
typeFails
=
arrayAdd
(
typeFails
,
failsCount
);
typeSums
=
arrayAdd
(
typeSums
,
sumCount
);
}
summaryBuilder
.
append
(
transactionType
.
getId
());
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
arrayToString
(
typeCounts
));
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
arrayToString
(
typeFails
));
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
transactionType
.
getMin
());
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
transactionType
.
getMax
());
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
arrayToString
(
typeSums
));
summaryBuilder
.
append
(
'\t'
);
summaryBuilder
.
append
(
transactionType
.
getSum2
());
summaryBuilder
.
append
(
'\n'
);
String
summaryKey
=
transactionType
.
getId
();
GraphLine
summaryLine
=
allSummaryCache
.
get
(
summaryKey
);
if
(
summaryLine
==
null
)
{
summaryLine
=
new
GraphLine
();
allSummaryCache
.
put
(
summaryKey
,
summaryLine
);
}
@Override
public
void
visitName
(
TransactionName
name
)
{
String
key
=
m_currentType
+
"\t"
+
name
.
getId
();
m_allDetail
=
m_allDetails
.
get
(
key
);
if
(
m_allDetail
==
null
)
{
m_allDetail
=
new
GraphLine
();
m_allDetails
.
put
(
key
,
m_allDetail
);
buildGraphLine
(
m_allDetail
,
name
,
true
);
}
else
{
buildGraphLine
(
m_allDetail
,
name
,
false
);
summaryLine
.
totalCounts
=
arrayAdd
(
summaryLine
.
totalCounts
,
typeCounts
);
summaryLine
.
failCounts
=
arrayAdd
(
summaryLine
.
failCounts
,
typeFails
);
summaryLine
.
min
+=
transactionType
.
getMin
();
summaryLine
.
max
+=
transactionType
.
getMax
();
summaryLine
.
sums
=
arrayAdd
(
summaryLine
.
sums
,
typeSums
);
summaryLine
.
sum2
+=
transactionType
.
getSum2
();
}
m_currentDetail
=
new
GraphLine
();
buildGraphLine
(
m_currentDetail
,
name
,
true
);
m_currentIndex
=
0
;
super
.
visitName
(
name
);
buildContent
(
m_detailContent
,
m_currentType
,
name
,
m_currentDetail
);
graph
.
setDetailContent
(
detailBuilder
.
toString
());
graph
.
setSummaryContent
(
summaryBuilder
.
toString
());
graphs
.
add
(
graph
);
}
@Override
public
void
visitRange
(
Range
range
)
{
addRange
(
m_currentDetail
,
m_currentIndex
,
range
);
addRange
(
m_currentSummary
,
m_currentIndex
,
range
);
addRange
(
m_allDetail
,
m_currentIndex
,
range
);
addRange
(
m_allSummary
,
m_currentIndex
,
range
);
m_currentIndex
++;
Graph
allGraph
=
new
Graph
();
allGraph
.
setIp
(
"all"
);
allGraph
.
setDomain
(
reportDomain
);
allGraph
.
setName
(
reportName
);
allGraph
.
setPeriod
(
reportPeriod
);
allGraph
.
setType
(
3
);
allGraph
.
setCreationDate
(
creationDate
);
StringBuilder
detailSb
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
entry
:
allDetailCache
.
entrySet
())
{
detailSb
.
append
(
entry
.
getKey
());
detailSb
.
append
(
'\t'
);
GraphLine
value
=
entry
.
getValue
();
detailSb
.
append
(
arrayToString
(
value
.
totalCounts
));
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
arrayToString
(
value
.
failCounts
));
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
value
.
min
);
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
value
.
max
);
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
arrayToString
(
value
.
sums
));
detailSb
.
append
(
'\t'
);
detailSb
.
append
(
value
.
sum2
);
detailSb
.
append
(
'\n'
);
}
@Override
public
void
visitTransactionReport
(
TransactionReport
transactionReport
)
{
Graph
allGraph
=
buildGraph
(
"all"
);
m_graphs
.
add
(
allGraph
);
m_allDetailContent
=
new
StringBuilder
();
m_allSummaryContent
=
new
StringBuilder
();
super
.
visitTransactionReport
(
transactionReport
);
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_allDetails
.
entrySet
())
{
buildContent
(
m_allDetailContent
,
entry
.
getKey
(),
entry
.
getValue
());
}
for
(
Entry
<
String
,
GraphLine
>
entry
:
m_allSummaries
.
entrySet
())
{
buildContent
(
m_allSummaryContent
,
entry
.
getKey
(),
entry
.
getValue
());
}
allGraph
.
setDetailContent
(
m_allDetailContent
.
toString
());
allGraph
.
setSummaryContent
(
m_allSummaryContent
.
toString
());
allGraph
.
setDetailContent
(
detailSb
.
toString
());
StringBuilder
summarySb
=
new
StringBuilder
();
for
(
Entry
<
String
,
GraphLine
>
entry
:
allSummaryCache
.
entrySet
())
{
summarySb
.
append
(
entry
.
getKey
());
summarySb
.
append
(
'\t'
);
GraphLine
value
=
entry
.
getValue
();
summarySb
.
append
(
arrayToString
(
value
.
totalCounts
));
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
arrayToString
(
value
.
failCounts
));
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
value
.
min
);
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
value
.
max
);
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
arrayToString
(
value
.
sums
));
summarySb
.
append
(
'\t'
);
summarySb
.
append
(
value
.
sum2
);
summarySb
.
append
(
'\n'
);
}
allGraph
.
setSummaryContent
(
summarySb
.
toString
());
@Override
public
void
visitType
(
TransactionType
type
)
{
// TYPE, TOTAL_COUNT, FAILURE_COUNT, MIN, MAX, SUM, SUM2
m_currentType
=
type
.
getId
();
String
key
=
m_currentType
;
m_allSummary
=
m_allSummaries
.
get
(
key
);
if
(
m_allSummary
==
null
)
{
m_allSummary
=
new
GraphLine
();
m_allSummaries
.
put
(
key
,
m_allSummary
);
buildGraphLine
(
m_allSummary
,
type
,
true
);
}
else
{
buildGraphLine
(
m_allSummary
,
type
,
false
);
}
m_currentSummary
=
new
GraphLine
();
buildGraphLine
(
m_currentSummary
,
type
,
true
);
super
.
visitType
(
type
);
graphs
.
add
(
allGraph
);
buildContent
(
m_summaryContent
,
type
,
m_currentSummary
);
}
return
graphs
;
}
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionMerger.java
浏览文件 @
a45a9bbc
...
...
@@ -47,15 +47,4 @@ public class TransactionMerger {
return
transactionReport
;
}
public
TransactionReport
mergeForGraph
(
String
reportDomain
,
List
<
TransactionReport
>
reports
)
{
TransactionReport
transactionReport
=
merge
(
reportDomain
,
reports
,
false
);
TransactionReportMerger
merger
=
new
TransactionReportMerger
(
new
TransactionReport
(
reportDomain
));
TransactionReport
all
=
merge
(
reportDomain
,
reports
,
false
);
com
.
dianping
.
cat
.
consumer
.
transaction
.
model
.
entity
.
Machine
allMachines
=
merger
.
mergesForAllMachine
(
all
);
transactionReport
.
addMachine
(
allMachines
);
transactionReport
.
getIps
().
add
(
"All"
);
new
TransactionReportUrlFilter
().
visitTransactionReport
(
transactionReport
);
return
transactionReport
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/transaction/TransactionReportBuilder.java
浏览文件 @
a45a9bbc
...
...
@@ -88,14 +88,11 @@ public class TransactionReportBuilder implements ReportTaskBuilder, LogEnabled {
}
private
List
<
Graph
>
buildHourlyGraphs
(
String
name
,
String
domain
,
Date
period
)
throws
DalException
{
List
<
TransactionReport
>
reports
=
new
ArrayList
<
TransactionReport
>();
long
startTime
=
period
.
getTime
();
TransactionReport
report
=
m_reportService
.
queryTransactionReport
(
domain
,
new
Date
(
startTime
),
new
Date
(
startTime
+
TimeUtil
.
ONE_HOUR
));
reports
.
add
(
report
);
TransactionReport
transactionReport
=
m_transactionMerger
.
mergeForGraph
(
domain
,
reports
);
return
m_transactionGraphCreator
.
buildGraph
(
transactionReport
);
return
m_transactionGraphCreator
.
splitReportToGraphs
(
period
,
domain
,
TransactionAnalyzer
.
ID
,
report
);
}
@Override
...
...
@@ -104,7 +101,7 @@ public class TransactionReportBuilder implements ReportTaskBuilder, LogEnabled {
List
<
Graph
>
graphs
=
buildHourlyGraphs
(
name
,
domain
,
period
);
if
(
graphs
!=
null
)
{
for
(
Graph
graph
:
graphs
)
{
m_graphDao
.
insert
(
graph
);
// use mysql unique index and insert
m_graphDao
.
insert
(
graph
);
}
}
}
catch
(
Exception
e
)
{
...
...
cat-home/src/main/webapp/jsp/report/event/eventHistoryGraphs.jsp
浏览文件 @
a45a9bbc
...
...
@@ -8,7 +8,6 @@
<script
type=
"text/javascript"
src=
"/cat/js/jquery-1.7.1.js"
></script>
<script
type=
"text/javascript"
src=
"/cat/js/highcharts.js"
></script>
<script
type=
"text/javascript"
src=
"/cat/js/baseGraph.js"
></script>
<script
type=
"text/javascript"
src=
"/cat/js/jquery-1.7.1.js"
></script>
<style
type=
"text/css"
>
.graph
{
width
:
550px
;
...
...
cat-home/src/test/java/com/dianping/cat/report/page/heartbeat/HeartbeatGraphDataTest.java
浏览文件 @
a45a9bbc
...
...
@@ -80,7 +80,7 @@ public class HeartbeatGraphDataTest extends ComponentTestCase {
String
xml
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"heartbeat.xml"
),
"utf-8"
);
HeartbeatReport
report
=
DefaultSaxParser
.
parse
(
xml
);
HeartbeatGraphCreator
creator
=
new
HeartbeatGraphCreator
();
List
<
Graph
>
graphs
=
creator
.
buildGraph
(
report
);
List
<
Graph
>
graphs
=
creator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
"heartbeat"
,
report
);
String
result
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"result"
),
"utf-8"
);
Assert
.
assertEquals
(
result
,
graphs
.
get
(
0
).
getDetailContent
());
...
...
cat-home/src/test/java/com/dianping/cat/report/task/event/BuilderTest.java
浏览文件 @
a45a9bbc
...
...
@@ -7,6 +7,7 @@ import java.util.Date;
import
org.junit.Test
;
import
org.unidal.lookup.ComponentTestCase
;
import
com.dianping.cat.consumer.event.EventAnalyzer
;
import
com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer
;
import
com.dianping.cat.consumer.problem.ProblemAnalyzer
;
import
com.dianping.cat.consumer.transaction.TransactionAnalyzer
;
...
...
@@ -40,4 +41,13 @@ public class BuilderTest extends ComponentTestCase {
Date
period
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
"2013-12-16 16:00:00"
);
builder
.
buildHourlyTask
(
TransactionAnalyzer
.
ID
,
"Cat"
,
period
);
}
@Test
public
void
testEvent
()
throws
ParseException
{
EventReportBuilder
builder
=
lookup
(
EventReportBuilder
.
class
);
Date
period
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
parse
(
"2013-12-16 16:00:00"
);
builder
.
buildHourlyTask
(
EventAnalyzer
.
ID
,
"Cat"
,
period
);
}
}
cat-home/src/test/java/com/dianping/cat/report/task/event/EventDailyGraphMergerTest.java
浏览文件 @
a45a9bbc
...
...
@@ -40,14 +40,6 @@ public class EventDailyGraphMergerTest {
Assert
.
assertEquals
(
expeted
.
replaceAll
(
"\r"
,
""
),
report
.
toString
().
replaceAll
(
"\r"
,
""
));
}
@Test
public
void
testForMegerGraph
()
throws
Exception
{
EventReport
report
=
m_meger
.
mergeForGraph
(
m_reportDomain
,
reports
);
String
expeted
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"EventMergerGraph.xml"
),
"utf-8"
);
Assert
.
assertEquals
(
expeted
.
replaceAll
(
"\r"
,
""
),
report
.
toString
().
replaceAll
(
"\r"
,
""
));
}
private
EventReport
creatReport
()
{
EventReport
result
=
new
EventReport
();
try
{
...
...
cat-home/src/test/java/com/dianping/cat/report/task/event/EventGraphCreatorTest.java
浏览文件 @
a45a9bbc
...
...
@@ -21,7 +21,9 @@ public class EventGraphCreatorTest {
EventGraphCreator
creator
=
new
EventGraphCreator
();
String
xml
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"BaseEventGraphReport.xml"
),
"utf-8"
);
EventReport
report
=
DefaultSaxParser
.
parse
(
xml
);
List
<
Graph
>
graphs
=
creator
.
buildGraph
(
report
);
List
<
Graph
>
graphs
=
creator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
"event"
,
report
);
//List<Graph> graphs = creator.buildGraph(report);
Map
<
String
,
Range
>
realResult
=
new
HashMap
<
String
,
Range
>();
Map
<
String
,
Range
>
excepectedResult
=
buildExceptedResult
();
buildResultResult
(
graphs
,
realResult
);
...
...
cat-home/src/test/java/com/dianping/cat/report/task/problem/ProblemCreateGraphDataTest.java
浏览文件 @
a45a9bbc
...
...
@@ -19,7 +19,7 @@ public class ProblemCreateGraphDataTest {
ProblemReport
report
=
DefaultSaxParser
.
parse
(
newXml
);
ProblemGraphCreator
creator
=
new
ProblemGraphCreator
();
List
<
Graph
>
graphs
=
creator
.
buildGraph
(
report
);
List
<
Graph
>
graphs
=
creator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
"problem"
,
report
);
Assert
.
assertEquals
(
"The graphs size"
,
3
,
graphs
.
size
());
...
...
cat-home/src/test/java/com/dianping/cat/report/task/problem/ProblemGraphCreatorTest.java
浏览文件 @
a45a9bbc
...
...
@@ -20,7 +20,7 @@ public class ProblemGraphCreatorTest {
ProblemReport
report
=
DefaultSaxParser
.
parse
(
xml
);
String
summary
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"problemGraphSummary"
),
"utf-8"
);
String
detail
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"problemGraphDetail"
),
"utf-8"
);
List
<
Graph
>
graphs
=
creator
.
buildGraph
(
report
);
List
<
Graph
>
graphs
=
creator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
"problem"
,
report
);
Assert
.
assertEquals
(
2
,
graphs
.
size
());
for
(
Graph
graph
:
graphs
)
{
...
...
cat-home/src/test/java/com/dianping/cat/report/task/transaction/TransactionDailyGraphMergerTest.java
浏览文件 @
a45a9bbc
...
...
@@ -36,19 +36,10 @@ public class TransactionDailyGraphMergerTest {
public
void
testForMergerDaily
()
throws
Exception
{
TransactionReport
report
=
m_meger
.
mergeForDaily
(
m_reportDomain
,
reports
,
m_domains
);
String
expeted
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"TransactionMergerDaily.xml"
),
"utf-8"
);
// Assert.assertEquals(expeted, report.toString());
Assert
.
assertEquals
(
expeted
.
replaceAll
(
"\r"
,
""
),
report
.
toString
().
replaceAll
(
"\r"
,
""
));
}
@Test
public
void
testForMegerGraph
()
throws
Exception
{
TransactionReport
report
=
m_meger
.
mergeForGraph
(
m_reportDomain
,
reports
);
String
expeted
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"TransactionMergerGraph.xml"
),
"utf-8"
);
// Assert.assertEquals(expeted, report.toString());
Assert
.
assertEquals
(
expeted
.
replaceAll
(
"\r"
,
""
),
report
.
toString
().
replaceAll
(
"\r"
,
""
));
}
private
TransactionReport
creatReport
()
{
TransactionReport
result
=
new
TransactionReport
();
try
{
...
...
cat-home/src/test/java/com/dianping/cat/report/task/transaction/TransactionGraphCreatorTest.java
浏览文件 @
a45a9bbc
...
...
@@ -22,7 +22,7 @@ public class TransactionGraphCreatorTest {
TransactionGraphCreator
creator
=
new
TransactionGraphCreator
();
String
xml
=
Files
.
forIO
().
readFrom
(
getClass
().
getResourceAsStream
(
"BaseTransactionReportForGraph.xml"
),
"utf-8"
);
TransactionReport
report
=
DefaultSaxParser
.
parse
(
xml
);
List
<
Graph
>
graphs
=
creator
.
buildGraph
(
report
);
List
<
Graph
>
graphs
=
creator
.
splitReportToGraphs
(
report
.
getStartTime
(),
report
.
getDomain
(),
"transaction"
,
report
);
Map
<
String
,
Range
>
realResult
=
new
HashMap
<
String
,
Range
>();
Map
<
String
,
Range
>
excepectedResult
=
buildExcepetedResult
();
buildRealResult
(
graphs
,
realResult
);
...
...
@@ -60,7 +60,6 @@ public class TransactionGraphCreatorTest {
range
.
total
=
tabs
[
1
];
range
.
sum
=
tabs
[
2
];
range
.
fail
=
tabs
[
3
];
result
.
put
(
tabs
[
0
],
range
);
}
}
...
...
@@ -79,7 +78,9 @@ public class TransactionGraphCreatorTest {
range
.
total
=
records
[
SummaryOrder
.
TOTAL_COUNT
.
ordinal
()];
range
.
fail
=
records
[
SummaryOrder
.
FAILURE_COUNT
.
ordinal
()];
range
.
sum
=
records
[
SummaryOrder
.
SUM
.
ordinal
()];
realResult
.
put
(
ip
+
':'
+
type
,
range
);
String
key
=
ip
+
':'
+
type
;
realResult
.
put
(
key
,
range
);
}
String
detailContent
=
graph
.
getDetailContent
();
lines
=
detailContent
.
split
(
"\n"
);
...
...
@@ -88,6 +89,7 @@ public class TransactionGraphCreatorTest {
String
type
=
records
[
0
];
String
name
=
records
[
1
];
Range
range
=
new
Range
();
range
.
total
=
records
[
DetailOrder
.
TOTAL_COUNT
.
ordinal
()];
range
.
fail
=
records
[
DetailOrder
.
FAILURE_COUNT
.
ordinal
()];
range
.
sum
=
records
[
DetailOrder
.
SUM
.
ordinal
()];
...
...
@@ -96,11 +98,11 @@ public class TransactionGraphCreatorTest {
}
}
static
class
Range
{
String
total
;
private
static
class
Range
{
public
String
total
;
String
fail
;
public
String
fail
;
String
sum
;
public
String
sum
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录