Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
460a1bb3
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,发现更多精彩内容 >>
提交
460a1bb3
编写于
1月 28, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
log view enhancement
上级
0b308eae
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
140 addition
and
58 deletion
+140
-58
cat-consumer/src/main/java/com/dianping/cat/consumer/configuration/ComponentsConfigurator.java
...ng/cat/consumer/configuration/ComponentsConfigurator.java
+0
-1
cat-consumer/src/main/resources/META-INF/plexus/components.xml
...onsumer/src/main/resources/META-INF/plexus/components.xml
+0
-1
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
...dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
+24
-1
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessageHandler.java
...nping/cat/message/spi/internal/DefaultMessageHandler.java
+5
-1
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessagePathBuilder.java
...g/cat/message/spi/internal/DefaultMessagePathBuilder.java
+1
-1
cat-home/src/main/java/com/dianping/cat/configuration/ComponentsConfigurator.java
...om/dianping/cat/configuration/ComponentsConfigurator.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/ReportPage.java
...ome/src/main/java/com/dianping/cat/report/ReportPage.java
+49
-40
cat-home/src/main/java/com/dianping/cat/report/page/logview/Handler.java
...in/java/com/dianping/cat/report/page/logview/Handler.java
+36
-6
cat-home/src/main/java/com/dianping/cat/servlet/CatServlet.java
...me/src/main/java/com/dianping/cat/servlet/CatServlet.java
+7
-1
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+7
-0
cat-home/src/main/resources/META-INF/wizard/webapp/wizard.xml
...home/src/main/resources/META-INF/wizard/webapp/wizard.xml
+3
-3
cat-home/src/main/webapp/WEB-INF/tags/body.tag
cat-home/src/main/webapp/WEB-INF/tags/body.tag
+1
-1
cat-home/src/main/webapp/jsp/report/logview.jsp
cat-home/src/main/webapp/jsp/report/logview.jsp
+6
-1
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/configuration/ComponentsConfigurator.java
浏览文件 @
460a1bb3
...
...
@@ -30,7 +30,6 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
MessageConsumer
.
class
,
"realtime"
,
RealtimeConsumer
.
class
)
//
.
req
(
AnalyzerFactory
.
class
).
config
(
E
(
"consumerId"
).
value
(
"realtime"
)
//
,
E
(
"domain"
).
value
(
"Review"
)
//
,
E
(
"extraTime"
).
value
(
"300000"
)
//
,
E
(
"analyzerNames"
).
value
(
"failure,transaction"
)));
...
...
cat-consumer/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
460a1bb3
...
...
@@ -15,7 +15,6 @@
<implementation>
com.dianping.cat.consumer.RealtimeConsumer
</implementation>
<configuration>
<consumerId>
realtime
</consumerId>
<domain>
Review
</domain>
<extraTime>
300000
</extraTime>
<analyzerNames>
failure,transaction
</analyzerNames>
</configuration>
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/consumer/DumpToHtmlConsumer.java
浏览文件 @
460a1bb3
...
...
@@ -4,6 +4,10 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
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
;
import
org.jboss.netty.buffer.ChannelBuffer
;
import
org.jboss.netty.buffer.ChannelBuffers
;
...
...
@@ -13,24 +17,30 @@ import com.dianping.cat.message.spi.MessagePathBuilder;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.site.lookup.annotation.Inject
;
public
class
DumpToHtmlConsumer
implements
MessageConsumer
{
public
class
DumpToHtmlConsumer
implements
MessageConsumer
,
Initializable
,
LogEnabled
{
@Inject
private
MessageCodec
m_codec
;
@Inject
private
MessagePathBuilder
m_builder
;
private
Logger
m_logger
;
@Override
public
void
consume
(
MessageTree
tree
)
{
File
baseDir
=
m_builder
.
getLogViewBaseDir
();
File
file
=
new
File
(
baseDir
,
m_builder
.
getLogViewPath
(
tree
));
FileOutputStream
fos
=
null
;
file
.
getParentFile
().
mkdirs
();
try
{
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
(
8192
);
m_codec
.
encode
(
tree
,
buf
);
fos
=
new
FileOutputStream
(
file
);
buf
.
readInt
();
// get rid of count
buf
.
getBytes
(
buf
.
readerIndex
(),
fos
,
buf
.
readableBytes
());
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
String
.
format
(
"Error when dumping to HTML file(%s)!"
,
file
),
e
);
...
...
@@ -45,6 +55,11 @@ public class DumpToHtmlConsumer implements MessageConsumer {
}
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
String
getConsumerId
()
{
return
"dump-to-file"
;
...
...
@@ -55,4 +70,12 @@ public class DumpToHtmlConsumer implements MessageConsumer {
// no limitation
return
null
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
File
baseDir
=
m_builder
.
getLogViewBaseDir
();
baseDir
.
mkdirs
();
m_logger
.
info
(
String
.
format
(
"Message will be dumpped to %s in HTML."
,
baseDir
));
}
}
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessageHandler.java
浏览文件 @
460a1bb3
...
...
@@ -20,7 +20,7 @@ import com.site.lookup.annotation.Inject;
public
class
DefaultMessageHandler
extends
ContainerHolder
implements
MessageHandler
,
Initializable
,
Runnable
{
@Inject
private
MessageManager
m_manager
;
@Inject
private
MessageConsumerRegistry
m_registry
;
...
...
@@ -77,4 +77,8 @@ public class DefaultMessageHandler extends ContainerHolder implements MessageHan
public
void
setRegistry
(
MessageConsumerRegistry
registry
)
{
m_registry
=
registry
;
}
public
void
shutdown
()
{
m_receiver
.
shutdown
();
}
}
cat-core/src/main/java/com/dianping/cat/message/spi/internal/DefaultMessagePathBuilder.java
浏览文件 @
460a1bb3
...
...
@@ -36,7 +36,7 @@ public class DefaultMessagePathBuilder implements MessagePathBuilder, Initializa
@Override
public
String
getLogViewPath
(
MessageTree
tree
)
{
MessageFormat
format
=
new
MessageFormat
(
"{0,date,yyyyMMdd}/{
1}/{2}
"
);
MessageFormat
format
=
new
MessageFormat
(
"{0,date,yyyyMMdd}/{
0,date,HH}/{1}/{2}.html
"
);
Date
date
=
new
Date
(
tree
.
getMessage
().
getTimestamp
());
String
path
=
format
.
format
(
new
Object
[]
{
date
,
tree
.
getDomain
(),
tree
.
getMessageId
()
});
...
...
cat-home/src/main/java/com/dianping/cat/configuration/ComponentsConfigurator.java
浏览文件 @
460a1bb3
...
...
@@ -17,7 +17,7 @@ public class ComponentsConfigurator extends AbstractWebComponentsConfigurator {
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
MessageConsumerRegistry
.
class
,
DefaultMessageConsumerRegistry
.
class
)
//
.
req
(
MessageConsumer
.
class
,
new
String
[]
{
"realtime"
},
"m_consumers"
));
.
req
(
MessageConsumer
.
class
,
new
String
[]
{
"realtime"
,
"dump-to-html"
},
"m_consumers"
));
defineModuleRegistry
(
all
,
ReportModule
.
class
,
ReportModule
.
class
);
...
...
cat-home/src/main/java/com/dianping/cat/report/ReportPage.java
浏览文件 @
460a1bb3
...
...
@@ -5,59 +5,68 @@ import com.site.web.mvc.annotation.ModuleMeta;
public
enum
ReportPage
implements
Page
{
HOME
(
"home"
,
"Home"
,
true
),
HOME
(
"home"
,
"
home"
,
"
Home"
,
true
),
TRANSACTION
(
"transaction"
,
"Transaction"
,
true
),
TRANSACTION
(
"transaction"
,
"
t"
,
"
Transaction"
,
true
),
FAILURE
(
"failure"
,
"Failure"
,
true
),
FAILURE
(
"failure"
,
"
f"
,
"
Failure"
,
true
),
LOGVIEW
(
"logview"
,
"Logview"
,
true
);
LOGVIEW
(
"logview"
,
"
m"
,
"
Logview"
,
true
);
private
String
m_name
;
private
String
m_name
;
private
String
m_description
;
private
String
m_path
;
private
boolean
m_realPage
;
private
String
m_description
;
private
ReportPage
(
String
name
,
String
description
,
boolean
realPage
)
{
m_name
=
name
;
m_description
=
description
;
m_realPage
=
realPage
;
}
private
boolean
m_realPage
;
public
static
ReportPage
getByName
(
String
name
,
ReportPage
default
Page
)
{
for
(
ReportPage
action
:
ReportPage
.
values
())
{
if
(
action
.
getName
().
equals
(
name
))
{
return
ac
tion
;
}
}
private
ReportPage
(
String
name
,
String
path
,
String
description
,
boolean
real
Page
)
{
m_name
=
name
;
m_path
=
path
;
m_description
=
descrip
tion
;
m_realPage
=
realPage
;
}
return
defaultPage
;
}
public
static
ReportPage
getByName
(
String
name
,
ReportPage
defaultPage
)
{
for
(
ReportPage
action
:
ReportPage
.
values
())
{
if
(
action
.
getName
().
equals
(
name
))
{
return
action
;
}
}
public
String
getName
()
{
return
m_name
;
}
return
defaultPage
;
}
public
String
getDescription
()
{
return
m_description
;
}
public
String
getDescription
()
{
return
m_description
;
}
public
String
getModuleName
()
{
ModuleMeta
meta
=
ReportModule
.
class
.
getAnnotation
(
ModuleMeta
.
class
);
public
String
getModuleName
()
{
ModuleMeta
meta
=
ReportModule
.
class
.
getAnnotation
(
ModuleMeta
.
class
);
if
(
meta
!=
null
)
{
return
meta
.
name
();
}
else
{
return
null
;
}
}
if
(
meta
!=
null
)
{
return
meta
.
name
();
}
else
{
return
null
;
}
}
public
boolean
isRealPage
()
{
return
m_realPage
;
}
@Override
public
String
getName
()
{
return
m_name
;
}
public
ReportPage
[]
getValues
()
{
return
ReportPage
.
values
();
}
@Override
public
String
getPath
()
{
return
m_path
;
}
public
boolean
isRealPage
()
{
return
m_realPage
;
}
public
ReportPage
[]
getValues
()
{
return
ReportPage
.
values
();
}
}
cat-home/src/main/java/com/dianping/cat/report/page/logview/Handler.java
浏览文件 @
460a1bb3
package
com.dianping.cat.report.page.logview
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
com.dianping.cat.message.spi.MessagePathBuilder
;
import
com.dianping.cat.report.ReportPage
;
import
com.ebay.webres.helper.Files
;
import
com.ebay.webres.helper.Joiners
;
import
com.site.lookup.annotation.Inject
;
import
com.site.web.mvc.PageHandler
;
import
com.site.web.mvc.annotation.InboundActionMeta
;
...
...
@@ -16,6 +21,9 @@ public class Handler implements PageHandler<Context> {
@Inject
private
JspViewer
m_jspViewer
;
@Inject
private
MessagePathBuilder
m_pathBuilder
;
@Override
@PayloadMeta
(
Payload
.
class
)
@InboundActionMeta
(
name
=
"m"
)
...
...
@@ -30,12 +38,34 @@ public class Handler implements PageHandler<Context> {
model
.
setAction
(
Action
.
VIEW
);
model
.
setPage
(
ReportPage
.
LOGVIEW
);
Payload
payload
=
ctx
.
getPayload
();
System
.
out
.
println
(
payload
.
getIdentifier
());
System
.
out
.
println
(
Arrays
.
asList
(
payload
.
getPath
()));
String
[]
path
=
payload
.
getPath
();
if
(
path
!=
null
&&
path
.
length
>
0
)
{
File
baseDir
=
m_pathBuilder
.
getLogViewBaseDir
();
String
relativePath
=
Joiners
.
by
(
'/'
).
join
(
path
);
File
file
=
new
File
(
baseDir
,
relativePath
);
if
(
file
.
exists
())
{
byte
[]
content
=
Files
.
forIO
().
readFrom
(
file
);
showHtml
(
ctx
,
content
);
return
;
}
}
m_jspViewer
.
view
(
ctx
,
model
);
}
private
void
showHtml
(
Context
ctx
,
byte
[]
content
)
throws
IOException
{
HttpServletResponse
response
=
ctx
.
getHttpServletResponse
();
ServletOutputStream
out
=
response
.
getOutputStream
();
response
.
setContentLength
(
content
.
length
);
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"utf-8"
);
out
.
write
(
content
);
}
}
cat-home/src/main/java/com/dianping/cat/servlet/CatServlet.java
浏览文件 @
460a1bb3
...
...
@@ -36,9 +36,15 @@ public class CatServlet extends AbstractContainerServlet {
manager
.
initializeServer
(
config
);
DefaultMessageHandler
handler
=
(
DefaultMessageHandler
)
lookup
(
MessageHandler
.
class
);
final
DefaultMessageHandler
handler
=
(
DefaultMessageHandler
)
lookup
(
MessageHandler
.
class
);
new
Thread
(
handler
).
start
();
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
()
{
@Override
public
void
run
()
{
handler
.
shutdown
();
}
});
}
catch
(
Exception
e
)
{
m_exception
=
e
;
throw
new
RuntimeException
(
"Error when initializing CatServlet, "
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
460a1bb3
...
...
@@ -8,6 +8,7 @@
<role>
com.dianping.cat.message.spi.MessageConsumer
</role>
<role-hints>
<role-hint>
realtime
</role-hint>
<role-hint>
dump-to-html
</role-hint>
</role-hints>
<field-name>
m_consumers
</field-name>
</requirement>
...
...
@@ -61,6 +62,9 @@
<role>
com.dianping.cat.consumer.RealtimeConsumer
</role>
<implementation>
com.dianping.cat.consumer.RealtimeConsumer
</implementation>
<requirements>
<requirement>
<role>
org.codehaus.plexus.logging.Logger
</role>
</requirement>
<requirement>
<role>
java.lang.String
</role>
</requirement>
...
...
@@ -106,6 +110,9 @@
<requirement>
<role>
com.dianping.cat.report.page.logview.JspViewer
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.message.spi.MessagePathBuilder
</role>
</requirement>
</requirements>
</component>
<component>
...
...
cat-home/src/main/resources/META-INF/wizard/webapp/wizard.xml
浏览文件 @
460a1bb3
...
...
@@ -2,9 +2,9 @@
<wizard
package=
"com.dianping.cat"
webres=
"true"
>
<module
name=
"report"
path=
"r"
>
<page
name=
"home"
description=
"Home"
default=
"true"
/>
<page
name=
"transaction"
description=
"Transaction"
/>
<page
name=
"failure"
description=
"Failure"
/>
<page
name=
"logview"
description=
"Logview"
/>
<page
name=
"transaction"
path=
"t"
description=
"Transaction"
/>
<page
name=
"failure"
path=
"f"
description=
"Failure"
/>
<page
name=
"logview"
path=
"m"
description=
"Logview"
/>
</module>
</wizard>
cat-home/src/main/webapp/WEB-INF/tags/body.tag
浏览文件 @
460a1bb3
...
...
@@ -18,7 +18,7 @@
<ul
class=
"tabs"
>
<c:forEach
var=
"page"
items=
"${navBar.visiblePages}"
>
<c:if
test=
"${page.realPage}"
>
<li
${
model.page.name =
=
page.name
?
'
class=
"selected"
'
:
''}
><a
href=
"${model.webapp}/${page.moduleName}/${page.
name
}"
>
${page.description}
</a></li>
<li
${
model.page.name =
=
page.name
?
'
class=
"selected"
'
:
''}
><a
href=
"${model.webapp}/${page.moduleName}/${page.
path
}"
>
${page.description}
</a></li>
</c:if>
</c:forEach>
</ul>
...
...
cat-home/src/main/webapp/jsp/report/logview.jsp
浏览文件 @
460a1bb3
<%@ page
contentType=
"text/html; charset=utf-8"
%>
<%@ taglib
prefix=
"a"
uri=
"/WEB-INF/app.tld"
%>
<jsp:useBean
id=
"ctx"
type=
"com.dianping.cat.report.page.logview.Context"
scope=
"request"
/>
<jsp:useBean
id=
"payload"
type=
"com.dianping.cat.report.page.logview.Payload"
scope=
"request"
/>
<jsp:useBean
id=
"model"
type=
"com.dianping.cat.report.page.logview.Model"
scope=
"request"
/>
View of logview page under report
\ No newline at end of file
<a:body>
Sorry, this message had already been archived.
</a:body>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录