Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
8733acd9
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,发现更多精彩内容 >>
提交
8733acd9
编写于
2月 02, 2012
作者:
S
sean.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
page fix
上级
68aa4be3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
44 deletion
+57
-44
cat-consumer/src/main/java/com/dianping/cat/consumer/transaction/TransactionReportAnalyzer.java
...g/cat/consumer/transaction/TransactionReportAnalyzer.java
+56
-43
cat-home/src/main/webapp/js/transaction.js
cat-home/src/main/webapp/js/transaction.js
+1
-1
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/transaction/TransactionReportAnalyzer.java
浏览文件 @
8733acd9
...
...
@@ -8,7 +8,6 @@ import java.io.IOException;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -20,7 +19,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
import
com.dianping.cat.configuration.model.entity.Config
;
import
com.dianping.cat.configuration.model.entity.Property
;
import
com.dianping.cat.consumer.failure.model.entity.FailureReport
;
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
;
...
...
@@ -38,16 +36,13 @@ import com.site.lookup.annotation.Inject;
* @since Jan 5, 2012
*/
public
class
TransactionReportAnalyzer
extends
AbstractMessageAnalyzer
<
TransactionReport
>
implements
Initializable
,
LogEnabled
{
private
final
static
long
MINUTE
=
60
*
1000L
;
private
final
static
SimpleDateFormat
FILE_SDF
=
new
SimpleDateFormat
(
"yyyyMMddHHmm"
);
@Inject
private
MessageManager
m_manager
;
private
Map
<
String
,
FailureReport
>
m_reports
=
new
HashMap
<
String
,
FailureReport
>();
private
TransactionReport
report
;
private
Map
<
String
,
TransactionReport
>
m_reports
=
new
HashMap
<
String
,
TransactionReport
>()
;
private
long
m_extraTime
;
...
...
@@ -55,7 +50,15 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
private
Logger
m_logger
;
private
void
computeMeanSquareDeviation
(
String
domain
)
{
private
long
m_startTime
;
private
long
m_duration
;
private
TransactionReport
computeMeanSquareDeviation
(
String
domain
)
{
TransactionReport
report
=
m_reports
.
get
(
domain
);
if
(
report
==
null
)
{
return
report
;
}
Collection
<
TransactionType
>
types
=
report
.
getTypes
().
values
();
for
(
TransactionType
type
:
types
)
{
...
...
@@ -97,16 +100,7 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
type
.
setFailPercent
(
100.0
*
typeFailCount
/
typeCount
);
type
.
setStd
(
std
(
typeCount
,
typeAvg
,
typeSum2
));
}
}
/**
* @param count
* @param ave
* @param sum2
* @return
*/
public
double
std
(
long
count
,
double
ave
,
double
sum2
)
{
return
Math
.
sqrt
(
sum2
/
count
-
2
*
ave
*
ave
+
ave
*
ave
);
return
report
;
}
@Override
...
...
@@ -118,11 +112,19 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
public
List
<
TransactionReport
>
generate
()
{
List
<
TransactionReport
>
reports
=
new
ArrayList
<
TransactionReport
>();
for
(
String
domain
:
m_reports
.
keySet
())
{
computeMeanSquareDeviation
(
domain
);
reports
.
add
(
generate
(
domain
)
);
}
return
reports
;
}
@Override
public
TransactionReport
generate
(
String
domain
)
{
if
(
domain
==
null
)
{
domain
=
(
String
)
this
.
m_reports
.
keySet
().
toArray
()[
0
];
}
return
computeMeanSquareDeviation
(
domain
);
}
private
String
getTransactionFileName
(
TransactionReport
report
)
{
StringBuffer
result
=
new
StringBuffer
();
String
start
=
FILE_SDF
.
format
(
report
.
getStartTime
());
...
...
@@ -147,7 +149,7 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
@Override
protected
boolean
isTimeout
()
{
long
endTime
=
report
.
getEndTime
().
getTime
()
;
long
endTime
=
m_startTime
+
m_duration
+
m_extraTime
;
long
currentTime
=
System
.
currentTimeMillis
();
if
(
currentTime
>
endTime
+
m_extraTime
)
{
...
...
@@ -156,7 +158,7 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
return
false
;
}
private
void
process
(
Message
message
,
String
messageId
)
{
private
void
process
(
TransactionReport
report
,
Message
message
,
String
messageId
)
{
if
(
message
instanceof
Transaction
)
{
Transaction
t
=
(
Transaction
)
message
;
String
tType
=
t
.
getType
();
...
...
@@ -192,54 +194,65 @@ public class TransactionReportAnalyzer extends AbstractMessageAnalyzer<Transacti
}
List
<
Message
>
children
=
t
.
getChildren
();
for
(
Message
child
:
children
)
{
process
(
child
,
null
);
process
(
report
,
child
,
null
);
}
}
}
@Override
protected
void
process
(
MessageTree
tree
)
{
String
domain
=
tree
.
getDomain
();
TransactionReport
report
=
this
.
m_reports
.
get
(
domain
);
if
(
report
==
null
)
{
this
.
report
=
new
TransactionReport
(
tree
.
getDomain
());
report
=
new
TransactionReport
(
domain
);
this
.
m_reports
.
put
(
domain
,
report
);
}
Message
message
=
tree
.
getMessage
();
process
(
message
,
tree
.
getMessageId
());
process
(
report
,
message
,
tree
.
getMessageId
());
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
String
domain
,
long
extraTime
)
{
report
=
new
TransactionReport
(
domain
);
report
.
setStartTime
(
new
Date
(
startTime
));
report
.
setEndTime
(
new
Date
(
startTime
+
duration
-
MINUTE
));
m_extraTime
=
extraTime
;
m_startTime
=
startTime
;
m_duration
=
duration
;
}
public
void
setReportPath
(
String
configPath
)
{
m_reportPath
=
configPath
;
}
/**
* @param count
* @param ave
* @param sum2
* @return
*/
public
double
std
(
long
count
,
double
ave
,
double
sum2
)
{
return
Math
.
sqrt
(
sum2
/
count
-
2
*
ave
*
ave
+
ave
*
ave
);
}
@Override
protected
void
store
(
List
<
TransactionReport
>
result
)
{
String
failureFileName
=
getTransactionFileName
(
report
);
String
htmlPath
=
new
StringBuilder
().
append
(
m_reportPath
).
append
(
failureFileName
).
append
(
".html"
).
toString
();
File
file
=
new
File
(
htmlPath
);
protected
void
store
(
List
<
TransactionReport
>
reports
)
{
if
(
reports
==
null
||
reports
.
size
()
==
0
)
{
return
;
}
for
(
TransactionReport
report
:
reports
)
{
String
failureFileName
=
getTransactionFileName
(
report
);
String
htmlPath
=
new
StringBuilder
().
append
(
m_reportPath
).
append
(
failureFileName
).
append
(
".html"
).
toString
();
File
file
=
new
File
(
htmlPath
);
file
.
getParentFile
().
mkdirs
();
file
.
getParentFile
().
mkdirs
();
DefaultJsonBuilder
builder
=
new
DefaultJsonBuilder
();
DefaultJsonBuilder
builder
=
new
DefaultJsonBuilder
();
report
.
accept
(
builder
);
report
.
accept
(
builder
);
try
{
Files
.
forIO
().
writeTo
(
file
,
builder
.
getString
());
}
catch
(
IOException
e
)
{
m_logger
.
error
(
String
.
format
(
"Error when writing to file(%s)!"
,
file
),
e
);
try
{
Files
.
forIO
().
writeTo
(
file
,
builder
.
getString
());
}
catch
(
IOException
e
)
{
m_logger
.
error
(
String
.
format
(
"Error when writing to file(%s)!"
,
file
),
e
);
}
}
}
@Override
public
TransactionReport
generate
(
String
domain
)
{
// TODO Auto-generated method stub
return
null
;
}
}
cat-home/src/main/webapp/js/transaction.js
浏览文件 @
8733acd9
...
...
@@ -25,7 +25,7 @@ $(function()
],
sortname
:
'
type
'
,
sortorder
:
'
asc
'
,
caption
:
"
Transaction Summary
"
,
caption
:
"
Domain
"
+
data
[
"
domain
"
]
+
"
Transaction Summary
"
,
height
:
'
100%
'
,
autowidth
:
true
,
loadComplete
:
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录