Skip to content

Commit

Permalink
clean problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jialinsun committed Mar 6, 2015
1 parent 100c267 commit fcc5af7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import com.dianping.cat.report.page.model.spi.ModelService;
import com.dianping.cat.report.page.state.StateGraphBuilder;
import com.dianping.cat.report.page.storage.topology.StorageAlertInfoRTContainer;
import com.dianping.cat.report.page.storage.topology.StorageAlertInfoService;
import com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager;
import com.dianping.cat.report.page.storage.topology.StorageGraphBuilder;
import com.dianping.cat.report.service.ReportService;
import com.dianping.cat.report.service.ReportServiceManager;
Expand Down Expand Up @@ -117,7 +117,7 @@ private List<Component> defineCommonComponents() {

all.add(C(StorageAlertInfoRTContainer.class));
all.add(C(StorageGraphBuilder.class).req(StorageAlertInfoRTContainer.class));
all.add(C(StorageAlertInfoService.class).req(AlertDao.class).req(StorageAlertInfoRTContainer.class)
all.add(C(StorageAlertInfoManager.class).req(AlertDao.class).req(StorageAlertInfoRTContainer.class)
.req(StorageGraphBuilder.class));

return all;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.dianping.cat.report.graph.LineChart;
import com.dianping.cat.report.page.PayloadNormalizer;
import com.dianping.cat.report.page.model.spi.ModelService;
import com.dianping.cat.report.page.storage.topology.StorageAlertInfoService;
import com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager;
import com.dianping.cat.report.service.ReportServiceManager;
import com.dianping.cat.service.ModelRequest;
import com.dianping.cat.service.ModelResponse;
Expand All @@ -50,7 +50,7 @@ public class Handler implements PageHandler<Context> {
private StorageMergeHelper m_mergeHelper;

@Inject
private StorageAlertInfoService m_alertInfoService;
private StorageAlertInfoManager m_alertInfoManager;

@Inject
private StorageGroupConfigManager m_storageGroupConfigManager;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void handleOutbound(Context ctx) throws ServletException, IOException {
storageReport = queryHistoryReport(payload, CACHE_TYPE);
break;
case DASHBOARD:
StorageAlertInfo alertInfo = m_alertInfoService.queryAlertInfo(payload.getDate(), model.getMinute());
StorageAlertInfo alertInfo = m_alertInfoManager.queryAlertInfo(payload.getDate(), model.getMinute());

model.setDepartments(m_storageGroupConfigManager.queryStorageDepartments());
model.setAlertInfo(alertInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.dianping.cat.home.storage.alert.entity.StorageAlertInfo;
import com.dianping.cat.report.alert.AlertType;

public class StorageAlertInfoService {
public class StorageAlertInfoManager {

@Inject
private AlertDao m_alertDao;
Expand All @@ -37,7 +37,6 @@ public StorageAlertInfo queryAlertInfo(long time, int minute) {
private StorageAlertInfo buildFromDatabase(long time, int minute) {
Date start = new Date(time + minute * TimeHelper.ONE_MINUTE);
Date end = new Date(start.getTime() + TimeHelper.ONE_MINUTE - 1000);
System.out.println(start + " " + end);
StorageAlertInfo alertInfo = new StorageAlertInfo("SQL");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,22 @@ public int buildLevel(int level, int other) {
return level > other ? level : other;
}

private String queryTarget(String target) {
if ("avg".equals(target)) {
return "响应时间";
} else if ("error".equals(target)) {
return "错误率";
} else {
return target;
}
}

public void processAlertEntity(int minute, AlertEntity entity, ReportFetcherParam param) {
int level = queryLevel(entity.getLevel());
String name = param.getName();
String ip = param.getMachine();
String opertaion = param.getMethod();
String target = param.getTarget();
String target = queryTarget(param.getTarget());

Storage storage = getAlertInfo(minute).findOrCreateStorage(name);
storage.incCount();
Expand All @@ -66,7 +76,7 @@ public void parseAlertEntity(Alert alert, StorageAlertInfo alertInfo) {
List<String> fields = Splitters.by(";").split(alert.getMetric());
String ip = fields.get(0);
String operation = fields.get(1);
String target = fields.get(2);
String target = queryTarget(fields.get(2));
int level = queryLevel(alert.getType());

Storage storage = alertInfo.findOrCreateStorage(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void initialize() throws InitializationException {

private void refreshData() {
Map<String, Rule> rules = m_config.getRules();
Map<String, RuleMappingConfig> mapping = new HashMap<String, RuleMappingConfig>();

for (Entry<String, Rule> entry : rules.entrySet()) {
String[] conditions = entry.getValue().getId().split(FIELD_SEPARATOR);
Expand All @@ -74,18 +75,19 @@ private void refreshData() {
String machine = conditions[1];
String operation = conditions[2];
String attribute = conditions[3];
RuleMappingConfig ruleMappingConfig = m_ruleMappings.get(name);
RuleMappingConfig ruleMappingConfig = mapping.get(name);

if (ruleMappingConfig == null) {
ruleMappingConfig = new RuleMappingConfig(name);

m_ruleMappings.put(name, ruleMappingConfig);
mapping.put(name, ruleMappingConfig);
}
IpMappingConfig ip = ruleMappingConfig.findOrCreate(machine);
OperationConfig op = ip.findOrCreate(operation);
op.addRule(attribute, entry.getValue());
}
}
m_ruleMappings = mapping;
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions cat-home/src/main/resources/META-INF/plexus/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
</requirements>
</component>
<component>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoService</role>
<implementation>com.dianping.cat.report.page.storage.topology.StorageAlertInfoService</implementation>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager</role>
<implementation>com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.home.dal.report.AlertDao</role>
Expand Down Expand Up @@ -5353,7 +5353,7 @@
<role>com.dianping.cat.report.page.storage.StorageMergeHelper</role>
</requirement>
<requirement>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoService</role>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.system.config.StorageGroupConfigManager</role>
Expand All @@ -5377,8 +5377,8 @@
<implementation>com.dianping.cat.report.page.storage.StorageMergeHelper</implementation>
</component>
<component>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoService</role>
<implementation>com.dianping.cat.report.page.storage.topology.StorageAlertInfoService</implementation>
<role>com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager</role>
<implementation>com.dianping.cat.report.page.storage.topology.StorageAlertInfoManager</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.home.dal.report.AlertDao</role>
Expand Down
77 changes: 45 additions & 32 deletions cat-home/src/main/webapp/jsp/report/storage/dashboard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<c:set var="alertInfo" value="${model.alertInfo}" />

<table class="table table-hover table-striped table-condensed table-bordered" style="width:100%">
<c:forEach var="entry" items="${model.departments}" varStatus="index">
<tr>
<td width="10%" rowspan="${w:size(entry.value.productlines)}">${entry.key}</td>
<c:forEach var="entry" items="${model.departments}">
<tr>
<td width="8%" rowspan="${w:size(entry.value.productlines)}" class="center" style="vertical-align:middle">${entry.key}</td>
<c:forEach var="e" items="${entry.value.productlines}" varStatus="index">
<c:if test="${index.index != 0}"><tr></c:if>
<c:forEach var="e" items="${entry.value.productlines}">
<td width="10%">${e.key}</td>
<td width="8%" class="center" style="vertical-align:middle">${e.key}</td>
<td>
<c:forEach var="storage" items="${e.value.storages}">
<c:set var="storageInfo" value="${alertInfo.storages[storage]}" />
Expand All @@ -35,59 +35,59 @@
<div class="modal-dialog" style="width:1100px">
<div class="modal-content">
<div class="modal-body">
<h4 class=" text-center">数据库:<a href="/cat/r/storage?op=database&domain=${storage}&ip=All">${storage}</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;告警时间:第&nbsp;&nbsp;<span class="text-danger">${model.minute}</span>&nbsp;&nbsp;分</h4>
<h4 class=" text-center"><strong>数据库:[&nbsp;<a href="/cat/r/storage?op=database&domain=${storage}&ip=All">${storage}</a>&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间:第&nbsp;&nbsp;<span class="text-danger">${model.minute}</span>&nbsp;&nbsp;</strong></h4>
<table class="table table-striped table-condensed table-hover table-bordered">
<tr class="text-success">
<th width="10%">机器</th>
<th width="20%">方法</th>
<th width="20%">指标</th>
<th width="50%">内容</th>
</tr>
<thead><tr>
<th width="10%" class="center">机器</th>
<th width="10%" class="center">方法</th>
<th width="10%" class="center">指标</th>
<th width="70%" class="center">内容</th>
</tr></thead>
<c:forEach var="machine_entry" items="${storageInfo.machines}">
<tr>
<td rowspan="${machine_entry.value.count}" class="center" style="vertical-align:middle">
<c:if test="${machine_entry.value.level == 1}">
<span class="text-warning">
<c:if test="${machine_entry.value.level == 1}">
<span class="text-warning">${machine_entry.key}</span>
</c:if>
<c:if test="${machine_entry.value.level == 2}">
<span class="text-danger">
<span class="text-danger"><strong>${machine_entry.key}</strong></span>
</c:if>
${machine_entry.key}</span></td>
</td>
<c:forEach var="operation_entry" items="${machine_entry.value.operations}" varStatus="index1">
<c:if test="${index1.index != 0}"><tr></c:if>
<c:if test="${index1.index != 0}"><tr></c:if>

<td rowspan="${operation_entry.value.count}" class="center" style="vertical-align:middle">
<c:if test="${operation_entry.value.level == 1}">
<span class="text-warning">
<span class="text-warning">${operation_entry.key}</span>
</c:if>
<c:if test="${operation_entry.value.level == 2}">
<span class="text-danger">
<span class="text-danger"><strong>${operation_entry.key}</strong></span>
</c:if>
${operation_entry.key}</span></td>
</td>
<c:forEach var="target_entry" items="${operation_entry.value.targets}" varStatus="index2">
<c:if test="${index2.index != 0}"><tr></c:if>
<td rowspan="${target_entry.value.count}" class="center" style="vertical-align:middle">
<c:if test="${target_entry.value.level == 1}">
<span class="text-warning">
<span class="text-warning">${target_entry.key}</span>
</c:if>
<c:if test="${target_entry.value.level == 2}">
<span class="text-danger">
<span class="text-danger"><strong>${target_entry.key}</strong></span>
</c:if>
${target_entry.key}</span></td>
<c:forEach var="detail" items="${target_entry.value.details}" varStatus="index3">
<c:if test="${index3.index != 0}"><tr></c:if>
<td>
<c:if test="${detail.level == 1}">
<span class="text-warning">
<span class="text-warning">${detail.content}</span>
</c:if>
<c:if test="${detail.level == 2}">
<span class="text-danger">
<span class="text-danger"><strong>${detail.content}</span></strong>
</c:if>
${detail.content}</span></td>
</td>
<c:if test="${index3.index != 0}"></tr></c:if>
</c:forEach>
<c:if test="${index4.index != 0}"></tr></c:if>
<c:if test="${index2.index != 0}"></tr></c:if>
</c:forEach>
<c:if test="${index3.index != 0}"></tr></c:if>
<c:if test="${index1.index != 0}"></tr></c:if>
</c:forEach>
</tr>
</c:forEach>
Expand All @@ -97,21 +97,34 @@
</div>
</div>
</c:if>

<c:if test="${storageInfo == null or storageInfo.level == 0 }">
<div class="modal fade" id="${storage}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:1100px">
<div class="modal-content">
<div class="modal-body">
<h4 class="text-center"><strong>数据库:[&nbsp;<a href="/cat/r/storage?op=database&domain=${storage}&ip=All">${storage}</a>&nbsp;]&nbsp;&nbsp;&nbsp;<span class="text-success">正常!</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间:第&nbsp;&nbsp;<span class="text-danger">${model.minute}</span>&nbsp;&nbsp;分</strong></h4>
</div>
</div>
</div>
</div>
</c:if>
<c:choose>
<c:when test="${storageInfo != null && storageInfo.level == 1}">
<button class="btn btn-app btn-lg radius-4 btn-warning alert-modal" data-id="${storage}" style="height: 50px; width: 100px">${storage}<span class="label label-inverse arrowed-in">${alertInfo.storages[storage].count }</span></button>
<button class="btn btn-app btn-lg radius-4 btn-warning alert-modal" data-id="${storage}" style="height: 50px; min-width: 100px; width: auto">${storage}<span class="label label-inverse arrowed-in">${alertInfo.storages[storage].count }</span></button>
</c:when>
<c:when test="${storageInfo != null && storageInfo.level == 2}">
<button class="btn btn-app btn-lg radius-4 btn-danger alert-modal" data-id="${storage}" style="height: 50px; width: 100px">${storage}<span class="label label-inverse arrowed-in">${alertInfo.storages[storage].count }</span></button>
<button class="btn btn-app btn-lg radius-4 btn-danger alert-modal" data-id="${storage}" style="height: 50px; min-width: 100px; width: auto">${storage}<span class="label label-inverse arrowed-in">${alertInfo.storages[storage].count }</span></button>
</c:when>
<c:otherwise>
<button class="btn btn-app btn-lg radius-4 btn-success alert-modal" onclick="document.location.href='/cat/r/storage?op=database&domain=${storage}&ip=All';" style="height: 50px; width: 100px">${storage}<span class="label label-inverse arrowed-in">${alertInfo.storages[storage].count }</span></button>
<button class="btn btn-app btn-lg radius-4 btn-success alert-modal" data-id="${storage}" style="height: 50px; min-width: 100px; width: auto">${storage}</button>
</c:otherwise>
</c:choose>
</c:forEach>
</td>
</tr>
<c:if test="${index.index != 0}"></tr></c:if>
</c:forEach>
</tr>
</c:forEach>
</table>
</jsp:body>
Expand Down

0 comments on commit fcc5af7

Please sign in to comment.