[김훈민] [PINPOINT-213] AgentStat 개선

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-server/trunk@2270 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Hoonmin Kim
2013-09-03 07:19:41 +00:00
parent 837ee78b70
commit 81db0d6606
5 changed files with 21 additions and 8 deletions
@@ -11,8 +11,8 @@ public interface AgentStatStore {
AgentStat get(String agentId);
String getInJson();
String getInJson(String agentId);
String toJson();
}
@@ -6,6 +6,12 @@ import com.nhn.pinpoint.common.dto2.thrift.StatWithG1Collector;
import com.nhn.pinpoint.common.dto2.thrift.StatWithParallelCollector;
import com.nhn.pinpoint.common.dto2.thrift.AgentStat._Fields;
/**
* AgentStat 메시지에서 agentId, timestamp 등의 공통 정보를 꺼내올 수 있는 유틸리티.
* AgentStat에 포함될 struct들이 agentId, timestamp 필드를 가지고 있다고 가정한다.
*
* @author harebox
*/
public class AgentStatSupport {
public static String getAgentId(AgentStat agentStat) {
@@ -6,22 +6,26 @@ import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.nhn.pinpoint.common.dto2.thrift.AgentStat;
/**
*
* 테스트를 위해 메모리에 (AgentId -> AgentStat) 맵을 캐싱해둔다.
* @author harebox
*/
public class DefaultAgentStatStore implements AgentStatStore {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
@Qualifier("jsonObjectMapper")
private ObjectMapper jsonObjectMapper;
// in-memory storage
private Map<String, AgentStat> map = new ConcurrentHashMap<String, AgentStat>();
private ObjectMapper jsonMapper = new ObjectMapper();
public void store(AgentStat agentStat) {
String agentId = AgentStatSupport.getAgentId(agentStat);
@@ -43,7 +47,7 @@ public class DefaultAgentStatStore implements AgentStatStore {
AgentStat agentStat = map.get(agentId);
if (agentStat != null) {
Object typeObject = agentStat.getFieldValue(agentStat.getSetField());
result = jsonMapper.writeValueAsString(typeObject);
result = jsonObjectMapper.writeValueAsString(typeObject);
}
} catch (Exception e) {
logger.error("failed to serialze the object to JSON : {}", e.getMessage());
@@ -51,7 +55,7 @@ public class DefaultAgentStatStore implements AgentStatStore {
return result;
}
public String toJson() {
public String getInJson() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("\"agentId\"").append(" : ").append("\"").append(map.keySet().toString()).append("\"");
@@ -62,7 +62,7 @@ public class AgentStatServlet extends HttpServlet {
jsonpCallback(req, res, "{\"error\": \"not found : " + agentId + "\"}");
}
} else {
jsonpCallback(req, res, statServer.getStore().toJson());
jsonpCallback(req, res, statServer.getStore().getInJson());
}
}
@@ -74,4 +74,7 @@
<bean id="udpReceiver" class="com.nhn.pinpoint.collector.receiver.udp.UDPReceiver">
</bean>
<bean id="jsonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper">
</bean>
</beans>