提交 3aca4635 编写于 作者: S sunryuan

refactor

上级 28aca73b
......@@ -2,6 +2,7 @@ package com.dianping.cat.consumer.state;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
......@@ -65,12 +66,14 @@ public class StateAnalyzer extends AbstractMessageAnalyzer<StateReport> implemen
machine.setTotalLoss(messageTotalLoss + machine.getTotalLoss());
machine.setSize(messageSize + machine.getSize());
for (String key : totals.keySet()) {
for (Entry<String,Long> entry : totals.entrySet()) {
String key = entry.getKey();
long value = entry.getValue();
ProcessDomain domain = machine.findOrCreateProcessDomain(key);
Detail detail = domain.findOrCreateDetail(start);
if(totals.containsKey(key)){
domain.setTotal(totals.get(key) + domain.getTotal());
detail.setTotal(totals.get(key));
domain.setTotal(value + domain.getTotal());
detail.setTotal(value);
}
if(totalLosses.containsKey(key)){
domain.setTotalLoss(totalLosses.get(key) + domain.getTotalLoss());
......@@ -183,10 +186,10 @@ public class StateAnalyzer extends AbstractMessageAnalyzer<StateReport> implemen
buildStateInfo(machine);
StateReport startReport = m_reportManager.getHourlyReport(getStartTime(), ReportConstants.CAT, true);
for(String key:machine.getProcessDomains().keySet()){
machine.getProcessDomains().get(key).getIps().addAll(startReport.findOrCreateMachine(ip).getProcessDomains().get(key).getIps());
Map<String, ProcessDomain> processDomains = startReport.findOrCreateMachine(ip).getProcessDomains();
for(Map.Entry<String, ProcessDomain> entry:machine.getProcessDomains().entrySet()){
entry.getValue().getIps().addAll(processDomains.get(entry.getKey()).getIps());
}
// machine.getProcessDomains().putAll(startReport.findOrCreateMachine(ip).getProcessDomains());
return report;
}
......
......@@ -13,18 +13,6 @@ public class StateReportMerger extends DefaultMerger {
super(stateReport);
}
// private long getTotal(Machine machine, String key) {
// return machine.getTotals().get(key).getCount();
// }
//
// private long getTotalLoss(Machine machine, String key) {
// return machine.getTotalLosses().get(key).getCount();
// }
//
// private double getSize(Machine machine, String key) {
// return machine.getSizes().get(key).getCount();
// }
@Override
protected void mergeMachine(Machine old, Machine machine) {
double oldCount = 0;
......@@ -39,17 +27,7 @@ public class StateReportMerger extends DefaultMerger {
if (totalCount > 0) {
old.setAvgTps((old.getTotal() + machine.getTotal()) / totalCount);
}
// for (String key : old.getTotals().keySet()) {
// old.findOrCreateTotal(key).setCount(getTotal(old, key) + getTotal(machine, key));
// }
//
// for (String key : old.getTotalLosses().keySet()) {
// old.findOrCreateTotalLoss(key).setCount(getTotalLoss(old, key) + getTotalLoss(machine, key));
// }
//
// for (String key : old.getTotals().keySet()) {
// old.findOrCreateSize(key).setCount(getSize(old, key) + getSize(machine, key));
// }
old.setTotal(old.getTotal() + machine.getTotal());
old.setTotalLoss(old.getTotalLoss() + machine.getTotalLoss());
old.setSize(old.getSize() + machine.getSize());
......
......@@ -31,7 +31,7 @@
<attribute name="name" value-type="String" key="true" />
<attribute name="total" value-type="long" primitive="true"/>
<attribute name="totalLoss" value-type="long" primitive="true"/>
<attribute name="size" value-type="double" primitive="true"/>
<attribute name="size" value-type="double" primitive="true" format="0.0"/>
<element name="ip" value-type="String" type="set" names="ips" />
<entity-ref name="detail" type="map" names="details" method-find-or-create="true" />
</entity>
......
......@@ -5,7 +5,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
public class ServerStatistic {
private Map<Long, Statistic> m_statistics = new LinkedHashMap<Long, Statistic>();
private Map<Long, Statistic> m_statistics = new LinkedHashMap<Long, Statistic>(60);
public Statistic findOrCreate(Long time) {
Statistic state = m_statistics.get(time);
......@@ -33,11 +33,11 @@ public class ServerStatistic {
private long m_messageDumpLoss;
private Map<String, Long> m_messageTotals = new HashMap<String, Long>();
private Map<String, Long> m_messageTotals = new HashMap<String, Long>(256);
private Map<String, Long> m_messageTotalLosses = new HashMap<String, Long>();
private Map<String, Long> m_messageTotalLosses = new HashMap<String, Long>(256);
private Map<String, Double> m_messageSizes = new HashMap<String, Double>();
private Map<String, Double> m_messageSizes = new HashMap<String, Double>(256);
private double m_processDelaySum;
......
......@@ -50,8 +50,9 @@ public class ServerStatisticManager {
public void addMessageSize(String domain, double size) {
Long time = getCurrentMinute();
m_serverState.findOrCreate(time).addMessageSize(domain, size);
addMessageSize(size);
}
public void addMessageSize(double size) {
......@@ -74,8 +75,9 @@ public class ServerStatisticManager {
public void addMessageTotalLoss(String domain, long total) {
Long time = getCurrentMinute();
m_serverState.findOrCreate(time).addMessageTotalLoss(domain, total);
addMessageTotalLoss(total);
}
public void addMessageTotalLoss(long total) {
......
......@@ -369,13 +369,13 @@ public class LocalMessageBucketManager extends ContainerHolder implements Messag
}
if (value != null && value % CatConstants.SUCCESS_COUNT == 0) {
Long lastTotalSize = m_lastTotalSizes.get(domain);
Long totalSize = m_totalSizes.get(domain);
if(lastTotalSize == null){
lastTotalSize = 0L;
}
double amount = m_totalSizes.get(domain) - lastTotalSize;
m_lastTotalSizes.put(domain, m_totalSizes.get(domain));
double amount = totalSize - lastTotalSize;
m_lastTotalSizes.put(domain, totalSize);
m_serverStateManager.addMessageSize(domain, amount);
m_serverStateManager.addMessageSize(amount);
}
}
......
......@@ -155,12 +155,9 @@
<table width="100%">
<tr class='odd'>
<td width="15%">处理项目列表</td>
<td width="5%">处理消息总量</td>
<td width="5%"></td>
<td width="5%">丢失消息总量</td>
<td width="5%"></td>
<td width="5%">压缩前消息大小(GB)</td>
<td width="5%"></td>
<td colspan='2' width="10%">处理消息总量</td>
<td colspan='2' width="10%">丢失消息总量</td>
<td colspan='2' width="10%">压缩前消息大小(GB)</td>
<td width="5%">机器总数</td>
<td>项目对应机器列表</td>
</tr>
......@@ -169,11 +166,11 @@
<tr class="${status.index mod 2 != 0 ? 'odd' : 'even'}">
<c:set var="lastIndex" value="${status.index}" />
<td>${item.name}</td>
<td style="text-align:right;">${item.total}</td>
<td style="text-align:left;">${item.total}</td>
<td><a href="?op=graph&ip=${model.ipAddress}&date=${model.date}&key=${item.name}:total" data-status="${item.name}:total" class="state_graph_link">[:: show ::]</a></td>
<td style="text-align:right;">${item.totalLoss}</td>
<td style="text-align:left;">${item.totalLoss}</td>
<td><a href="?op=graph&ip=${model.ipAddress}&date=${model.date}&key=${item.name}:totalLoss" data-status="${item.name}:totalLoss" class="state_graph_link">[:: show ::]</a></td>
<td style="text-align:right;">${w:format(item.size/1024/1024/1024,'0.00#')}</td>
<td style="text-align:left;">${w:format(item.size/1024/1024/1024,'0.00#')}</td>
<td><a href="?op=graph&ip=${model.ipAddress}&date=${model.date}&key=${item.name}:size" data-status="${item.name}:size" class="state_graph_link">[:: show ::]</a></td>
<td style="text-align:center;">${w:size(item.ips)}</td>
<td style="white-space: normal">${item.ips}</td>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册