Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
55b39b7e
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,发现更多精彩内容 >>
提交
55b39b7e
编写于
4月 24, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust heartbeat model
上级
d14ef1f0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
159 addition
and
99 deletion
+159
-99
cat-consumer/src/main/java/com/dianping/cat/consumer/heartbeat/HeartbeatAnalyzer.java
...om/dianping/cat/consumer/heartbeat/HeartbeatAnalyzer.java
+72
-45
cat-core/src/main/java/com/dianping/cat/configuration/ServerConfigManager.java
...a/com/dianping/cat/configuration/ServerConfigManager.java
+26
-20
cat-core/src/main/java/com/dianping/cat/status/StatusInfoCollector.java
...ain/java/com/dianping/cat/status/StatusInfoCollector.java
+29
-14
cat-core/src/main/resources/META-INF/dal/model/status-codegen.xml
.../src/main/resources/META-INF/dal/model/status-codegen.xml
+9
-5
cat-core/src/main/resources/META-INF/dal/model/status-model.xml
...re/src/main/resources/META-INF/dal/model/status-model.xml
+13
-9
cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/FileSystemManager.java
.../java/com/dianping/cat/hadoop/hdfs/FileSystemManager.java
+10
-6
未找到文件。
cat-consumer/src/main/java/com/dianping/cat/consumer/heartbeat/HeartbeatAnalyzer.java
浏览文件 @
55b39b7e
...
...
@@ -24,7 +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.MessageTree
;
import
com.dianping.cat.status.model.entity.DiskSpaceInfo
;
import
com.dianping.cat.status.model.entity.DiskInfo
;
import
com.dianping.cat.status.model.entity.DiskVolumeInfo
;
import
com.dianping.cat.status.model.entity.MemoryInfo
;
import
com.dianping.cat.status.model.entity.MessageInfo
;
import
com.dianping.cat.status.model.entity.StatusInfo
;
...
...
@@ -79,11 +80,79 @@ public class HeartbeatAnalyzer extends AbstractMessageAnalyzer<HeartbeatReport>
return
report
;
}
private
DiskVolumeInfo
getDefaultDiskVolume
(
DiskInfo
diskInfo
)
{
DiskVolumeInfo
root
=
null
;
for
(
DiskVolumeInfo
volume
:
diskInfo
.
getDiskVolumes
())
{
String
id
=
volume
.
getId
();
if
(
id
.
startsWith
(
"/data"
))
{
// for production
return
volume
;
}
else
if
(
id
.
equals
(
"/"
))
{
root
=
volume
;
}
}
if
(
root
!=
null
)
{
return
root
;
}
else
{
// return first system volume for Windows
return
diskInfo
.
getDiskVolumes
().
get
(
0
);
}
}
@Override
public
Set
<
String
>
getDomains
()
{
return
m_reports
.
keySet
();
}
private
Period
getHeartBeatInfo
(
Heartbeat
heartbeat
)
{
String
xml
=
(
String
)
heartbeat
.
getData
();
StatusInfo
info
=
null
;
try
{
info
=
new
com
.
dianping
.
cat
.
status
.
model
.
transform
.
DefaultXmlParser
().
parse
(
xml
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
heartbeat
.
getTimestamp
());
int
minute
=
cal
.
get
(
Calendar
.
MINUTE
);
Period
period
=
new
Period
(
minute
);
try
{
ThreadsInfo
thread
=
info
.
getThread
();
period
.
setThreadCount
(
thread
.
getCount
());
period
.
setDaemonCount
(
thread
.
getDaemonCount
());
period
.
setTotalStartedCount
((
int
)
thread
.
getTotalStartedCount
());
period
.
setCatThreadCount
(
thread
.
getCatThreadCount
());
period
.
setPigeonThreadCount
(
thread
.
getPigeonThreadCount
());
MessageInfo
catInfo
=
info
.
getMessage
();
period
.
setCatMessageProduced
((
int
)
catInfo
.
getProduced
());
period
.
setCatMessageOverflow
((
int
)
catInfo
.
getOverflowed
());
period
.
setCatMessageSize
(
catInfo
.
getBytes
());
MemoryInfo
memeryInfo
=
info
.
getMemory
();
DiskInfo
diskInfo
=
info
.
getDisk
();
DiskVolumeInfo
volumeInfo
=
getDefaultDiskVolume
(
diskInfo
);
period
.
setGcCount
((
int
)
info
.
getMemory
().
getGc
().
getCount
());
period
.
setHeapUsage
(
memeryInfo
.
getHeapUsage
());
period
.
setNoneHeapUsage
(
memeryInfo
.
getNonHeapUsage
());
period
.
setDiskFree
(
volumeInfo
.
getFree
());
period
.
setDiskUseable
(
volumeInfo
.
getUsable
());
period
.
setSystemLoadAverage
(
info
.
getOs
().
getSystemLoadAverage
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
period
;
}
public
HeartbeatReport
getReport
(
String
domain
)
{
HeartbeatReport
report
=
m_reports
.
get
(
domain
);
...
...
@@ -143,11 +212,12 @@ public class HeartbeatAnalyzer extends AbstractMessageAnalyzer<HeartbeatReport>
private
int
processHeartbeat
(
HeartbeatReport
report
,
Heartbeat
heartbeat
,
MessageTree
tree
)
{
String
ip
=
tree
.
getIpAddress
();
Period
period
=
getHeartBeatInfo
(
heartbeat
);
if
(
period
!=
null
)
{
report
.
findOrCreateMachine
(
ip
).
getPeriods
().
add
(
period
);
}
return
1
;
}
...
...
@@ -176,49 +246,6 @@ public class HeartbeatAnalyzer extends AbstractMessageAnalyzer<HeartbeatReport>
loadReports
();
}
private
Period
getHeartBeatInfo
(
Heartbeat
heartbeat
)
{
String
xml
=
(
String
)
heartbeat
.
getData
();
StatusInfo
info
=
null
;
try
{
info
=
new
com
.
dianping
.
cat
.
status
.
model
.
transform
.
DefaultXmlParser
().
parse
(
xml
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTimeInMillis
(
heartbeat
.
getTimestamp
());
int
minute
=
cal
.
get
(
Calendar
.
MINUTE
);
Period
period
=
new
Period
(
minute
);
try
{
ThreadsInfo
thread
=
info
.
getThread
();
period
.
setThreadCount
(
thread
.
getCount
());
period
.
setDaemonCount
(
thread
.
getDaemonCount
());
period
.
setTotalStartedCount
((
int
)
thread
.
getTotalStartedCount
());
period
.
setCatThreadCount
(
thread
.
getCatThreadCount
());
period
.
setPigeonThreadCount
(
thread
.
getPigeonThreadCount
());
MessageInfo
catInfo
=
info
.
getMessage
();
period
.
setCatMessageProduced
((
int
)
catInfo
.
getProduced
());
period
.
setCatMessageOverflow
((
int
)
catInfo
.
getOverflowed
());
period
.
setCatMessageSize
(
catInfo
.
getBytes
());
DiskSpaceInfo
diskInfo
=
info
.
getDiskSpace
();
MemoryInfo
memeryInfo
=
info
.
getMemory
();
period
.
setGcCount
((
int
)
info
.
getMemory
().
getGc
().
getCount
());
period
.
setHeapUsage
(
memeryInfo
.
getHeapUsage
());
period
.
setNoneHeapUsage
(
memeryInfo
.
getNonHeapUsage
());
period
.
setDiskFree
(
diskInfo
.
getFree
());
period
.
setDiskUseable
(
diskInfo
.
getUsable
());
period
.
setSystemLoadAverage
(
info
.
getOs
().
getSystemLoadAverage
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
period
;
}
private
void
storeMessage
(
MessageTree
tree
)
{
String
messageId
=
tree
.
getMessageId
();
String
domain
=
tree
.
getDomain
();
...
...
cat-core/src/main/java/com/dianping/cat/configuration/ServerConfigManager.java
浏览文件 @
55b39b7e
...
...
@@ -25,7 +25,7 @@ import com.site.helper.Threads.Task;
public
class
ServerConfigManager
implements
LogEnabled
{
private
ServerConfig
m_config
;
private
List
<
Listener
>
m_listeners
=
new
ArrayList
<
ServerConfigManager
.
Listener
>();
private
List
<
ServiceConfigSupport
>
m_listeners
=
new
ArrayList
<
ServerConfigManager
.
ServiceConfigSupport
>();
private
Logger
m_logger
;
...
...
@@ -189,6 +189,12 @@ public class ServerConfigManager implements LogEnabled {
}
}
public
void
onRefresh
(
ServiceConfigSupport
listener
)
{
if
(!
m_listeners
.
contains
(
listener
))
{
m_listeners
.
add
(
listener
);
}
}
private
long
toLong
(
String
str
,
long
defaultValue
)
{
long
value
=
0
;
int
len
=
str
==
null
?
0
:
str
.
length
();
...
...
@@ -212,14 +218,8 @@ public class ServerConfigManager implements LogEnabled {
}
}
public
void
onRefresh
(
Listener
listener
)
{
if
(!
m_listeners
.
contains
(
listener
))
{
m_listeners
.
add
(
listener
);
}
}
public
static
interface
Listener
{
public
void
onRefresh
(
ServerConfigManager
manager
);
public
static
interface
ServerConfigKey
{
public
void
add
(
String
section
);
}
static
class
ServerConfigReloader
implements
Task
{
...
...
@@ -231,6 +231,17 @@ public class ServerConfigManager implements LogEnabled {
m_file
=
file
;
}
@Override
public
String
getName
()
{
return
"ServerConfigReloader"
;
}
private
boolean
isActive
()
{
synchronized
(
this
)
{
return
m_active
;
}
}
@Override
public
void
run
()
{
while
(
isActive
())
{
...
...
@@ -246,17 +257,6 @@ public class ServerConfigManager implements LogEnabled {
}
}
private
boolean
isActive
()
{
synchronized
(
this
)
{
return
m_active
;
}
}
@Override
public
String
getName
()
{
return
"ServerConfigReloader"
;
}
@Override
public
void
shutdown
()
{
synchronized
(
this
)
{
...
...
@@ -264,4 +264,10 @@ public class ServerConfigManager implements LogEnabled {
}
}
}
public
static
interface
ServiceConfigSupport
{
public
void
buildKey
(
ServerConfigManager
manager
,
ServerConfigKey
key
);
public
void
configure
(
ServerConfigManager
manager
,
boolean
firstTime
);
}
}
cat-core/src/main/java/com/dianping/cat/status/StatusInfoCollector.java
浏览文件 @
55b39b7e
...
...
@@ -13,7 +13,8 @@ import java.util.List;
import
java.util.TreeMap
;
import
com.dianping.cat.message.spi.MessageStatistics
;
import
com.dianping.cat.status.model.entity.DiskSpaceInfo
;
import
com.dianping.cat.status.model.entity.DiskInfo
;
import
com.dianping.cat.status.model.entity.DiskVolumeInfo
;
import
com.dianping.cat.status.model.entity.GcInfo
;
import
com.dianping.cat.status.model.entity.MemoryInfo
;
import
com.dianping.cat.status.model.entity.MessageInfo
;
...
...
@@ -30,20 +31,22 @@ class StatusInfoCollector extends BaseVisitor {
m_statistics
=
statistics
;
}
int
countThreadsByPrefix
(
ThreadInfo
[]
threads
,
String
prefix
)
{
int
countThreadsByPrefix
(
ThreadInfo
[]
threads
,
String
...
prefixes
)
{
int
count
=
0
;
for
(
ThreadInfo
thread
:
threads
)
{
if
(
thread
.
getThreadName
().
startsWith
(
prefix
))
{
count
++;
for
(
String
prefix
:
prefixes
)
{
if
(
thread
.
getThreadName
().
startsWith
(
prefix
))
{
count
++;
}
}
}
return
count
;
}
long
getGcCount
(
List
<
GarbageCollectorMXBean
>
mxbeans
)
{
long
count
=
0
;
int
getGcCount
(
List
<
GarbageCollectorMXBean
>
mxbeans
)
{
int
count
=
0
;
for
(
GarbageCollectorMXBean
mxbean
:
mxbeans
)
{
if
(
mxbean
.
isValid
())
{
...
...
@@ -102,12 +105,23 @@ class StatusInfoCollector extends BaseVisitor {
}
@Override
public
void
visitDiskSpace
(
DiskSpaceInfo
diskSpace
)
{
File
workingDir
=
new
File
(
"."
);
public
void
visitDisk
(
DiskInfo
disk
)
{
File
[]
roots
=
File
.
listRoots
();
for
(
File
root:
roots
)
{
disk
.
addDiskVolume
(
new
DiskVolumeInfo
(
root
.
getAbsolutePath
()));
}
super
.
visitDisk
(
disk
);
}
@Override
public
void
visitDiskVolume
(
DiskVolumeInfo
diskVolume
)
{
File
volume
=
new
File
(
diskVolume
.
getId
());
disk
Space
.
setTotal
(
workingDir
.
getTotalSpace
());
disk
Space
.
setFree
(
workingDir
.
getFreeSpace
());
disk
Space
.
setUsable
(
workingDir
.
getUsableSpace
());
disk
Volume
.
setTotal
(
volume
.
getTotalSpace
());
disk
Volume
.
setFree
(
volume
.
getFreeSpace
());
disk
Volume
.
setUsable
(
volume
.
getUsableSpace
());
}
@Override
...
...
@@ -176,7 +190,7 @@ class StatusInfoCollector extends BaseVisitor {
public
void
visitStatus
(
StatusInfo
status
)
{
status
.
setTimestamp
(
new
Date
());
status
.
setOs
(
new
OsInfo
());
status
.
setDisk
Space
(
new
DiskSpace
Info
());
status
.
setDisk
(
new
Disk
Info
());
status
.
setRuntime
(
new
RuntimeInfo
());
status
.
setMemory
(
new
MemoryInfo
());
status
.
setThread
(
new
ThreadsInfo
());
...
...
@@ -193,9 +207,10 @@ class StatusInfoCollector extends BaseVisitor {
thread
.
setCount
(
bean
.
getThreadCount
());
thread
.
setDaemonCount
(
bean
.
getDaemonThreadCount
());
thread
.
setPeekCount
(
bean
.
getPeakThreadCount
());
thread
.
setTotalStartedCount
(
bean
.
getTotalStartedThreadCount
());
thread
.
setTotalStartedCount
(
(
int
)
bean
.
getTotalStartedThreadCount
());
thread
.
setCatThreadCount
(
countThreadsByPrefix
(
threads
,
"Cat-"
));
thread
.
setPigeonThreadCount
(
countThreadsByPrefix
(
threads
,
"Pigeon-"
));
thread
.
setPigeonThreadCount
(
countThreadsByPrefix
(
threads
,
"Pigeon-"
,
"DPSF-"
,
"Netty-"
,
"Client-ResponseProcessor"
));
thread
.
setDump
(
getThreadDump
(
threads
));
}
}
\ No newline at end of file
cat-core/src/main/resources/META-INF/dal/model/status-codegen.xml
浏览文件 @
55b39b7e
...
...
@@ -4,7 +4,7 @@
<attribute
name=
"timestamp"
value-type=
"Date"
format=
"yyyy-MM-dd HH:mm:ss.SSS"
/>
<entity-ref
name=
"runtime"
/>
<entity-ref
name=
"os"
/>
<entity-ref
name=
"disk
-space
"
/>
<entity-ref
name=
"disk"
/>
<entity-ref
name=
"memory"
/>
<entity-ref
name=
"thread"
/>
<entity-ref
name=
"message"
/>
...
...
@@ -26,10 +26,14 @@
<attribute
name=
"total-swap-space"
value-type=
"int"
/>
<attribute
name=
"free-swap-space"
value-type=
"int"
/>
</entity>
<entity
name=
"disk-space"
>
<attribute
name=
"total"
value-type=
"int"
/>
<attribute
name=
"free"
value-type=
"int"
/>
<attribute
name=
"usable"
value-type=
"int"
/>
<entity
name=
"disk"
>
<entity-ref
name=
"disk-volume"
type=
"list"
names=
"disk-volumes"
/>
</entity>
<entity
name=
"disk-volume"
>
<attribute
name=
"id"
value-type=
"String"
/>
<attribute
name=
"total"
value-type=
"long"
/>
<attribute
name=
"free"
value-type=
"long"
/>
<attribute
name=
"usable"
value-type=
"long"
/>
</entity>
<entity
name=
"memory"
>
<attribute
name=
"total"
value-type=
"int"
/>
...
...
cat-core/src/main/resources/META-INF/dal/model/status-model.xml
浏览文件 @
55b39b7e
...
...
@@ -16,11 +16,15 @@
<attribute
name=
"total-swap-space"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"free-swap-space"
value-type=
"long"
primitive=
"true"
/>
</entity>
<entity
name=
"disk-space"
class-name=
"DiskSpaceInfo"
>
<attribute
name=
"total"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"free"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"usable"
value-type=
"long"
primitive=
"true"
/>
</entity>
<entity
name=
"disk"
class-name=
"DiskInfo"
>
<entity-ref
name=
"disk-volume"
list=
"list"
names=
"disk-volumes"
/>
</entity>
<entity
name=
"disk-volume"
class-name=
"DiskVolumeInfo"
>
<attribute
name=
"id"
value-type=
"String"
key=
"true"
/>
<attribute
name=
"total"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"free"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"usable"
value-type=
"long"
primitive=
"true"
/>
</entity>
<entity
name=
"memory"
class-name=
"MemoryInfo"
>
<attribute
name=
"total"
value-type=
"long"
primitive=
"true"
/>
<attribute
name=
"free"
value-type=
"long"
primitive=
"true"
/>
...
...
@@ -29,16 +33,16 @@
<entity-ref
name=
"gc"
/>
</entity>
<entity
name=
"gc"
class-name=
"GcInfo"
>
<attribute
name=
"count"
value-type=
"
long
"
primitive=
"true"
/>
<attribute
name=
"count"
value-type=
"
int
"
primitive=
"true"
/>
<attribute
name=
"time"
value-type=
"long"
primitive=
"true"
/>
</entity>
<entity
name=
"thread"
class-name=
"ThreadsInfo"
>
<attribute
name=
"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=
"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=
"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=
"
int
"
primitive=
"true"
/>
</entity>
<entity
name=
"message"
class-name=
"MessageInfo"
>
<attribute
name=
"produced"
value-type=
"long"
primitive=
"true"
/>
...
...
cat-hadoop/src/main/java/com/dianping/cat/hadoop/hdfs/FileSystemManager.java
浏览文件 @
55b39b7e
...
...
@@ -86,7 +86,8 @@ public class FileSystemManager implements Initializable {
// For MAC OS X
// -Djava.security.krb5.realm=OX.AC.UK
// -Djava.security.krb5.kdc=kdc0.ox.ac.uk:kdc1.ox.ac.uk
System
.
setProperty
(
"java.security.krb5.realm"
,
getValue
(
properties
,
"java.security.krb5.realm"
,
"DIANPING.COM"
));
System
.
setProperty
(
"java.security.krb5.realm"
,
getValue
(
properties
,
"java.security.krb5.realm"
,
"DIANPING.COM"
));
System
.
setProperty
(
"java.security.krb5.kdc"
,
getValue
(
properties
,
"java.security.krb5.kdc"
,
"192.168.7.80"
));
UserGroupInformation
.
setConfiguration
(
config
);
...
...
@@ -109,11 +110,14 @@ public class FileSystemManager implements Initializable {
@Override
public
void
initialize
()
throws
InitializationException
{
m_defaultBaseDir
=
m_configManager
.
getHdfsLocalBaseDir
(
"hdfs"
);
try
{
m_config
=
getHdfsConfiguration
();
SecurityUtil
.
login
(
m_config
,
"dfs.cat.keytab.file"
,
"dfs.cat.kerberos.principal"
);
}
catch
(
IOException
e
)
{
throw
new
InitializationException
(
"init FileSystemManager fail"
,
e
);
if
(!
m_configManager
.
isLocalMode
())
{
try
{
m_config
=
getHdfsConfiguration
();
SecurityUtil
.
login
(
m_config
,
"dfs.cat.keytab.file"
,
"dfs.cat.kerberos.principal"
);
}
catch
(
IOException
e
)
{
throw
new
InitializationException
(
"init FileSystemManager fail"
,
e
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录