Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
6b6e74ef
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,发现更多精彩内容 >>
提交
6b6e74ef
编写于
9月 20, 2012
作者:
Y
youyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify the cat
上级
eedd7f93
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
303 addition
and
303 deletion
+303
-303
cat-consumer/src/main/java/com/dianping/cat/consumer/common/CommonAnalyzer.java
...java/com/dianping/cat/consumer/common/CommonAnalyzer.java
+46
-46
cat-consumer/src/main/java/com/dianping/cat/consumer/cross/CrossAnalyzer.java
...n/java/com/dianping/cat/consumer/cross/CrossAnalyzer.java
+91
-91
cat-consumer/src/main/java/com/dianping/cat/consumer/database/DatabaseAnalyzer.java
.../com/dianping/cat/consumer/database/DatabaseAnalyzer.java
+71
-71
cat-consumer/src/main/java/com/dianping/cat/consumer/sql/SqlAnalyzer.java
.../main/java/com/dianping/cat/consumer/sql/SqlAnalyzer.java
+72
-72
cat-consumer/src/main/java/com/dianping/cat/consumer/sql/SqlParseManager.java
...n/java/com/dianping/cat/consumer/sql/SqlParseManager.java
+17
-17
cat-consumer/src/main/java/com/dianping/cat/consumer/transaction/TransactionAnalyzer.java
...ianping/cat/consumer/transaction/TransactionAnalyzer.java
+6
-6
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/common/CommonAnalyzer.java
浏览文件 @
6b6e74ef
...
...
@@ -48,6 +48,52 @@ public class CommonAnalyzer extends AbstractMessageAnalyzer<CommonReport> implem
}
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
Set
<
String
>
getDomains
()
{
return
m_reports
.
keySet
();
}
@Override
public
CommonReport
getReport
(
String
domain
)
{
throw
new
RuntimeException
(
"Can't invoke get report in common anayler!"
);
}
@Override
protected
boolean
isTimeout
()
{
long
currentTime
=
System
.
currentTimeMillis
();
long
endTime
=
m_startTime
+
m_duration
+
m_extraTime
;
return
currentTime
>
endTime
;
}
@Override
protected
void
process
(
MessageTree
tree
)
{
String
domain
=
tree
.
getDomain
();
CommonReport
report
=
m_reports
.
get
(
domain
);
if
(
report
==
null
)
{
report
=
new
CommonReport
(
domain
);
report
.
setStartTime
(
new
Date
(
m_startTime
));
report
.
setEndTime
(
new
Date
(
m_startTime
+
MINUTE
*
60
-
1
));
m_reports
.
put
(
domain
,
report
);
}
String
ip
=
tree
.
getIpAddress
();
report
.
getIps
().
add
(
ip
);
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
long
extraTime
)
{
m_extraTime
=
extraTime
;
m_startTime
=
startTime
;
m_duration
=
duration
;
}
private
void
storeReport
()
{
Transaction
t
=
Cat
.
getProducer
().
newTransaction
(
"Checkpoint"
,
getClass
().
getSimpleName
());
...
...
@@ -97,50 +143,4 @@ public class CommonAnalyzer extends AbstractMessageAnalyzer<CommonReport> implem
t
.
complete
();
}
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
Set
<
String
>
getDomains
()
{
return
m_reports
.
keySet
();
}
@Override
protected
boolean
isTimeout
()
{
long
currentTime
=
System
.
currentTimeMillis
();
long
endTime
=
m_startTime
+
m_duration
+
m_extraTime
;
return
currentTime
>
endTime
;
}
@Override
protected
void
process
(
MessageTree
tree
)
{
String
domain
=
tree
.
getDomain
();
CommonReport
report
=
m_reports
.
get
(
domain
);
if
(
report
==
null
)
{
report
=
new
CommonReport
(
domain
);
report
.
setStartTime
(
new
Date
(
m_startTime
));
report
.
setEndTime
(
new
Date
(
m_startTime
+
MINUTE
*
60
-
1
));
m_reports
.
put
(
domain
,
report
);
}
String
ip
=
tree
.
getIpAddress
();
report
.
getIps
().
add
(
ip
);
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
long
extraTime
)
{
m_extraTime
=
extraTime
;
m_startTime
=
startTime
;
m_duration
=
duration
;
}
@Override
public
CommonReport
getReport
(
String
domain
)
{
throw
new
RuntimeException
(
"Can't invoke get report in common anayler!"
);
}
}
cat-consumer/src/main/java/com/dianping/cat/consumer/cross/CrossAnalyzer.java
浏览文件 @
6b6e74ef
...
...
@@ -56,6 +56,12 @@ public class CrossAnalyzer extends AbstractMessageAnalyzer<CrossReport> implemen
return
m_reports
.
keySet
();
}
private
String
getIpFromMessageId
(
String
messageId
)
{
MessageId
id
=
MessageId
.
parse
(
messageId
);
return
id
.
getIpAddress
();
}
public
CrossReport
getReport
(
String
domain
)
{
CrossReport
report
=
m_reports
.
get
(
domain
);
...
...
@@ -96,73 +102,19 @@ public class CrossAnalyzer extends AbstractMessageAnalyzer<CrossReport> implemen
}
}
@Override
protected
void
process
(
MessageTree
tree
)
{
String
domain
=
tree
.
getDomain
();
CrossReport
report
=
m_reports
.
get
(
domain
);
if
(
report
==
null
)
{
report
=
new
CrossReport
(
domain
);
report
.
setStartTime
(
new
Date
(
m_startTime
));
report
.
setEndTime
(
new
Date
(
m_startTime
+
MINUTE
*
60
-
1
));
m_reports
.
put
(
domain
,
report
);
}
Message
message
=
tree
.
getMessage
();
report
.
addIp
(
tree
.
getIpAddress
());
if
(
message
instanceof
Transaction
)
{
processTransaction
(
report
,
tree
,
(
Transaction
)
message
);
}
}
private
void
processTransaction
(
CrossReport
report
,
MessageTree
tree
,
Transaction
t
)
{
CrossInfo
info
=
parseCorssTransaction
(
t
,
tree
);
if
(
info
!=
null
)
{
updateCrossReport
(
report
,
t
,
info
);
}
List
<
Message
>
children
=
t
.
getChildren
();
for
(
Message
child
:
children
)
{
if
(
child
instanceof
Transaction
)
{
processTransaction
(
report
,
tree
,
(
Transaction
)
child
);
}
}
}
private
void
updateCrossReport
(
CrossReport
report
,
Transaction
t
,
CrossInfo
info
)
{
String
localIp
=
info
.
getLocalAddress
();
String
remoteIp
=
info
.
getRemoteAddress
();
String
role
=
info
.
getRemoteRole
();
String
transactionName
=
t
.
getName
();
Local
client
=
report
.
findOrCreateLocal
(
localIp
);
Remote
server
=
client
.
findOrCreateRemote
(
remoteIp
);
server
.
setRole
(
role
);
Type
type
=
server
.
getType
();
if
(
type
==
null
)
{
type
=
new
Type
();
type
.
setId
(
info
.
getDetailType
());
server
.
setType
(
type
);
public
CrossInfo
parseCorssTransaction
(
Transaction
t
,
MessageTree
tree
)
{
if
(
shouldDiscard
(
t
))
{
return
null
;
}
Name
name
=
type
.
findOrCreateName
(
transactionName
);
type
.
incTotalCount
();
name
.
incTotalCount
();
String
type
=
t
.
getType
();
if
(!
t
.
isSuccess
())
{
type
.
incFailCount
();
name
.
incFailCount
();
if
(
"PigeonCall"
.
equals
(
type
)
||
"Call"
.
equals
(
type
))
{
return
parsePigeonClientTransaction
(
t
,
tree
);
}
else
if
(
"PigeonService"
.
equals
(
type
)
||
"Service"
.
equals
(
type
))
{
return
parsePigeonServerTransaction
(
t
,
tree
);
}
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
name
.
setSum
(
name
.
getSum
()
+
duration
);
type
.
setSum
(
type
.
getSum
()
+
duration
);
return
null
;
}
private
CrossInfo
parsePigeonClientTransaction
(
Transaction
t
,
MessageTree
tree
)
{
...
...
@@ -213,25 +165,40 @@ public class CrossAnalyzer extends AbstractMessageAnalyzer<CrossReport> implemen
return
crossInfo
;
}
private
String
getIpFromMessageId
(
String
messageId
)
{
MessageId
id
=
MessageId
.
parse
(
messageId
);
@Override
protected
void
process
(
MessageTree
tree
)
{
String
domain
=
tree
.
getDomain
();
CrossReport
report
=
m_reports
.
get
(
domain
);
return
id
.
getIpAddress
();
if
(
report
==
null
)
{
report
=
new
CrossReport
(
domain
);
report
.
setStartTime
(
new
Date
(
m_startTime
));
report
.
setEndTime
(
new
Date
(
m_startTime
+
MINUTE
*
60
-
1
));
m_reports
.
put
(
domain
,
report
);
}
Message
message
=
tree
.
getMessage
();
report
.
addIp
(
tree
.
getIpAddress
());
if
(
message
instanceof
Transaction
)
{
processTransaction
(
report
,
tree
,
(
Transaction
)
message
);
}
}
public
CrossInfo
parseCorssTransaction
(
Transaction
t
,
MessageTree
tree
)
{
if
(
shouldDiscard
(
t
))
{
return
null
;
private
void
processTransaction
(
CrossReport
report
,
MessageTree
tree
,
Transaction
t
)
{
CrossInfo
info
=
parseCorssTransaction
(
t
,
tree
);
if
(
info
!=
null
)
{
updateCrossReport
(
report
,
t
,
info
);
}
String
type
=
t
.
getType
();
List
<
Message
>
children
=
t
.
getChildren
();
if
(
"PigeonCall"
.
equals
(
type
)
||
"Call"
.
equals
(
type
)
)
{
return
parsePigeonClientTransaction
(
t
,
tree
);
}
else
if
(
"PigeonService"
.
equals
(
type
)
||
"Service"
.
equals
(
type
))
{
return
parsePigeonServerTransaction
(
t
,
tree
);
for
(
Message
child
:
children
)
{
if
(
child
instanceof
Transaction
)
{
processTransaction
(
report
,
tree
,
(
Transaction
)
child
);
}
}
return
null
;
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
long
extraTime
)
{
...
...
@@ -306,6 +273,39 @@ public class CrossAnalyzer extends AbstractMessageAnalyzer<CrossReport> implemen
}
}
private
void
updateCrossReport
(
CrossReport
report
,
Transaction
t
,
CrossInfo
info
)
{
String
localIp
=
info
.
getLocalAddress
();
String
remoteIp
=
info
.
getRemoteAddress
();
String
role
=
info
.
getRemoteRole
();
String
transactionName
=
t
.
getName
();
Local
client
=
report
.
findOrCreateLocal
(
localIp
);
Remote
server
=
client
.
findOrCreateRemote
(
remoteIp
);
server
.
setRole
(
role
);
Type
type
=
server
.
getType
();
if
(
type
==
null
)
{
type
=
new
Type
();
type
.
setId
(
info
.
getDetailType
());
server
.
setType
(
type
);
}
Name
name
=
type
.
findOrCreateName
(
transactionName
);
type
.
incTotalCount
();
name
.
incTotalCount
();
if
(!
t
.
isSuccess
())
{
type
.
incFailCount
();
name
.
incFailCount
();
}
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
name
.
setSum
(
name
.
getSum
()
+
duration
);
type
.
setSum
(
type
.
getSum
()
+
duration
);
}
static
class
CrossInfo
{
private
String
m_remoteRole
=
UNKNOWN
;
...
...
@@ -315,36 +315,36 @@ public class CrossAnalyzer extends AbstractMessageAnalyzer<CrossReport> implemen
private
String
m_detailType
=
UNKNOWN
;
public
String
getRemoteRole
()
{
return
m_remoteRole
;
}
public
void
setRemoteRole
(
String
remoteRole
)
{
m_remoteRole
=
remoteRole
;
public
String
getDetailType
()
{
return
m_detailType
;
}
public
String
getLocalAddress
()
{
return
m_LocalAddress
;
}
public
void
setLocalAddress
(
String
localAddress
)
{
m_LocalAddress
=
localAddress
;
}
public
String
getRemoteAddress
()
{
return
m_RemoteAddress
;
}
public
void
setRemoteAddress
(
String
remoteAddress
)
{
m_RemoteAddress
=
remoteAddress
;
}
public
String
getDetailType
()
{
return
m_detailType
;
public
String
getRemoteRole
()
{
return
m_remoteRole
;
}
public
void
setDetailType
(
String
detailType
)
{
m_detailType
=
detailType
;
}
public
void
setLocalAddress
(
String
localAddress
)
{
m_LocalAddress
=
localAddress
;
}
public
void
setRemoteAddress
(
String
remoteAddress
)
{
m_RemoteAddress
=
remoteAddress
;
}
public
void
setRemoteRole
(
String
remoteRole
)
{
m_remoteRole
=
remoteRole
;
}
}
}
cat-consumer/src/main/java/com/dianping/cat/consumer/database/DatabaseAnalyzer.java
浏览文件 @
6b6e74ef
...
...
@@ -41,6 +41,35 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
private
Map
<
String
,
DatabaseReport
>
m_reports
=
new
HashMap
<
String
,
DatabaseReport
>();
private
DatabaseItem
buildDataBaseItem
(
String
domain
,
Transaction
t
)
{
List
<
Message
>
messages
=
t
.
getChildren
();
String
connection
=
null
;
String
method
=
null
;
String
sqlName
=
t
.
getName
();
String
sqlStatement
=
(
String
)
t
.
getData
();
for
(
Message
message
:
messages
)
{
if
(
message
instanceof
Event
)
{
String
type
=
message
.
getType
();
if
(
type
.
equals
(
"SQL.Method"
))
{
method
=
message
.
getName
();
}
else
if
(
type
.
equals
(
"SQL.Database"
))
{
connection
=
message
.
getName
();
}
}
}
if
(
connection
!=
null
&&
method
!=
null
)
{
DatabaseItem
item
=
new
DatabaseItem
();
String
tables
=
m_sqlParseManeger
.
getTableNames
(
sqlName
,
sqlStatement
,
domain
);
String
database
=
getDataBaseName
(
connection
);
item
.
setDatabase
(
database
).
setTables
(
tables
).
setMethod
(
method
).
setConnectionUrl
(
connection
);
return
item
;
}
return
null
;
}
@Override
public
void
doCheckpoint
(
boolean
atEnd
)
{
storeReports
(
atEnd
);
...
...
@@ -51,6 +80,19 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
m_logger
=
logger
;
}
private
String
getDataBaseName
(
String
url
)
{
try
{
int
index
=
url
.
indexOf
(
"://"
);
String
temp
=
url
.
substring
(
index
+
3
);
index
=
temp
.
indexOf
(
"/"
);
int
index2
=
temp
.
indexOf
(
"?"
);
String
schema
=
temp
.
substring
(
index
+
1
,
index2
!=
-
1
?
index2
:
temp
.
length
());
return
schema
;
}
catch
(
Exception
e
)
{
}
return
"Unknown"
;
}
@Override
public
Set
<
String
>
getDomains
()
{
return
m_reports
.
keySet
();
...
...
@@ -145,29 +187,6 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
}
}
private
void
updateTableInfo
(
Table
table
,
String
method
,
String
sqlName
,
Transaction
t
)
{
String
status
=
t
.
getStatus
();
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
Method
m
=
table
.
findOrCreateMethod
(
method
);
if
(!
status
.
equals
(
Message
.
SUCCESS
))
{
m
.
incFailCount
();
table
.
incFailCount
();
}
m
.
addSql
(
sqlName
);
m
.
incTotalCount
();
m
.
setSum
(
m
.
getSum
()
+
duration
);
m
.
setAvg
(
m
.
getSum
()
/
(
double
)
m
.
getTotalCount
());
m
.
setFailPercent
(
m
.
getFailCount
()
/
(
double
)
m
.
getTotalCount
());
table
.
incTotalCount
();
table
.
setSum
(
table
.
getSum
()
+
duration
);
table
.
setAvg
(
table
.
getSum
()
/
(
double
)
table
.
getTotalCount
());
table
.
setFailPercent
(
table
.
getFailCount
()
/
(
double
)
table
.
getTotalCount
());
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
long
extraTime
)
{
m_extraTime
=
extraTime
;
m_startTime
=
startTime
;
...
...
@@ -238,46 +257,27 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
}
}
private
DatabaseItem
buildDataBaseItem
(
String
domain
,
Transaction
t
)
{
List
<
Message
>
messages
=
t
.
getChildren
();
String
connection
=
null
;
String
method
=
null
;
String
sqlName
=
t
.
getName
();
String
sqlStatement
=
(
String
)
t
.
getData
();
private
void
updateTableInfo
(
Table
table
,
String
method
,
String
sqlName
,
Transaction
t
)
{
String
status
=
t
.
getStatus
();
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
for
(
Message
message
:
messages
)
{
if
(
message
instanceof
Event
)
{
String
type
=
message
.
getType
();
Method
m
=
table
.
findOrCreateMethod
(
method
);
if
(
type
.
equals
(
"SQL.Method"
))
{
method
=
message
.
getName
();
}
else
if
(
type
.
equals
(
"SQL.Database"
))
{
connection
=
message
.
getName
();
}
}
if
(!
status
.
equals
(
Message
.
SUCCESS
))
{
m
.
incFailCount
();
table
.
incFailCount
();
}
if
(
connection
!=
null
&&
method
!=
null
)
{
DatabaseItem
item
=
new
DatabaseItem
();
String
tables
=
m_sqlParseManeger
.
getTableNames
(
sqlName
,
sqlStatement
,
domain
);
String
database
=
getDataBaseName
(
connection
);
m
.
addSql
(
sqlName
);
item
.
setDatabase
(
database
).
setTables
(
tables
).
setMethod
(
method
).
setConnectionUrl
(
connection
);
return
item
;
}
return
null
;
}
m
.
incTotalCount
();
m
.
setSum
(
m
.
getSum
()
+
duration
);
m
.
setAvg
(
m
.
getSum
()
/
(
double
)
m
.
getTotalCount
());
m
.
setFailPercent
(
m
.
getFailCount
()
/
(
double
)
m
.
getTotalCount
());
private
String
getDataBaseName
(
String
url
)
{
try
{
int
index
=
url
.
indexOf
(
"://"
);
String
temp
=
url
.
substring
(
index
+
3
);
index
=
temp
.
indexOf
(
"/"
);
int
index2
=
temp
.
indexOf
(
"?"
);
String
schema
=
temp
.
substring
(
index
+
1
,
index2
!=
-
1
?
index2
:
temp
.
length
());
return
schema
;
}
catch
(
Exception
e
)
{
}
return
"Unknown"
;
table
.
incTotalCount
();
table
.
setSum
(
table
.
getSum
()
+
duration
);
table
.
setAvg
(
table
.
getSum
()
/
(
double
)
table
.
getTotalCount
());
table
.
setFailPercent
(
table
.
getFailCount
()
/
(
double
)
table
.
getTotalCount
());
}
public
static
class
DatabaseItem
{
...
...
@@ -289,12 +289,20 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
private
String
m_method
;
public
String
getConnectionUrl
()
{
return
m_connectionUrl
;
}
public
String
getDatabase
()
{
return
m_database
;
}
public
String
getConnectionUrl
()
{
return
m_connectionUrl
;
public
String
getMethod
()
{
return
m_method
;
}
public
String
getTables
()
{
return
m_tables
;
}
public
DatabaseItem
setConnectionUrl
(
String
connectionUrl
)
{
...
...
@@ -307,22 +315,14 @@ public class DatabaseAnalyzer extends AbstractMessageAnalyzer<DatabaseReport> im
return
this
;
}
public
String
getTables
()
{
return
m_tables
;
public
DatabaseItem
setMethod
(
String
method
)
{
m_method
=
method
;
return
this
;
}
public
DatabaseItem
setTables
(
String
tables
)
{
m_tables
=
tables
;
return
this
;
}
public
String
getMethod
()
{
return
m_method
;
}
public
DatabaseItem
setMethod
(
String
method
)
{
m_method
=
method
;
return
this
;
}
}
}
cat-consumer/src/main/java/com/dianping/cat/consumer/sql/SqlAnalyzer.java
浏览文件 @
6b6e74ef
...
...
@@ -40,6 +40,35 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
private
Map
<
String
,
SqlReport
>
m_reports
=
new
HashMap
<
String
,
SqlReport
>();
private
DatabaseItem
buildDataBaseItem
(
String
domain
,
Transaction
t
)
{
List
<
Message
>
messages
=
t
.
getChildren
();
String
connection
=
null
;
String
method
=
null
;
String
sqlName
=
t
.
getName
();
String
sqlStatement
=
(
String
)
t
.
getData
();
for
(
Message
message
:
messages
)
{
if
(
message
instanceof
Event
)
{
String
type
=
message
.
getType
();
if
(
type
.
equals
(
"SQL.Method"
))
{
method
=
message
.
getName
();
}
else
if
(
type
.
equals
(
"SQL.Database"
))
{
connection
=
message
.
getName
();
}
}
}
if
(
connection
!=
null
&&
method
!=
null
)
{
DatabaseItem
item
=
new
DatabaseItem
();
String
tables
=
m_sqlParseManager
.
getTableNames
(
sqlName
,
sqlStatement
,
domain
);
String
database
=
getDataBaseName
(
connection
);
item
.
setDatabase
(
database
).
setTables
(
tables
).
setMethod
(
method
).
setConnectionUrl
(
connection
);
return
item
;
}
return
null
;
}
@Override
public
void
doCheckpoint
(
boolean
atEnd
)
{
storeReports
(
atEnd
);
...
...
@@ -50,6 +79,20 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
m_logger
=
logger
;
}
private
String
getDataBaseName
(
String
url
)
{
try
{
int
index
=
url
.
indexOf
(
"://"
);
String
temp
=
url
.
substring
(
index
+
3
);
index
=
temp
.
indexOf
(
"/"
);
int
index2
=
temp
.
indexOf
(
"?"
);
String
schema
=
temp
.
substring
(
index
+
1
,
index2
!=
-
1
?
index2
:
temp
.
length
());
return
schema
;
}
catch
(
Exception
e
)
{
}
return
"Unknown"
;
}
@Override
public
Set
<
String
>
getDomains
()
{
return
m_reports
.
keySet
();
...
...
@@ -148,29 +191,6 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
}
}
private
void
updateTableInfo
(
Table
table
,
String
method
,
String
sqlName
,
Transaction
t
)
{
String
status
=
t
.
getStatus
();
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
Method
m
=
table
.
findOrCreateMethod
(
method
);
if
(!
status
.
equals
(
Message
.
SUCCESS
))
{
m
.
incFailCount
();
table
.
incFailCount
();
}
m
.
addSql
(
sqlName
);
m
.
incTotalCount
();
m
.
setSum
(
m
.
getSum
()
+
duration
);
m
.
setAvg
(
m
.
getSum
()
/
(
double
)
m
.
getTotalCount
());
m
.
setFailPercent
(
m
.
getFailCount
()
/
(
double
)
m
.
getTotalCount
());
table
.
incTotalCount
();
table
.
setSum
(
table
.
getSum
()
+
duration
);
table
.
setAvg
(
table
.
getSum
()
/
(
double
)
table
.
getTotalCount
());
table
.
setFailPercent
(
table
.
getFailCount
()
/
(
double
)
table
.
getTotalCount
());
}
public
void
setAnalyzerInfo
(
long
startTime
,
long
duration
,
long
extraTime
)
{
m_extraTime
=
extraTime
;
m_startTime
=
startTime
;
...
...
@@ -242,47 +262,27 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
}
private
DatabaseItem
buildDataBaseItem
(
String
domain
,
Transaction
t
)
{
List
<
Message
>
messages
=
t
.
getChildren
();
String
connection
=
null
;
String
method
=
null
;
String
sqlName
=
t
.
getName
();
String
sqlStatement
=
(
String
)
t
.
getData
();
private
void
updateTableInfo
(
Table
table
,
String
method
,
String
sqlName
,
Transaction
t
)
{
String
status
=
t
.
getStatus
();
double
duration
=
t
.
getDurationInMicros
()
/
1000
d
;
for
(
Message
message
:
messages
)
{
if
(
message
instanceof
Event
)
{
String
type
=
message
.
getType
();
Method
m
=
table
.
findOrCreateMethod
(
method
);
if
(
type
.
equals
(
"SQL.Method"
))
{
method
=
message
.
getName
();
}
else
if
(
type
.
equals
(
"SQL.Database"
))
{
connection
=
message
.
getName
();
}
}
if
(!
status
.
equals
(
Message
.
SUCCESS
))
{
m
.
incFailCount
();
table
.
incFailCount
();
}
if
(
connection
!=
null
&&
method
!=
null
)
{
DatabaseItem
item
=
new
DatabaseItem
();
String
tables
=
m_sqlParseManager
.
getTableNames
(
sqlName
,
sqlStatement
,
domain
);
String
database
=
getDataBaseName
(
connection
);
m
.
addSql
(
sqlName
);
item
.
setDatabase
(
database
).
setTables
(
tables
).
setMethod
(
method
).
setConnectionUrl
(
connection
);
return
item
;
}
return
null
;
}
m
.
incTotalCount
();
m
.
setSum
(
m
.
getSum
()
+
duration
);
m
.
setAvg
(
m
.
getSum
()
/
(
double
)
m
.
getTotalCount
());
m
.
setFailPercent
(
m
.
getFailCount
()
/
(
double
)
m
.
getTotalCount
());
private
String
getDataBaseName
(
String
url
)
{
try
{
int
index
=
url
.
indexOf
(
"://"
);
String
temp
=
url
.
substring
(
index
+
3
);
index
=
temp
.
indexOf
(
"/"
);
int
index2
=
temp
.
indexOf
(
"?"
);
String
schema
=
temp
.
substring
(
index
+
1
,
index2
!=
-
1
?
index2
:
temp
.
length
());
return
schema
;
}
catch
(
Exception
e
)
{
}
return
"Unknown"
;
table
.
incTotalCount
();
table
.
setSum
(
table
.
getSum
()
+
duration
);
table
.
setAvg
(
table
.
getSum
()
/
(
double
)
table
.
getTotalCount
());
table
.
setFailPercent
(
table
.
getFailCount
()
/
(
double
)
table
.
getTotalCount
());
}
public
static
class
DatabaseItem
{
...
...
@@ -294,12 +294,20 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
private
String
m_method
;
public
String
getConnectionUrl
()
{
return
m_connectionUrl
;
}
public
String
getDatabase
()
{
return
m_database
;
}
public
String
getConnectionUrl
()
{
return
m_connectionUrl
;
public
String
getMethod
()
{
return
m_method
;
}
public
String
getTables
()
{
return
m_tables
;
}
public
DatabaseItem
setConnectionUrl
(
String
connectionUrl
)
{
...
...
@@ -312,22 +320,14 @@ public class SqlAnalyzer extends AbstractMessageAnalyzer<SqlReport> implements L
return
this
;
}
public
String
getTables
()
{
return
m_tables
;
public
DatabaseItem
setMethod
(
String
method
)
{
m_method
=
method
;
return
this
;
}
public
DatabaseItem
setTables
(
String
tables
)
{
m_tables
=
tables
;
return
this
;
}
public
String
getMethod
()
{
return
m_method
;
}
public
DatabaseItem
setMethod
(
String
method
)
{
m_method
=
method
;
return
this
;
}
}
}
cat-consumer/src/main/java/com/dianping/cat/consumer/sql/SqlParseManager.java
浏览文件 @
6b6e74ef
...
...
@@ -52,6 +52,23 @@ public class SqlParseManager {
}
}
private
synchronized
void
loadAllFromDatabase
(
String
domain
)
{
if
(
m_domains
.
contains
(
domain
))
{
return
;
}
try
{
List
<
Sqltable
>
sqltables
=
m_sqltableDao
.
findAllByDomain
(
domain
,
SqltableEntity
.
READSET_FULL
);
for
(
Sqltable
sqltable
:
sqltables
)
{
m_sqltables
.
put
(
sqltable
.
getSqlName
(),
sqltable
.
getTableName
());
}
m_domains
.
add
(
domain
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
private
String
parseSql
(
String
sqlStatement
)
{
List
<
String
>
tables
=
SqlParsers
.
forTable
().
parse
(
sqlStatement
);
String
result
=
""
;
...
...
@@ -70,21 +87,4 @@ public class SqlParseManager {
}
return
result
;
}
private
synchronized
void
loadAllFromDatabase
(
String
domain
)
{
if
(
m_domains
.
contains
(
domain
))
{
return
;
}
try
{
List
<
Sqltable
>
sqltables
=
m_sqltableDao
.
findAllByDomain
(
domain
,
SqltableEntity
.
READSET_FULL
);
for
(
Sqltable
sqltable
:
sqltables
)
{
m_sqltables
.
put
(
sqltable
.
getSqlName
(),
sqltable
.
getTableName
());
}
m_domains
.
add
(
domain
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
}
cat-consumer/src/main/java/com/dianping/cat/consumer/transaction/TransactionAnalyzer.java
浏览文件 @
6b6e74ef
...
...
@@ -401,6 +401,12 @@ public class TransactionAnalyzer extends AbstractMessageAnalyzer<TransactionRepo
m_maxItems
=
maxItem
;
}
@Override
public
void
visitTransactionReport
(
TransactionReport
transactionReport
)
{
m_domain
=
transactionReport
.
getDomain
();
super
.
visitTransactionReport
(
transactionReport
);
}
@Override
public
void
visitType
(
TransactionType
type
)
{
long
totalCount
=
type
.
getTotalCount
();
...
...
@@ -440,11 +446,5 @@ public class TransactionAnalyzer extends AbstractMessageAnalyzer<TransactionRepo
}
super
.
visitType
(
type
);
}
@Override
public
void
visitTransactionReport
(
TransactionReport
transactionReport
)
{
m_domain
=
transactionReport
.
getDomain
();
super
.
visitTransactionReport
(
transactionReport
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录