mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 08:16:15 +10:00
[강운덕] [LUCYSUS-1744] pinpoint의 agent의 랜덤으로 획득하는 identifier를 java process의 pid로 변경함.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@2399 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -57,7 +57,7 @@ public class DefaultAgent implements Agent {
|
||||
private final String agentId;
|
||||
private final String applicationName;
|
||||
private final long startTime;
|
||||
private final int identifier;
|
||||
private final int pid;
|
||||
|
||||
// agent info는 heartbeat에서 매번 사용한다.
|
||||
private AgentInfo agentInfo;
|
||||
@@ -97,8 +97,8 @@ public class DefaultAgent implements Agent {
|
||||
this.machineName = NetworkUtils.getHostName();
|
||||
this.agentId = getId("pinpoint.agentId", machineName, PinpointConstants.AGENT_NAME_MAX_LEN);
|
||||
this.applicationName = getId("pinpoint.applicationName", "UnknownApplicationName", PinpointConstants.APPLICATION_NAME_MAX_LEN);
|
||||
this.startTime = getVmStartTime();
|
||||
this.identifier = getPid();
|
||||
this.startTime = RuntimeMXBeanUtils.getVmStartTime();
|
||||
this.pid = RuntimeMXBeanUtils.getPid();
|
||||
|
||||
this.tcpDataSender = createTcpDataSender();
|
||||
this.spanDataSender = createUdpDataSender(this.profilerConfig.getCollectorUdpSpanServerPort(), "Pinpoint-UdpSpanDataExecutor");
|
||||
@@ -191,8 +191,7 @@ public class DefaultAgent implements Agent {
|
||||
agentInfo.setPorts(ports);
|
||||
|
||||
agentInfo.setAgentId(getAgentId());
|
||||
// TODO identifier를 pid로 변경할것.
|
||||
agentInfo.setIdentifier((short) this.identifier);
|
||||
agentInfo.setPid(this.pid);
|
||||
agentInfo.setApplicationName(getApplicationName());
|
||||
agentInfo.setServiceType(profilerConfig.getServiceType().getCode());
|
||||
|
||||
@@ -273,22 +272,13 @@ public class DefaultAgent implements Agent {
|
||||
}
|
||||
}
|
||||
|
||||
public long getVmStartTime() {
|
||||
long vmStartTime = RuntimeMXBeanUtils.getVmStartTime();
|
||||
if (vmStartTime == 0) {
|
||||
vmStartTime = System.currentTimeMillis();
|
||||
}
|
||||
return vmStartTime;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return RuntimeMXBeanUtils.getPid();
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
public static DefaultAgent INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static DefaultAgent getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
@@ -306,10 +296,6 @@ public class DefaultAgent implements Agent {
|
||||
return agentId;
|
||||
}
|
||||
|
||||
public int getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
@@ -318,6 +304,10 @@ public class DefaultAgent implements Agent {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public TraceContext getTraceContext() {
|
||||
return traceContext;
|
||||
}
|
||||
@@ -330,7 +320,7 @@ public class DefaultAgent implements Agent {
|
||||
// TODO 필요없을것 같음 started를 start로 바꿔도 될 듯...
|
||||
@Override
|
||||
public void start() {
|
||||
logger.info("Starting " + ProductInfo.CAMEL_NAME + " Agent.");
|
||||
logger.info("Starting {} Agent.", ProductInfo.CAMEL_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,7 +335,7 @@ public class DefaultAgent implements Agent {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
logger.info("Stopping " + ProductInfo.CAMEL_NAME +" Agent.");
|
||||
logger.info("Stopping {} Agent.", ProductInfo.CAMEL_NAME);
|
||||
|
||||
changeStatus(AgentStatus.STOPPING);
|
||||
this.heartBitChecker.close();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.nhn.pinpoint.profiler.context;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.profiler.DefaultAgent;
|
||||
import com.nhn.pinpoint.thrift.dto.ApiMetaData;
|
||||
import com.nhn.pinpoint.thrift.dto.SqlMetaData;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
@@ -14,7 +13,6 @@ import com.nhn.pinpoint.profiler.metadata.StringCache;
|
||||
import com.nhn.pinpoint.profiler.modifier.db.JDBCUrlParser;
|
||||
import com.nhn.pinpoint.profiler.sampler.Sampler;
|
||||
import com.nhn.pinpoint.profiler.sender.DataSender;
|
||||
import com.nhn.pinpoint.profiler.util.Assert;
|
||||
import com.nhn.pinpoint.profiler.util.NamedThreadLocal;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -150,6 +148,9 @@ public class DefaultTraceContext implements TraceContext {
|
||||
|
||||
@Override
|
||||
public void setAgentId(String agentId) {
|
||||
if (agentId == null) {
|
||||
throw new NullPointerException("agentId must not be null");
|
||||
}
|
||||
this.agentId = agentId;
|
||||
}
|
||||
|
||||
@@ -160,6 +161,9 @@ public class DefaultTraceContext implements TraceContext {
|
||||
|
||||
@Override
|
||||
public void setApplicationId(String applicationId) {
|
||||
if (applicationId == null) {
|
||||
throw new NullPointerException("applicationId must not be null");
|
||||
}
|
||||
this.applicationId = applicationId;
|
||||
}
|
||||
|
||||
@@ -169,11 +173,16 @@ public class DefaultTraceContext implements TraceContext {
|
||||
}
|
||||
|
||||
public void setStorageFactory(StorageFactory storageFactory) {
|
||||
Assert.notNull(storageFactory, "storageFactory myst not be null");
|
||||
if (storageFactory == null) {
|
||||
throw new NullPointerException("storageFactory must not be null");
|
||||
}
|
||||
this.storageFactory = storageFactory;
|
||||
}
|
||||
|
||||
public void setSampler(Sampler sampler) {
|
||||
if (sampler == null) {
|
||||
throw new NullPointerException("sampler must not be null");
|
||||
}
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@@ -184,9 +193,8 @@ public class DefaultTraceContext implements TraceContext {
|
||||
Result result = this.apiCache.put(fullName);
|
||||
if (result.isNewValue()) {
|
||||
ApiMetaData apiMetadata = new ApiMetaData();
|
||||
DefaultAgent agent = DefaultAgent.getInstance();
|
||||
apiMetadata.setAgentId(agent.getAgentId());
|
||||
apiMetadata.setAgentStartTime(agent.getStartTime());
|
||||
apiMetadata.setAgentId(agentId);
|
||||
apiMetadata.setAgentStartTime(agentStartTime);
|
||||
|
||||
apiMetadata.setApiId(result.getId());
|
||||
apiMetadata.setApiInfo(methodDescriptor.getApiDescriptor());
|
||||
@@ -227,7 +235,7 @@ public class DefaultTraceContext implements TraceContext {
|
||||
|
||||
SqlMetaData sqlMetaData = new SqlMetaData();
|
||||
sqlMetaData.setAgentId(agentId);
|
||||
sqlMetaData.setAgentStartTime(DefaultAgent.getInstance().getStartTime());
|
||||
sqlMetaData.setAgentStartTime(agentStartTime);
|
||||
|
||||
sqlMetaData.setHashCode(normalizedSql.hashCode());
|
||||
sqlMetaData.setSql(normalizedSql);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class SpanChunk implements Thriftable {
|
||||
|
||||
// tSpanEvent.setAgentId(Agent.getInstance().getAgentId());
|
||||
// tSpanEvent.setApplicationName(Agent.getInstance().getApplicationName());
|
||||
// tSpanEvent.setAgentIdentifier(Agent.getInstance().getIdentifier());
|
||||
// tSpanEvent.setAgentIdentifier(Agent.getInstance().getPid());
|
||||
|
||||
long parentSpanStartTime = spanEvent.getParentSpan().getStartTime();
|
||||
tSpanEvent.setStartElapsed((int) (spanEvent.getStartTime() - parentSpanStartTime));
|
||||
|
||||
@@ -42,17 +42,21 @@ public class RuntimeMXBeanUtils {
|
||||
|
||||
public static long getVmStartTime() {
|
||||
if (START_TIME == 0) {
|
||||
try {
|
||||
START_TIME = RUNTIME_MBEAN.getStartTime();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
final Logger logger = getLogger();
|
||||
logger.log(Level.WARNING, "RuntimeMXBean.getStartTime() unsupported. Caused:" + e.getMessage(), e);
|
||||
START_TIME = System.currentTimeMillis();
|
||||
}
|
||||
START_TIME = getVmStartTime0();
|
||||
}
|
||||
return START_TIME;
|
||||
}
|
||||
|
||||
private static long getVmStartTime0() {
|
||||
try {
|
||||
return RUNTIME_MBEAN.getStartTime();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
final Logger logger = getLogger();
|
||||
logger.log(Level.WARNING, "RuntimeMXBean.getStartTime() unsupported. Caused:" + e.getMessage(), e);
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
private static Logger getLogger() {
|
||||
return Logger.getLogger(RuntimeMXBeanUtils.class.getName());
|
||||
}
|
||||
|
||||
@@ -16,18 +16,7 @@ public class AgentTest {
|
||||
|
||||
@Test
|
||||
public void testGetIdentifier() throws Exception {
|
||||
checkIdentifier();
|
||||
checkIdentifier();
|
||||
checkIdentifier();
|
||||
checkIdentifier();
|
||||
// identifier가 pid기반으로 변경되어 테스트 삭제.
|
||||
}
|
||||
|
||||
private void checkIdentifier() throws IOException {
|
||||
ProfilerConfig config = new ProfilerConfig();
|
||||
// config.readConfigFile();
|
||||
DefaultAgent agent = new DefaultAgent("", new DummyInstrumentation(), config);
|
||||
|
||||
int identifier = agent.getIdentifier();
|
||||
logger.info("{}", identifier);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user