Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
5a5632d0
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,发现更多精彩内容 >>
提交
5a5632d0
编写于
1月 13, 2012
作者:
U
unknown
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify the config
上级
883de335
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
109 addition
and
82 deletion
+109
-82
cat-consumer/src/main/java/com/dianping/cat/consumer/AnalyzerFactory.java
.../main/java/com/dianping/cat/consumer/AnalyzerFactory.java
+1
-2
cat-consumer/src/main/java/com/dianping/cat/consumer/RealtimeConsumer.java
...main/java/com/dianping/cat/consumer/RealtimeConsumer.java
+59
-52
cat-consumer/src/main/java/com/dianping/cat/consumer/configuration/ComponentsConfigurator.java
...ng/cat/consumer/configuration/ComponentsConfigurator.java
+7
-3
cat-consumer/src/main/java/com/dianping/cat/consumer/failure/FailureReportAnalyzer.java
.../dianping/cat/consumer/failure/FailureReportAnalyzer.java
+21
-12
cat-consumer/src/main/java/com/dianping/cat/consumer/failure/FailureReportStore.java
...com/dianping/cat/consumer/failure/FailureReportStore.java
+6
-11
cat-consumer/src/main/resources/META-INF/dal/model/failure-report-codegen.xml
...n/resources/META-INF/dal/model/failure-report-codegen.xml
+2
-1
cat-consumer/src/main/resources/META-INF/plexus/components.xml
...onsumer/src/main/resources/META-INF/plexus/components.xml
+12
-0
cat-home/src/main/webapp/js/failure.js
cat-home/src/main/webapp/js/failure.js
+1
-1
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/AnalyzerFactory.java
浏览文件 @
5a5632d0
...
...
@@ -8,8 +8,7 @@ import com.dianping.cat.message.spi.MessageAnalyzer;
*/
public
interface
AnalyzerFactory
{
public
MessageAnalyzer
create
(
String
name
,
long
start
,
long
duration
,
String
domain
,
long
extraTime
);
public
MessageAnalyzer
create
(
String
name
,
long
start
,
long
duration
,
String
domain
,
long
extraTime
);
public
void
release
(
Object
component
);
...
...
cat-consumer/src/main/java/com/dianping/cat/consumer/RealtimeConsumer.java
浏览文件 @
5a5632d0
...
...
@@ -8,7 +8,8 @@ import java.util.Map;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
org.apache.log4j.Logger
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
...
...
@@ -27,8 +28,52 @@ import com.site.lookup.annotation.Inject;
* @author yong.you
* @since Jan 5, 2012
*/
public
class
RealtimeConsumer
extends
ContainerHolder
implements
MessageConsumer
,
Initializable
{
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
RealtimeConsumer
.
class
);
public
class
RealtimeConsumer
extends
ContainerHolder
implements
MessageConsumer
,
Initializable
,
LogEnabled
{
static
class
Period
{
private
long
m_startTime
;
private
long
m_endTime
;
private
List
<
MessageQueue
>
m_queues
;
public
Period
(
long
startTime
,
long
endTime
,
List
<
MessageQueue
>
queues
)
{
m_startTime
=
startTime
;
m_endTime
=
endTime
;
m_queues
=
queues
;
}
public
List
<
MessageQueue
>
getQueues
()
{
return
m_queues
;
}
public
boolean
isIn
(
long
timestamp
)
{
return
timestamp
>=
m_startTime
&&
timestamp
<
m_endTime
;
}
}
static
class
Task
implements
Runnable
{
private
AnalyzerFactory
m_factory
;
private
MessageAnalyzer
m_analyzer
;
private
MessageQueue
m_queue
;
public
Task
(
AnalyzerFactory
factory
,
MessageAnalyzer
analyzer
,
MessageQueue
queue
)
{
m_factory
=
factory
;
m_analyzer
=
analyzer
;
m_queue
=
queue
;
}
public
MessageQueue
getQueue
()
{
return
m_queue
;
}
public
void
run
()
{
m_analyzer
.
analyze
(
m_queue
);
m_factory
.
release
(
m_analyzer
);
m_factory
.
release
(
m_queue
);
}
}
private
static
final
long
HOUR
=
60
*
60
*
1000L
;
...
...
@@ -40,6 +85,9 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
private
static
final
long
FIVE_MINUTES
=
5
*
60
*
1000L
;
@Inject
private
Logger
m_logger
;
@Inject
private
String
m_consumerId
;
...
...
@@ -94,7 +142,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
if
(
timestamp
<
now
+
MINUTE
*
3
&&
timestamp
>=
nextStart
)
{
startTasks
(
tree
);
}
else
{
LOG
.
warn
(
"The message is not excepceted!"
+
tree
);
m_logger
.
warn
(
"The message is not excepceted!"
+
tree
);
}
}
}
...
...
@@ -109,6 +157,11 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
}
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
String
getConsumerId
()
{
return
m_consumerId
;
...
...
@@ -122,7 +175,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
public
String
getDomain
()
{
return
m_domain
;
}
public
MessageAnalyzer
getLastAnalyzer
(
String
name
)
{
return
m_lastAnalyzers
.
get
(
name
);
}
...
...
@@ -173,7 +226,7 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
private
void
startTasks
(
MessageTree
tree
)
{
long
time
=
tree
.
getMessage
().
getTimestamp
();
long
start
=
time
-
time
%
m_duration
;
LOG
.
info
(
"Start Tasks At "
+
new
Date
(
start
));
m_logger
.
info
(
"Start Tasks At "
+
new
Date
(
start
));
List
<
MessageQueue
>
queues
=
new
ArrayList
<
MessageQueue
>();
Period
current
=
new
Period
(
start
,
start
+
m_duration
,
queues
);
...
...
@@ -200,50 +253,4 @@ public class RealtimeConsumer extends ContainerHolder implements MessageConsumer
m_periods
.
add
(
current
);
}
static
class
Period
{
private
long
m_startTime
;
private
long
m_endTime
;
private
List
<
MessageQueue
>
m_queues
;
public
Period
(
long
startTime
,
long
endTime
,
List
<
MessageQueue
>
queues
)
{
m_startTime
=
startTime
;
m_endTime
=
endTime
;
m_queues
=
queues
;
}
public
List
<
MessageQueue
>
getQueues
()
{
return
m_queues
;
}
public
boolean
isIn
(
long
timestamp
)
{
return
timestamp
>=
m_startTime
&&
timestamp
<
m_endTime
;
}
}
static
class
Task
implements
Runnable
{
private
AnalyzerFactory
m_factory
;
private
MessageAnalyzer
m_analyzer
;
private
MessageQueue
m_queue
;
public
Task
(
AnalyzerFactory
factory
,
MessageAnalyzer
analyzer
,
MessageQueue
queue
)
{
m_factory
=
factory
;
m_analyzer
=
analyzer
;
m_queue
=
queue
;
}
public
MessageQueue
getQueue
()
{
return
m_queue
;
}
public
void
run
()
{
m_analyzer
.
analyze
(
m_queue
);
m_factory
.
release
(
m_analyzer
);
m_factory
.
release
(
m_queue
);
}
}
}
\ No newline at end of file
cat-consumer/src/main/java/com/dianping/cat/consumer/configuration/ComponentsConfigurator.java
浏览文件 @
5a5632d0
...
...
@@ -15,6 +15,7 @@ import com.dianping.cat.consumer.transaction.TransactionReportAnalyzer;
import
com.dianping.cat.message.spi.MessageConsumer
;
import
com.dianping.cat.message.spi.MessageManager
;
import
com.dianping.cat.message.spi.MessageQueue
;
import
com.dianping.cat.message.spi.MessageStorage
;
import
com.site.lookup.configuration.AbstractResourceConfigurator
;
import
com.site.lookup.configuration.Component
;
...
...
@@ -34,11 +35,14 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
,
E
(
"analyzerNames"
).
value
(
"failure,transaction"
)));
String
failureTypes
=
"Error,RuntimeException,Exception"
;
all
.
add
(
C
(
Handler
.
class
,
"failure-handler"
,
FailureHandler
.
class
)
//
.
config
(
E
(
"failureType"
).
value
(
failureTypes
)));
.
config
(
E
(
"failureType"
).
value
(
failureTypes
))
//
.
req
(
MessageStorage
.
class
,
"html"
));
all
.
add
(
C
(
Handler
.
class
,
"long-url-handler"
,
LongUrlHandler
.
class
)
//
.
config
(
E
(
"threshold"
).
value
(
"2000"
)));
.
config
(
E
(
"threshold"
).
value
(
"2000"
))
//
.
req
(
MessageStorage
.
class
,
"html"
));
all
.
add
(
C
(
FailureReportAnalyzer
.
class
).
is
(
PER_LOOKUP
)
//
.
config
(
E
(
"reportPath"
).
value
(
"target/report/failure"
))
//
...
...
cat-consumer/src/main/java/com/dianping/cat/consumer/failure/FailureReportAnalyzer.java
浏览文件 @
5a5632d0
...
...
@@ -24,8 +24,8 @@ import com.dianping.cat.message.Message;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.message.spi.AbstractMessageAnalyzer
;
import
com.dianping.cat.message.spi.MessageManager
;
import
com.dianping.cat.message.spi.MessageStorage
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.message.spi.internal.DefaultMessageTree
;
import
com.site.helper.Splitters
;
import
com.site.lookup.annotation.Inject
;
...
...
@@ -136,6 +136,14 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
}
public
static
abstract
class
AbstractHandler
implements
Handler
{
@Inject
private
MessageStorage
m_storage
;
public
void
setMessageStorage
(
MessageStorage
storage
)
{
m_storage
=
storage
;
}
protected
Segment
findOrCreateSegment
(
Message
message
,
FailureReport
report
)
{
long
time
=
message
.
getTimestamp
();
long
segmentId
=
time
-
time
%
MINUTE
;
...
...
@@ -161,6 +169,16 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
}
return
result
;
}
private
Entry
getEntry
(
MessageTree
tree
)
{
String
base
=
m_storage
.
getBaseUrl
().
toString
();
String
url
=
m_storage
.
store
(
tree
);
Entry
entry
=
new
Entry
();
entry
.
setPath
(
base
+
url
);
entry
.
setThreadId
(
tree
.
getThreadId
());
return
entry
;
}
}
public
static
class
FailureHandler
extends
AbstractHandler
{
...
...
@@ -168,13 +186,8 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
private
Set
<
String
>
m_failureTypes
;
private
void
addEntry
(
FailureReport
report
,
Message
message
,
MessageTree
tree
)
{
Entry
entry
=
super
.
getEntry
(
tree
);
String
messageId
=
tree
.
getMessageId
();
String
threadId
=
tree
.
getThreadId
();
Entry
entry
=
new
Entry
();
entry
.
setMessageId
(
messageId
);
entry
.
setThreadId
(
threadId
);
entry
.
setText
(
message
.
getName
());
entry
.
setType
(
message
.
getType
());
...
...
@@ -234,15 +247,11 @@ public class FailureReportAnalyzer extends AbstractMessageAnalyzer<FailureReport
Message
message
=
tree
.
getMessage
();
if
(
message
instanceof
Transaction
)
{
String
messageId
=
((
DefaultMessageTree
)
tree
).
getMessageId
();
String
threadId
=
((
DefaultMessageTree
)
tree
).
getThreadId
();
Transaction
t
=
(
Transaction
)
message
;
if
(
t
.
getDuration
()
>
m_threshold
)
{
Entry
entry
=
new
Entry
(
);
Entry
entry
=
super
.
getEntry
(
tree
);
entry
.
setMessageId
(
messageId
);
entry
.
setThreadId
(
threadId
);
entry
.
setText
(
message
.
getType
()
+
message
.
getName
());
entry
.
setType
(
LONG_URL
);
...
...
cat-consumer/src/main/java/com/dianping/cat/consumer/failure/FailureReportStore.java
浏览文件 @
5a5632d0
...
...
@@ -10,8 +10,7 @@ import com.site.helper.Files;
public
class
FailureReportStore
{
private
static
final
SimpleDateFormat
SDF
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
private
static
final
SimpleDateFormat
SDF
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
private
static
final
String
END
=
"\n"
;
...
...
@@ -19,8 +18,7 @@ public class FailureReportStore {
try
{
Files
.
forIO
().
writeTo
(
file
,
getStoreString
(
report
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
String
.
format
(
"Unable to create file %s!"
,
file
),
e
);
throw
new
RuntimeException
(
String
.
format
(
"Unable to create file %s!"
,
file
),
e
);
}
}
...
...
@@ -32,13 +30,10 @@ public class FailureReportStore {
String
jsonString
=
jsonBuilder
.
getString
();
result
.
append
(
"<html>"
).
append
(
END
).
append
(
"<head>"
).
append
(
END
)
.
append
(
"<title>"
).
append
(
END
).
append
(
"Failure Report "
)
.
append
(
"From "
).
append
(
SDF
.
format
(
report
.
getStartTime
()))
.
append
(
" To "
).
append
(
SDF
.
format
(
report
.
getEndTime
()))
.
append
(
END
).
append
(
"</title>"
).
append
(
END
).
append
(
"<body>"
)
.
append
(
END
).
append
(
jsonString
).
append
(
"</body>"
).
append
(
END
)
.
append
(
"</html>"
).
append
(
END
);
result
.
append
(
"<html>"
).
append
(
END
).
append
(
"<head>"
).
append
(
END
).
append
(
"<title>"
).
append
(
END
).
append
(
"Failure Report "
).
append
(
"From "
).
append
(
SDF
.
format
(
report
.
getStartTime
())).
append
(
" To "
).
append
(
SDF
.
format
(
report
.
getEndTime
())).
append
(
END
).
append
(
"</title>"
).
append
(
END
).
append
(
"<body>"
).
append
(
END
)
.
append
(
jsonString
).
append
(
"</body>"
).
append
(
END
).
append
(
"</html>"
).
append
(
END
);
return
result
.
toString
();
}
}
cat-consumer/src/main/resources/META-INF/dal/model/failure-report-codegen.xml
浏览文件 @
5a5632d0
<model>
<entity
name=
"failure-report"
root=
"true"
>
<attribute
name=
"domain"
value-type=
"String"
/>
<attribute
name=
"baseUrl"
value-type=
"String"
/>
<attribute
name=
"startTime"
value-type=
"Date"
format=
"yyyy-MM-dd HH:mm:ss"
/>
<attribute
name=
"endTime"
value-type=
"Date"
format=
"yyyy-MM-dd HH:mm:ss"
/>
<entity-ref
name=
"machines"
/>
...
...
@@ -20,7 +21,7 @@
</entity>
<entity
name=
"entry"
>
<attribute
name=
"type"
value-type=
"String"
/>
<attribute
name=
"
messageId
"
value-type=
"String"
/>
<attribute
name=
"
path
"
value-type=
"String"
/>
<attribute
name=
"threadId"
value-type=
"String"
/>
<element
name=
"text"
value-type=
"String"
text=
"true"
/>
</entity>
...
...
cat-consumer/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
5a5632d0
...
...
@@ -32,6 +32,12 @@
<configuration>
<failureType>
Error,RuntimeException,Exception
</failureType>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageStorage
</role>
<role-hint>
html
</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.consumer.failure.FailureReportAnalyzer$Handler
</role>
...
...
@@ -40,6 +46,12 @@
<configuration>
<threshold>
2000
</threshold>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageStorage
</role>
<role-hint>
html
</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.consumer.failure.FailureReportAnalyzer
</role>
...
...
cat-home/src/main/webapp/js/failure.js
浏览文件 @
5a5632d0
...
...
@@ -86,7 +86,7 @@ function getIndex(object, array) {
function
getUrl
(
type
,
text
,
messageId
)
{
if
(
type
==
'
RuntimeException
'
)
{
return
'
<a target=
\'
_blank
\'
style=
\'
background:red;
\'
href=
\'
w
ww.dianping.com
/messageId=
'
return
'
<a target=
\'
_blank
\'
style=
\'
background:red;
\'
href=
\'
w/messageId=
'
+
messageId
+
'
\'
>
'
+
text
+
'
</a>
'
;
}
else
if
(
type
==
'
Exception
'
)
{
return
'
<a target=
\'
_blank
\'
style=
\'
background:#FFFF00;
\'
href=
\'
www.dianping.com/messageId=
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录