提交 55b39b7e 编写于 作者: F Frankie Wu

adjust heartbeat model

上级 d14ef1f0
......@@ -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();
......
......@@ -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);
}
}
......@@ -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());
diskSpace.setTotal(workingDir.getTotalSpace());
diskSpace.setFree(workingDir.getFreeSpace());
diskSpace.setUsable(workingDir.getUsableSpace());
diskVolume.setTotal(volume.getTotalSpace());
diskVolume.setFree(volume.getFreeSpace());
diskVolume.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.setDiskSpace(new DiskSpaceInfo());
status.setDisk(new DiskInfo());
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
......@@ -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" />
......
......@@ -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" />
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册