Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
75a23219
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,发现更多精彩内容 >>
提交
75a23219
编写于
4月 17, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cat-thread-count to heartbeat and fix getSessionToken() bug
上级
31bdeca8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
12 deletion
+66
-12
cat-core/src/main/java/com/dianping/cat/servlet/CatFilter.java
...ore/src/main/java/com/dianping/cat/servlet/CatFilter.java
+22
-5
cat-core/src/main/java/com/dianping/cat/status/StatusInfoCollector.java
...ain/java/com/dianping/cat/status/StatusInfoCollector.java
+38
-6
cat-core/src/main/resources/META-INF/dal/model/status-codegen.xml
.../src/main/resources/META-INF/dal/model/status-codegen.xml
+3
-0
cat-core/src/main/resources/META-INF/dal/model/status-model.xml
...re/src/main/resources/META-INF/dal/model/status-model.xml
+3
-1
未找到文件。
cat-core/src/main/java/com/dianping/cat/servlet/CatFilter.java
浏览文件 @
75a23219
...
@@ -8,6 +8,7 @@ import javax.servlet.FilterConfig;
...
@@ -8,6 +8,7 @@ import javax.servlet.FilterConfig;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.Cat
;
...
@@ -22,17 +23,15 @@ public class CatFilter implements Filter {
...
@@ -22,17 +23,15 @@ public class CatFilter implements Filter {
public
void
destroy
()
{
public
void
destroy
()
{
}
}
protected
String
getOriginalUrl
(
ServletRequest
request
)
{
return
((
HttpServletRequest
)
request
).
getRequestURI
();
}
@Override
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
ServletException
{
HttpServletRequest
req
=
(
HttpServletRequest
)
request
;
HttpServletRequest
req
=
(
HttpServletRequest
)
request
;
String
sessionToken
=
req
.
getSession
().
getId
();
String
sessionToken
=
getSessionIdFromCookie
(
req
);
// setup for thread local data
// setup for thread local data
Cat
.
setup
(
sessionToken
);
Cat
.
setup
(
sessionToken
);
MessageProducer
cat
=
Cat
.
getProducer
();
MessageProducer
cat
=
Cat
.
getProducer
();
Transaction
t
=
cat
.
newTransaction
(
CatConstants
.
TYPE_URL
,
getOriginalUrl
(
request
));
Transaction
t
=
cat
.
newTransaction
(
CatConstants
.
TYPE_URL
,
getOriginalUrl
(
request
));
...
@@ -70,6 +69,24 @@ public class CatFilter implements Filter {
...
@@ -70,6 +69,24 @@ public class CatFilter implements Filter {
}
}
}
}
protected
String
getOriginalUrl
(
ServletRequest
request
)
{
return
((
HttpServletRequest
)
request
).
getRequestURI
();
}
private
String
getSessionIdFromCookie
(
HttpServletRequest
req
)
{
Cookie
[]
cookies
=
req
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
Cookie
cookie
:
cookies
)
{
if
(
"JSESSIONID"
.
equalsIgnoreCase
(
cookie
.
getName
()))
{
return
cookie
.
getValue
();
}
}
}
return
null
;
}
@Override
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
}
}
...
...
cat-core/src/main/java/com/dianping/cat/status/StatusInfoCollector.java
浏览文件 @
75a23219
...
@@ -6,9 +6,11 @@ import java.lang.management.ManagementFactory;
...
@@ -6,9 +6,11 @@ import java.lang.management.ManagementFactory;
import
java.lang.management.MemoryMXBean
;
import
java.lang.management.MemoryMXBean
;
import
java.lang.management.OperatingSystemMXBean
;
import
java.lang.management.OperatingSystemMXBean
;
import
java.lang.management.RuntimeMXBean
;
import
java.lang.management.RuntimeMXBean
;
import
java.lang.management.ThreadInfo
;
import
java.lang.management.ThreadMXBean
;
import
java.lang.management.ThreadMXBean
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.TreeMap
;
import
com.dianping.cat.message.spi.MessageStatistics
;
import
com.dianping.cat.message.spi.MessageStatistics
;
import
com.dianping.cat.status.model.entity.DiskSpaceInfo
;
import
com.dianping.cat.status.model.entity.DiskSpaceInfo
;
...
@@ -18,7 +20,7 @@ import com.dianping.cat.status.model.entity.MessageInfo;
...
@@ -18,7 +20,7 @@ import com.dianping.cat.status.model.entity.MessageInfo;
import
com.dianping.cat.status.model.entity.OsInfo
;
import
com.dianping.cat.status.model.entity.OsInfo
;
import
com.dianping.cat.status.model.entity.RuntimeInfo
;
import
com.dianping.cat.status.model.entity.RuntimeInfo
;
import
com.dianping.cat.status.model.entity.StatusInfo
;
import
com.dianping.cat.status.model.entity.StatusInfo
;
import
com.dianping.cat.status.model.entity.ThreadInfo
;
import
com.dianping.cat.status.model.entity.Thread
s
Info
;
import
com.dianping.cat.status.model.transform.BaseVisitor
;
import
com.dianping.cat.status.model.transform.BaseVisitor
;
class
StatusInfoCollector
extends
BaseVisitor
{
class
StatusInfoCollector
extends
BaseVisitor
{
...
@@ -28,6 +30,18 @@ class StatusInfoCollector extends BaseVisitor {
...
@@ -28,6 +30,18 @@ class StatusInfoCollector extends BaseVisitor {
m_statistics
=
statistics
;
m_statistics
=
statistics
;
}
}
int
countThreadsByPrefix
(
ThreadInfo
[]
threads
,
String
prefix
)
{
int
count
=
0
;
for
(
ThreadInfo
thread
:
threads
)
{
if
(
thread
.
getThreadName
().
startsWith
(
prefix
))
{
count
++;
}
}
return
count
;
}
long
getGcCount
(
List
<
GarbageCollectorMXBean
>
mxbeans
)
{
long
getGcCount
(
List
<
GarbageCollectorMXBean
>
mxbeans
)
{
long
count
=
0
;
long
count
=
0
;
...
@@ -52,6 +66,23 @@ class StatusInfoCollector extends BaseVisitor {
...
@@ -52,6 +66,23 @@ class StatusInfoCollector extends BaseVisitor {
return
time
;
return
time
;
}
}
String
getThreadDump
(
ThreadInfo
[]
threads
)
{
StringBuilder
sb
=
new
StringBuilder
(
32768
);
int
index
=
1
;
TreeMap
<
String
,
ThreadInfo
>
sortedThreads
=
new
TreeMap
<
String
,
ThreadInfo
>();
for
(
ThreadInfo
thread
:
threads
)
{
sortedThreads
.
put
(
thread
.
getThreadName
(),
thread
);
}
for
(
ThreadInfo
thread
:
sortedThreads
.
values
())
{
sb
.
append
(
index
++).
append
(
": "
).
append
(
thread
);
}
return
sb
.
toString
();
}
boolean
isInstanceOfInterface
(
Class
<?>
clazz
,
String
interfaceName
)
{
boolean
isInstanceOfInterface
(
Class
<?>
clazz
,
String
interfaceName
)
{
if
(
clazz
==
Object
.
class
)
{
if
(
clazz
==
Object
.
class
)
{
return
false
;
return
false
;
...
@@ -148,22 +179,23 @@ class StatusInfoCollector extends BaseVisitor {
...
@@ -148,22 +179,23 @@ class StatusInfoCollector extends BaseVisitor {
status
.
setDiskSpace
(
new
DiskSpaceInfo
());
status
.
setDiskSpace
(
new
DiskSpaceInfo
());
status
.
setRuntime
(
new
RuntimeInfo
());
status
.
setRuntime
(
new
RuntimeInfo
());
status
.
setMemory
(
new
MemoryInfo
());
status
.
setMemory
(
new
MemoryInfo
());
status
.
setThread
(
new
ThreadInfo
());
status
.
setThread
(
new
Thread
s
Info
());
status
.
setMessage
(
new
MessageInfo
());
status
.
setMessage
(
new
MessageInfo
());
super
.
visitStatus
(
status
);
super
.
visitStatus
(
status
);
}
}
@Override
@Override
public
void
visitThread
(
ThreadInfo
thread
)
{
public
void
visitThread
(
Thread
s
Info
thread
)
{
ThreadMXBean
bean
=
ManagementFactory
.
getThreadMXBean
();
ThreadMXBean
bean
=
ManagementFactory
.
getThreadMXBean
();
ThreadInfo
[]
threads
=
bean
.
dumpAllThreads
(
true
,
true
);
thread
.
setCount
(
bean
.
getThreadCount
());
thread
.
setCount
(
bean
.
getThreadCount
());
thread
.
setDaemonCount
(
bean
.
getDaemonThreadCount
());
thread
.
setDaemonCount
(
bean
.
getDaemonThreadCount
());
thread
.
setPeekCount
(
bean
.
getPeakThreadCount
());
thread
.
setPeekCount
(
bean
.
getPeakThreadCount
());
thread
.
setTotalStartedCount
(
bean
.
getTotalStartedThreadCount
());
thread
.
setTotalStartedCount
(
bean
.
getTotalStartedThreadCount
());
thread
.
setCatThreadCount
(
countThreadsByPrefix
(
threads
,
"Cat-"
));
// TODO remove below
thread
.
setPigeonThreadCount
(
countThreadsByPrefix
(
threads
,
"Pigeon-"
));
// System.out.println(Arrays.asList(bean.dumpAllThreads(true, true)
));
thread
.
setDump
(
getThreadDump
(
threads
));
}
}
}
}
\ No newline at end of file
cat-core/src/main/resources/META-INF/dal/model/status-codegen.xml
浏览文件 @
75a23219
...
@@ -47,6 +47,9 @@
...
@@ -47,6 +47,9 @@
<attribute
name=
"daemon-count"
value-type=
"int"
/>
<attribute
name=
"daemon-count"
value-type=
"int"
/>
<attribute
name=
"peek-count"
value-type=
"int"
/>
<attribute
name=
"peek-count"
value-type=
"int"
/>
<attribute
name=
"total-started-count"
value-type=
"int"
/>
<attribute
name=
"total-started-count"
value-type=
"int"
/>
<attribute
name=
"cat-thread-count"
value-type=
"int"
/>
<attribute
name=
"pigeon-thread-count"
value-type=
"int"
/>
<element
name=
"dump"
value-type=
"String"
/>
</entity>
</entity>
<entity
name=
"message"
>
<entity
name=
"message"
>
<attribute
name=
"produced"
value-type=
"int"
/>
<attribute
name=
"produced"
value-type=
"int"
/>
...
...
cat-core/src/main/resources/META-INF/dal/model/status-model.xml
浏览文件 @
75a23219
...
@@ -32,10 +32,12 @@
...
@@ -32,10 +32,12 @@
<attribute
name=
"count"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"count"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"time"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"time"
value-type=
"long"
primitive=
"true"
/>
</entity>
</entity>
<entity
name=
"thread"
class-name=
"ThreadInfo"
>
<entity
name=
"thread"
class-name=
"Thread
s
Info"
>
<attribute
name=
"count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"daemon-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"daemon-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"peek-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"peek-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"cat-thread-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"pigeon-thread-count"
value-type=
"int"
primitive=
"true"
/>
<attribute
name=
"total-started-count"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"total-started-count"
value-type=
"long"
primitive=
"true"
/>
</entity>
</entity>
<entity
name=
"message"
class-name=
"MessageInfo"
>
<entity
name=
"message"
class-name=
"MessageInfo"
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录