[유치수] [NOBTS] 서버맵에서 hostname조회 개선. agentinfo는 ip와 hostname을 수집하고 view에서는 hostname을 조회해서 보여준다.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@1340 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2013-03-18 07:13:30 +00:00
parent b916544e1c
commit 2a5596dfb2
4 changed files with 57 additions and 6 deletions
@@ -46,13 +46,14 @@ public class Server implements Comparable<Server> {
this.id = nodeSelector.getServerId(span);
if (span.getServiceType().isTerminal()) {
// TODO 이 함수는 terminal span이 들어올리가 없음.
this.hosts.add(span.getAgentId());
} else {
this.hosts.add(span.getEndPoint());
// this.hosts.add(span.getEndPoint());
}
this.applicationName = span.getApplicationId();
this.recursiveCallCount = span.getRecursiveCallCount();
this.serviceType = span.getServiceType();
}
@@ -91,6 +92,12 @@ public class Server implements Comparable<Server> {
return hosts;
}
public void setHosts(Set<String> hosts) {
if (hosts != null) {
this.hosts.addAll(hosts);
}
}
// public String getEndPoint() {
// return endPoint;
// }
@@ -3,9 +3,11 @@ package com.nhn.hippo.web.calltree.server;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +40,8 @@ public class ServerCallTree {
private final Map<String, String> clientServerMap = new HashMap<String, String>();
private final Map<String, TerminalStatistics> terminalRequests = new HashMap<String, TerminalStatistics>();
private final Map<String, ClientStatistics> clientRequests = new HashMap<String, ClientStatistics>();
private final Map<String, Set<String>> applicationHosts = new HashMap<String, Set<String>>();
public ServerCallTree(NodeSelector nodeSelector) {
this.nodeSelector = nodeSelector;
}
@@ -133,11 +136,21 @@ public class ServerCallTree {
spanList.add(span);
}
public void addApplicationHosts(String applicationId, Set<String> hosts) {
applicationHosts.put(applicationId, hosts);
}
public ServerCallTree build() {
if (isBuilt)
return this;
// fill WAS hostnames.
for (Entry<String, Server> entry : servers.entrySet()) {
Server server = entry.getValue();
server.setHosts(applicationHosts.get(server.getApplicationName()));
}
// add terminal to the servers
for (Entry<String, TerminalStatistics> entry : terminalRequests.entrySet()) {
TerminalStatistics terminal = entry.getValue();
@@ -48,7 +48,7 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
logger.debug("agent:{} startTime value {}", agentId, startTime);
// 바로 전 시작 시간을 찾아야 한다.
if (startTime < currentTime) {
byte[] value = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO__IDENTIFIER);
byte[] value = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER);
AgentInfoBo agentInfoBo = new AgentInfoBo();
agentInfoBo.setAgentId(agentId);
agentInfoBo.setTimestamp(startTime);
@@ -17,6 +17,7 @@ import org.springframework.util.StopWatch;
import com.nhn.hippo.web.calltree.server.AgentIdNodeSelector;
import com.nhn.hippo.web.calltree.server.ApplicationIdNodeSelector;
import com.nhn.hippo.web.calltree.server.ServerCallTree;
import com.nhn.hippo.web.dao.AgentInfoDao;
import com.nhn.hippo.web.dao.ApplicationIndexDao;
import com.nhn.hippo.web.dao.ApplicationTraceIndexDao;
import com.nhn.hippo.web.dao.ClientStatisticsDao;
@@ -29,6 +30,7 @@ import com.nhn.hippo.web.vo.TerminalStatistics;
import com.nhn.hippo.web.vo.TraceId;
import com.nhn.hippo.web.vo.scatter.Dot;
import com.profiler.common.ServiceType;
import com.profiler.common.bo.AgentInfoBo;
import com.profiler.common.bo.SpanBo;
import com.profiler.common.bo.SpanEventBo;
@@ -58,6 +60,9 @@ public class FlowChartServiceImpl implements FlowChartService {
@Autowired
private ClientStatisticsDao clientStatisticsDao;
@Autowired
private AgentInfoDao agentInfoDao;
@Override
public List<String> selectAllApplicationNames() {
return applicationIndexDao.selectAllApplicationNames();
@@ -203,6 +208,20 @@ public class FlowChartServiceImpl implements FlowChartService {
return endPointSet;
}
private Set<String> selectApplicationHosts(String applicationId) {
String[] agentIds = applicationIndexDao.selectAgentIds(applicationId);
Set<String> hostnames = new HashSet<String>();
for (String agentId : agentIds) {
// TODO 조회 시간대에 따라서 agent info row timestamp를 변경하여 조회해야하는지는 모르겠음.
AgentInfoBo info = agentInfoDao.findAgentInfoBeforeStartTime(agentId, System.currentTimeMillis());
hostnames.add(info.getHostname());
}
return hostnames;
}
/**
* 메인화면에서 사용. 시간별로 TimeSlot을 조회하여 서버 맵을 그릴 때 사용한다. makes call tree of main
* view
@@ -211,6 +230,8 @@ public class FlowChartServiceImpl implements FlowChartService {
public ServerCallTree selectServerCallTree(Set<TraceId> traceIds, String applicationName, long from, long to) {
final Map<String, ServiceType> terminalQueryParams = new HashMap<String, ServiceType>();
final Map<String, ServiceType> clientQueryParams = new HashMap<String, ServiceType>();
final Set<String> hostnameQueryParams = new HashSet<String>();
final ServerCallTree tree = new ServerCallTree(new ApplicationIdNodeSelector());
StopWatch watch = new StopWatch();
@@ -232,6 +253,9 @@ public class FlowChartServiceImpl implements FlowChartService {
// markRecursiveCall(transaction);
for (SpanBo eachTransaction : transaction) {
tree.addSpan(eachTransaction);
// make hostname query params
hostnameQueryParams.add(eachTransaction.getApplicationId());
// make query param
terminalQueryParams.put(eachTransaction.getApplicationId(), eachTransaction.getServiceType());
@@ -279,6 +303,9 @@ public class FlowChartServiceImpl implements FlowChartService {
}
}
watch.stop();
logger.info("Fetch terminal statistics elapsed : {}ms", watch.getLastTaskTimeMillis());
logger.debug("client query params=" + clientQueryParams);
// fetch client info
@@ -292,9 +319,13 @@ public class FlowChartServiceImpl implements FlowChartService {
}
}
}
logger.debug("hostname query params=" + hostnameQueryParams);
watch.stop();
logger.info("Fetch terminal statistics elapsed : {}ms", watch.getLastTaskTimeMillis());
// fetch hostnames
for (String applicationId : hostnameQueryParams) {
tree.addApplicationHosts(applicationId, selectApplicationHosts(applicationId));
}
return tree.build();
}