use of com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo in project pinpoint by naver.
the class CpuLoadCodecV1 method decodeValues.
@Override
public List<CpuLoadBo> decodeValues(Buffer valueBuffer, AgentStatDecodingContext decodingContext) {
final String agentId = decodingContext.getAgentId();
final long baseTimestamp = decodingContext.getBaseTimestamp();
final long timestampDelta = decodingContext.getTimestampDelta();
final long initialTimestamp = baseTimestamp + timestampDelta;
int numValues = valueBuffer.readVInt();
List<Long> timestamps = this.codec.decodeTimestamps(initialTimestamp, valueBuffer, numValues);
// decode headers
final byte[] header = valueBuffer.readPrefixedBytes();
AgentStatHeaderDecoder headerDecoder = new BitCountingHeaderDecoder(header);
EncodingStrategy<Long> jvmCpuLoadEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode());
EncodingStrategy<Long> systemCpuLoadEncodingStrategy = UnsignedLongEncodingStrategy.getFromCode(headerDecoder.getCode());
// decode values
List<Long> jvmCpuLoads = this.codec.decodeValues(valueBuffer, jvmCpuLoadEncodingStrategy, numValues);
List<Long> systemCpuLoads = this.codec.decodeValues(valueBuffer, systemCpuLoadEncodingStrategy, numValues);
List<CpuLoadBo> cpuLoadBos = new ArrayList<CpuLoadBo>(numValues);
for (int i = 0; i < numValues; ++i) {
CpuLoadBo cpuLoadBo = new CpuLoadBo();
cpuLoadBo.setAgentId(agentId);
cpuLoadBo.setTimestamp(timestamps.get(i));
cpuLoadBo.setJvmCpuLoad(AgentStatUtils.convertLongToDouble(jvmCpuLoads.get(i)));
cpuLoadBo.setSystemCpuLoad(AgentStatUtils.convertLongToDouble(systemCpuLoads.get(i)));
cpuLoadBos.add(cpuLoadBo);
}
return cpuLoadBos;
}
use of com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo in project pinpoint by naver.
the class CpuLoadCodecV2 method encodeValues.
@Override
public void encodeValues(Buffer valueBuffer, List<CpuLoadBo> cpuLoadBos) {
if (CollectionUtils.isEmpty(cpuLoadBos)) {
throw new IllegalArgumentException("cpuLoadBos must not be empty");
}
final int numValues = cpuLoadBos.size();
valueBuffer.putVInt(numValues);
List<Long> startTimestamps = new ArrayList<Long>(numValues);
List<Long> timestamps = new ArrayList<Long>(numValues);
UnsignedLongEncodingStrategy.Analyzer.Builder jvmCpuLoadAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder();
UnsignedLongEncodingStrategy.Analyzer.Builder systemCpuLoadAnalyzerBuilder = new UnsignedLongEncodingStrategy.Analyzer.Builder();
for (CpuLoadBo cpuLoadBo : cpuLoadBos) {
startTimestamps.add(cpuLoadBo.getStartTimestamp());
timestamps.add(cpuLoadBo.getTimestamp());
jvmCpuLoadAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(cpuLoadBo.getJvmCpuLoad()));
systemCpuLoadAnalyzerBuilder.addValue(AgentStatUtils.convertDoubleToLong(cpuLoadBo.getSystemCpuLoad()));
}
this.codec.encodeValues(valueBuffer, UnsignedLongEncodingStrategy.REPEAT_COUNT, startTimestamps);
this.codec.encodeTimestamps(valueBuffer, timestamps);
this.encodeDataPoints(valueBuffer, jvmCpuLoadAnalyzerBuilder.build(), systemCpuLoadAnalyzerBuilder.build());
}
use of com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo in project pinpoint by naver.
the class AgentStatBatchMapper method map.
@Override
public AgentStatBo map(TAgentStatBatch tAgentStatBatch) {
if (!tAgentStatBatch.isSetAgentStats()) {
return null;
}
AgentStatBo agentStatBo = new AgentStatBo();
final String agentId = tAgentStatBatch.getAgentId();
final long startTimestamp = tAgentStatBatch.getStartTimestamp();
agentStatBo.setAgentId(agentId);
List<JvmGcBo> jvmGcBos = new ArrayList<>(tAgentStatBatch.getAgentStatsSize());
List<JvmGcDetailedBo> jvmGcDetailedBos = new ArrayList<>(tAgentStatBatch.getAgentStatsSize());
List<CpuLoadBo> cpuLoadBos = new ArrayList<>(tAgentStatBatch.getAgentStatsSize());
List<TransactionBo> transactionBos = new ArrayList<>(tAgentStatBatch.getAgentStatsSize());
List<ActiveTraceBo> activeTraceBos = new ArrayList<>(tAgentStatBatch.getAgentStatsSize());
List<DataSourceListBo> dataSourceListBos = new ArrayList<DataSourceListBo>(tAgentStatBatch.getAgentStatsSize());
for (TAgentStat tAgentStat : tAgentStatBatch.getAgentStats()) {
final long timestamp = tAgentStat.getTimestamp();
// jvmGc
if (tAgentStat.isSetGc()) {
JvmGcBo jvmGcBo = this.jvmGcBoMapper.map(tAgentStat.getGc());
setBaseData(jvmGcBo, agentId, startTimestamp, timestamp);
jvmGcBos.add(jvmGcBo);
}
// jvmGcDetailed
if (tAgentStat.isSetGc()) {
if (tAgentStat.getGc().isSetJvmGcDetailed()) {
JvmGcDetailedBo jvmGcDetailedBo = this.jvmGcDetailedBoMapper.map(tAgentStat.getGc().getJvmGcDetailed());
setBaseData(jvmGcDetailedBo, agentId, startTimestamp, timestamp);
jvmGcDetailedBos.add(jvmGcDetailedBo);
}
}
// cpuLoad
if (tAgentStat.isSetCpuLoad()) {
CpuLoadBo cpuLoadBo = this.cpuLoadBoMapper.map(tAgentStat.getCpuLoad());
setBaseData(cpuLoadBo, agentId, startTimestamp, timestamp);
cpuLoadBos.add(cpuLoadBo);
}
// transaction
if (tAgentStat.isSetTransaction()) {
TransactionBo transactionBo = this.transactionBoMapper.map(tAgentStat.getTransaction());
setBaseData(transactionBo, agentId, startTimestamp, timestamp);
transactionBo.setCollectInterval(tAgentStat.getCollectInterval());
transactionBos.add(transactionBo);
}
// activeTrace
if (tAgentStat.isSetActiveTrace() && tAgentStat.getActiveTrace().isSetHistogram()) {
ActiveTraceBo activeTraceBo = this.activeTraceBoMapper.map(tAgentStat.getActiveTrace());
setBaseData(activeTraceBo, agentId, startTimestamp, timestamp);
activeTraceBos.add(activeTraceBo);
}
// datasource
if (tAgentStat.isSetDataSourceList()) {
DataSourceListBo dataSourceListBo = new DataSourceListBo();
setBaseData(dataSourceListBo, agentId, startTimestamp, timestamp);
TDataSourceList dataSourceList = tAgentStat.getDataSourceList();
if (dataSourceList.getDataSourceListSize() > 0) {
for (TDataSource dataSource : dataSourceList.getDataSourceList()) {
DataSourceBo dataSourceBo = dataSourceBoMapper.map(dataSource);
setBaseData(dataSourceBo, agentId, startTimestamp, timestamp);
dataSourceListBo.add(dataSourceBo);
}
}
dataSourceListBos.add(dataSourceListBo);
}
}
agentStatBo.setJvmGcBos(jvmGcBos);
agentStatBo.setJvmGcDetailedBos(jvmGcDetailedBos);
agentStatBo.setCpuLoadBos(cpuLoadBos);
agentStatBo.setTransactionBos(transactionBos);
agentStatBo.setActiveTraceBos(activeTraceBos);
agentStatBo.setDataSourceListBos(dataSourceListBos);
return agentStatBo;
}
use of com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo in project pinpoint by naver.
the class HeapUsageRateCheckerTest method before.
@BeforeClass
public static void before() {
jvmGcDao = new AgentStatDao<JvmGcBo>() {
@Override
public List<JvmGcBo> getAgentStatList(String agentId, Range range) {
List<JvmGcBo> jvmGcs = new LinkedList<>();
for (int i = 0; i < 36; i++) {
JvmGcBo jvmGcBo = new JvmGcBo();
jvmGcBo.setHeapUsed(70L);
jvmGcBo.setHeapMax(100L);
jvmGcs.add(jvmGcBo);
}
return jvmGcs;
}
@Override
public boolean agentStatExists(String agentId, Range range) {
return true;
}
};
cpuLoadDao = new AgentStatDao<CpuLoadBo>() {
@Override
public List<CpuLoadBo> getAgentStatList(String agentId, Range range) {
return Collections.emptyList();
}
@Override
public boolean agentStatExists(String agentId, Range range) {
return false;
}
};
applicationIndexDao = new ApplicationIndexDao() {
@Override
public List<Application> selectAllApplicationNames() {
throw new UnsupportedOperationException();
}
@Override
public List<String> selectAgentIds(String applicationName) {
if (SERVICE_NAME.equals(applicationName)) {
List<String> agentIds = new LinkedList<String>();
agentIds.add("local_tomcat");
return agentIds;
}
throw new IllegalArgumentException();
}
@Override
public void deleteApplicationName(String applicationName) {
throw new UnsupportedOperationException();
}
@Override
public void deleteAgentIds(Map<String, List<String>> applicationAgentIdMap) {
throw new UnsupportedOperationException();
}
@Override
public void deleteAgentId(String applicationName, String agentId) {
throw new UnsupportedOperationException();
}
};
}
use of com.navercorp.pinpoint.common.server.bo.stat.CpuLoadBo in project pinpoint by naver.
the class AgentStatDataCollector method collect.
@Override
public void collect() {
if (init.get()) {
return;
}
Range range = Range.createUncheckedRange(timeSlotEndTime - slotInterval, timeSlotEndTime);
List<String> agentIds = applicationIndexDao.selectAgentIds(application.getName());
for (String agentId : agentIds) {
List<JvmGcBo> jvmGcBos = jvmGcDao.getAgentStatList(agentId, range);
List<CpuLoadBo> cpuLoadBos = cpuLoadDao.getAgentStatList(agentId, range);
long totalHeapSize = 0;
long usedHeapSize = 0;
long jvmCpuUsaged = 0;
for (JvmGcBo jvmGcBo : jvmGcBos) {
totalHeapSize += jvmGcBo.getHeapMax();
usedHeapSize += jvmGcBo.getHeapUsed();
}
for (CpuLoadBo cpuLoadBo : cpuLoadBos) {
jvmCpuUsaged += cpuLoadBo.getJvmCpuLoad() * 100;
}
if (!jvmGcBos.isEmpty()) {
long percent = calculatePercent(usedHeapSize, totalHeapSize);
agentHeapUsageRate.put(agentId, percent);
long accruedLastGcCount = jvmGcBos.get(0).getGcOldCount();
long accruedFirstGcCount = jvmGcBos.get(jvmGcBos.size() - 1).getGcOldCount();
agentGcCount.put(agentId, accruedLastGcCount - accruedFirstGcCount);
}
if (!cpuLoadBos.isEmpty()) {
long percent = calculatePercent(jvmCpuUsaged, 100 * cpuLoadBos.size());
agentJvmCpuUsageRate.put(agentId, percent);
}
}
init.set(true);
}
Aggregations