提交 a160a6e4 编写于 作者: Y youyong205

fix the metric analyzer config problem

上级 ee22fd00
......@@ -12,7 +12,6 @@ import org.unidal.lookup.util.StringUtils;
import com.dianping.cat.Cat;
import com.dianping.cat.Constants;
import com.dianping.cat.advanced.metric.config.entity.MetricItemConfig;
import com.dianping.cat.analysis.AbstractMessageAnalyzer;
import com.dianping.cat.configuration.NetworkInterfaceManager;
import com.dianping.cat.consumer.advanced.dal.BusinessReport;
......@@ -53,6 +52,8 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
// key is project line,such as tuangou
private Map<String, MetricReport> m_reports = new HashMap<String, MetricReport>();
private static final String METRIC = "metric";
@Override
public void doCheckpoint(boolean atEnd) {
storeReports(atEnd);
......@@ -147,9 +148,6 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
Message message = tree.getMessage();
if (message instanceof Transaction) {
processMetricOnTransaction(product, report, (Transaction) message, tree);
}
if (message instanceof Transaction) {
processTransaction(product, report, tree, (Transaction) message);
} else if (message instanceof Metric) {
......@@ -159,7 +157,7 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
private int processMetric(String group, MetricReport report, MessageTree tree, Metric metric) {
String type = metric.getType();
String name = metric.getName();
String metricName = metric.getName();
String domain = tree.getDomain();
String data = (String) metric.getData();
String status = metric.getStatus();
......@@ -171,41 +169,17 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
if (config != null) {
long current = metric.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
String key = m_configManager.buildMetricKey(domain, "Metric", name);
String key = m_configManager.buildMetricKey(domain, METRIC, metricName);
MetricItem metricItem = report.findOrCreateMetricItem(key);
metricItem.addDomain(domain).setType(status);
updateMetric(metricItem, min, config.getCount(), config.getValue());
config.setTitle(name);
m_configManager.insertIfNotExist(domain, "Metric", name, config);
}
return 0;
}
private void processMetricOnTransaction(String product, MetricReport report, Transaction transaction,
MessageTree tree) {
String type = transaction.getType();
config.setTitle(metricName);
if (type.equals("Service")) {
type = "PigeonService";
}
if ("URL".equals(type) || "PigeonService".equals(type)) {
String domain = tree.getDomain();
String name = transaction.getName();
String key = m_configManager.buildMetricKey(domain, type, name);
MetricItemConfig config = m_configManager.queryMetricItemConfig(key);
if (config != null) {
long current = transaction.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
double sum = transaction.getDurationInMicros();
MetricItem metricItem = report.findOrCreateMetricItem(key);
metricItem.addDomain(domain).setType("C");
updateMetric(metricItem, min, 1, sum);
}
m_configManager.insertIfNotExist(domain, METRIC, metricName, config);
}
return 0;
}
private int processTransaction(String group, MetricReport report, MessageTree tree, Transaction t) {
......
......@@ -58,7 +58,9 @@ public class ProductLineConfigManager implements Initializable, LogEnabled {
public static final String SYSTEM_MONITOR = "系统监控";
public static final String NETWORK_MONITOR_PREFIX = "network-";
public static final String NETWORK_SWITCH_PREFIX = "switch-";
public static final String NETWORK_F5_PREFIX = "f5-";
public static final String SYSTEM_MONITOR_PREFIX = "system-";
......@@ -132,11 +134,12 @@ public class ProductLineConfigManager implements Initializable, LogEnabled {
if ("broker-service".equals(domain)) {
userMonitor = true;
} else if (line.startsWith(NETWORK_MONITOR_PREFIX)) {
} else if (line.startsWith(NETWORK_SWITCH_PREFIX) || line.startsWith(NETWORK_F5_PREFIX)) {
networkMonitor = true;
} else if (line.startsWith(SYSTEM_MONITOR_PREFIX)) {
systemMonitor = true;
}
productLine.setNetworkDashboard(networkMonitor);
productLine.setUserMonitorDashboard(userMonitor);
productLine.setSystemMonitorDashboard(systemMonitor);
......@@ -168,9 +171,8 @@ public class ProductLineConfigManager implements Initializable, LogEnabled {
return storeConfig();
}
}
} else {
return false;
}
return false;
}
public boolean insertProductLine(ProductLine line, String[] domains) {
......
......@@ -428,28 +428,20 @@ public class Handler implements PageHandler<Context> {
Set<String> exists = new HashSet<String>();
for (Entry<String, ProductLine> entry : productLines.entrySet()) {
Set<String> domains = entry.getValue().getDomains().keySet();
List<MetricItemConfig> configs = m_metricConfigManager.queryMetricItemConfigs(domains);
for (MetricItemConfig config : configs) {
exists.add(m_metricConfigManager.buildMetricKey(config.getDomain(), config.getType(), config.getMetricKey()));
ProductLine productLine = entry.getValue();
if (productLine.isMetricDashboard()) {
Set<String> domains = productLine.getDomains().keySet();
List<MetricItemConfig> configs = m_metricConfigManager.queryMetricItemConfigs(domains);
for (MetricItemConfig config : configs) {
exists.add(m_metricConfigManager.buildMetricKey(config.getDomain(), config.getType(),
config.getMetricKey()));
}
metricConfigs.put(productLine, configs);
}
metricConfigs.put(entry.getValue(), configs);
}
Map<String, MetricItemConfig> allConfigs = m_metricConfigManager.getMetricConfig().getMetricItemConfigs();
Set<String> keysClone = new HashSet<String>(allConfigs.keySet());
List<MetricItemConfig> otherConfigs = new ArrayList<MetricItemConfig>();
for (String key : exists) {
keysClone.remove(key);
}
for (String str : keysClone) {
otherConfigs.add(allConfigs.get(str));
}
ProductLine otherProductLine = new ProductLine("Other").setTitle("Other");
metricConfigs.put(otherProductLine, otherConfigs);
model.setProductMetricConfigs(metricConfigs);
}
......
......@@ -100,7 +100,9 @@
<th width="8%"><h5 class='text-center'>显示次数</h5></th>
<th width="8%"><h5 class='text-center'>显示平均值</h5></th>
<th width="8%"><h5 class='text-center'>显示总和</h5></th>
<th width="13%"><h5 class='text-center'>操作&nbsp;&nbsp;<a class="btn update btn-primary btn-small" href="?op=metricConfigAdd&metricKey=${config.metricKey}&domain=${config.domain}&productLineName=${key}">新增</a></h5></th>
<th width="13%"><h5 class='text-center'>操作
<%--&nbsp;&nbsp;<a class="btn update btn-primary btn-small" href="?op=metricConfigAdd&metricKey=${config.metricKey}&domain=${config.domain}&productLineName=${key}">新增</a>
--%></h5></th>
</tr>
<c:forEach var="config" items="${value}">
<tr>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册