From b6367f53cfbb81379c356a090a4e7dfd751cbeb6 Mon Sep 17 00:00:00 2001 From: HyunGil Jeong Date: Wed, 28 Oct 2015 16:25:00 +0900 Subject: [PATCH] #1069 Add transaction metric support --- .../dao/hbase/HbaseAgentStatDao.java | 34 +- .../pinpoint/common/hbase/HBaseTables.java | 25 +- .../profiler/monitor/AgentStatMonitor.java | 23 +- .../monitor/codahale/MetricMonitorValues.java | 5 +- .../tps/TransactionMetricCollector.java | 21 +- .../tps/metric/TransactionMetricSet.java | 65 +-- .../monitor/AgentStatMonitorTest.java | 2 +- .../tps/metric/TransactionMetricSetTest.java | 154 +++-- .../pinpoint/thrift/dto/TAgentStat.java | 121 +++- .../pinpoint/thrift/dto/TTransaction.java | 524 ++++++++++++++++-- thrift/src/main/thrift/Pinpoint.thrift | 7 +- .../pinpoint/web/mapper/AgentStatMapper.java | 60 +- .../navercorp/pinpoint/web/vo/AgentStat.java | 66 ++- .../SampledTimeSeriesDoubleChartBuilder.java | 35 +- .../agentstat/AgentStatChartGroup.java | 70 ++- .../web/mapper/AgentStatMapperTest.java | 54 +- 16 files changed, 965 insertions(+), 301 deletions(-) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentStatDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentStatDao.java index 9816c26a3..3ca792249 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentStatDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentStatDao.java @@ -59,36 +59,42 @@ public class HbaseAgentStatDao implements AgentStatDao { Put put = createPut(agentStat); hbaseTemplate.put(AGENT_STAT, put); } - + private Put createPut(TAgentStat agentStat) { long timestamp = agentStat.getTimestamp(); byte[] key = getDistributedRowKey(agentStat, timestamp); Put put = new Put(key); - + + final long collectInterval = agentStat.getCollectInterval(); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_INTERVAL, Bytes.toBytes(collectInterval)); // GC, Memory if (agentStat.isSetGc()) { TJvmGc gc = agentStat.getGc(); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_GC_TYPE, Bytes.toBytes(gc.getType().name())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_GC_OLD_COUNT, Bytes.toBytes(gc.getJvmGcOldCount())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_GC_OLD_TIME, Bytes.toBytes(gc.getJvmGcOldTime())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_HEAP_USED, Bytes.toBytes(gc.getJvmMemoryHeapUsed())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_HEAP_MAX, Bytes.toBytes(gc.getJvmMemoryHeapMax())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_USED, Bytes.toBytes(gc.getJvmMemoryNonHeapUsed())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_MAX, Bytes.toBytes(gc.getJvmMemoryNonHeapMax())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_GC_TYPE, Bytes.toBytes(gc.getType().name())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_GC_OLD_COUNT, Bytes.toBytes(gc.getJvmGcOldCount())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_GC_OLD_TIME, Bytes.toBytes(gc.getJvmGcOldTime())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_HEAP_USED, Bytes.toBytes(gc.getJvmMemoryHeapUsed())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_HEAP_MAX, Bytes.toBytes(gc.getJvmMemoryHeapMax())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_NON_HEAP_USED, Bytes.toBytes(gc.getJvmMemoryNonHeapUsed())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_NON_HEAP_MAX, Bytes.toBytes(gc.getJvmMemoryNonHeapMax())); } else { - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_GC_TYPE, Bytes.toBytes(TJvmGcType.UNKNOWN.name())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_GC_TYPE, Bytes.toBytes(TJvmGcType.UNKNOWN.name())); } // CPU if (agentStat.isSetCpuLoad()) { TCpuLoad cpuLoad = agentStat.getCpuLoad(); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_JVM_CPU, Bytes.toBytes(cpuLoad.getJvmCpuLoad())); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_SYS_CPU, Bytes.toBytes(cpuLoad.getSystemCpuLoad())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_JVM_CPU, Bytes.toBytes(cpuLoad.getJvmCpuLoad())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_SYS_CPU, Bytes.toBytes(cpuLoad.getSystemCpuLoad())); } // Transaction if (agentStat.isSetTransaction()) { TTransaction transaction = agentStat.getTransaction(); - put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_CF_STATISTICS_COL_TPS, Bytes.toBytes(transaction.getTps())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_TRANSACTION_VERSION, Bytes.toBytes(transaction.getVersion())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW, Bytes.toBytes(transaction.getSampledNewCount())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION, Bytes.toBytes(transaction.getSampledContinuationCount())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW, Bytes.toBytes(transaction.getUnsampledNewCount())); + put.addColumn(AGENT_STAT_CF_STATISTICS, AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION, Bytes.toBytes(transaction.getUnsampledContinuationCount())); } return put; } @@ -105,7 +111,7 @@ public class HbaseAgentStatDao implements AgentStatDao { } /** - * Create row key based on the timestamp and distribute it into different buckets + * Create row key based on the timestamp and distribute it into different buckets */ private byte[] getDistributedRowKey(TAgentStat agentStat, long timestamp) { byte[] key = getRowKey(agentStat.getAgentId(), timestamp); diff --git a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java index b662dd73d..0335e86c2 100644 --- a/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java +++ b/commons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java @@ -40,16 +40,21 @@ public final class HBaseTables { // FIXME (2015.10) Legacy column for storing serialzied Bos separately. @Deprecated public static final byte[] AGENT_STAT_CF_STATISTICS_MEMORY_GC = Bytes.toBytes("Gc"); // qualifier for Heap Memory/Gc statistics @Deprecated public static final byte[] AGENT_STAT_CF_STATISTICS_CPU_LOAD = Bytes.toBytes("Cpu"); // qualifier for CPU load statistics - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_GC_TYPE = Bytes.toBytes("gcT"); // qualifier for GC type - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_GC_OLD_COUNT = Bytes.toBytes("gcOldC"); // qualifier for GC old count - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_GC_OLD_TIME = Bytes.toBytes("gcOldT"); // qualifier for GC old time - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_HEAP_USED = Bytes.toBytes("hpU"); // gualifier for heap used - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_HEAP_MAX = Bytes.toBytes("hpM"); // qualifier for heap max - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_USED = Bytes.toBytes("nHpU"); // qualifier for non-heap used - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_MAX = Bytes.toBytes("nHpM"); // qualifier for non-heap max - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_JVM_CPU = Bytes.toBytes("jvmCpu"); // qualifier for JVM CPU usage - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_SYS_CPU = Bytes.toBytes("sysCpu"); // qualifier for system CPU usage - public static final byte[] AGENT_STAT_CF_STATISTICS_COL_TPS = Bytes.toBytes("tps"); // qualifier for tps + public static final byte[] AGENT_STAT_COL_INTERVAL = Bytes.toBytes("int"); // qualifier for collection interval + public static final byte[] AGENT_STAT_COL_GC_TYPE = Bytes.toBytes("gcT"); // qualifier for GC type + public static final byte[] AGENT_STAT_COL_GC_OLD_COUNT = Bytes.toBytes("gcOldC"); // qualifier for GC old count + public static final byte[] AGENT_STAT_COL_GC_OLD_TIME = Bytes.toBytes("gcOldT"); // qualifier for GC old time + public static final byte[] AGENT_STAT_COL_HEAP_USED = Bytes.toBytes("hpU"); // gualifier for heap used + public static final byte[] AGENT_STAT_COL_HEAP_MAX = Bytes.toBytes("hpM"); // qualifier for heap max + public static final byte[] AGENT_STAT_COL_NON_HEAP_USED = Bytes.toBytes("nHpU"); // qualifier for non-heap used + public static final byte[] AGENT_STAT_COL_NON_HEAP_MAX = Bytes.toBytes("nHpM"); // qualifier for non-heap max + public static final byte[] AGENT_STAT_COL_JVM_CPU = Bytes.toBytes("jvmCpu"); // qualifier for JVM CPU usage + public static final byte[] AGENT_STAT_COL_SYS_CPU = Bytes.toBytes("sysCpu"); // qualifier for system CPU usage + public static final byte[] AGENT_STAT_COL_TRANSACTION_VERSION = Bytes.toBytes("tV"); // qualifier for transaction version + public static final byte[] AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW = Bytes.toBytes("tSN"); // qualifier for sampled new count + public static final byte[] AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION = Bytes.toBytes("tSC"); // qualifier for sampled continuation count + public static final byte[] AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW = Bytes.toBytes("tUnSN"); // qualifier for unsampled new count + public static final byte[] AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION = Bytes.toBytes("tUnSC"); // qualifier for unsampled continuation count public static final int AGENT_STAT_ROW_DISTRIBUTE_SIZE = 1; // agent statistics hash size public static final String TRACES = "Traces"; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitor.java index b156583bf..ee2b5a07d 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitor.java @@ -83,9 +83,8 @@ public class AgentStatMonitor { } public void start() { - long wait = 0; CollectJob job = new CollectJob(this.numCollectionsPerBatch); - executor.scheduleAtFixedRate(job, wait, this.collectionIntervalMs, TimeUnit.MILLISECONDS); + executor.scheduleAtFixedRate(job, this.collectionIntervalMs, this.collectionIntervalMs, TimeUnit.MILLISECONDS); logger.info("AgentStat monitor started"); } @@ -99,15 +98,17 @@ public class AgentStatMonitor { logger.info("AgentStat monitor stopped"); } + // NotThreadSafe private class CollectJob implements Runnable { private final GarbageCollector garbageCollector; private final CpuLoadCollector cpuLoadCollector; private final TransactionMetricCollector transactionMetricCollector; - // Will be used by single thread. - // I don't think this object would run with multi threads. + + // Not thread safe. For use with single thread ONLY private final int numStatsPerBatch; private int collectCount = 0; + private long prevCollectionTimestamp = System.currentTimeMillis(); private List agentStats; private CollectJob(int numStatsPerBatch) { @@ -118,9 +119,14 @@ public class AgentStatMonitor { this.agentStats = new ArrayList(this.numStatsPerBatch); } + @Override public void run() { + final long currentCollectionTimestamp = System.currentTimeMillis(); + final long collectInterval = currentCollectionTimestamp - this.prevCollectionTimestamp; try { final TAgentStat agentStat = collectAgentStat(); + agentStat.setTimestamp(currentCollectionTimestamp); + agentStat.setCollectInterval(collectInterval); this.agentStats.add(agentStat); if (++this.collectCount >= this.numStatsPerBatch) { sendAgentStats(); @@ -128,21 +134,19 @@ public class AgentStatMonitor { } } catch (Exception ex) { logger.warn("AgentStat collect failed. Caused:{}", ex.getMessage(), ex); + } finally { + this.prevCollectionTimestamp = currentCollectionTimestamp; } } private TAgentStat collectAgentStat() { final TAgentStat agentStat = new TAgentStat(); - agentStat.setTimestamp(System.currentTimeMillis()); final TJvmGc gc = garbageCollector.collect(); agentStat.setGc(gc); final TCpuLoad cpuLoad = cpuLoadCollector.collect(); agentStat.setCpuLoad(cpuLoad); final TTransaction transaction = transactionMetricCollector.collect(); agentStat.setTransaction(transaction); - if (isTrace) { - logger.trace("collect agentStat:{}", agentStat); - } return agentStat; } @@ -154,7 +158,8 @@ public class AgentStatMonitor { agentStatBatch.setAgentId(agentId); agentStatBatch.setStartTimestamp(agentStartTime); agentStatBatch.setAgentStats(this.agentStats); - // If we reuse agentStats list, there could be concurrency issue because data sender runs in a different thread. + // If we reuse agentStats list, there could be concurrency issue because data sender runs in a different + // thread. // So create new list. this.agentStats = new ArrayList(this.numStatsPerBatch); if (isTrace) { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/MetricMonitorValues.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/MetricMonitorValues.java index b98438933..bc4d9fff4 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/MetricMonitorValues.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/MetricMonitorValues.java @@ -99,7 +99,10 @@ public final class MetricMonitorValues { public static final String CPU_LOAD_SYSTEM = CPU_LOAD + ".system"; public static final String TRANSACTION = "transaction"; - public static final String TRANSACTION_PER_SECOND = TRANSACTION + ".tps"; + public static final String TRANSACTION_SAMPLED_NEW = TRANSACTION + ".sampled.new"; + public static final String TRANSACTION_SAMPLED_CONTINUATION = TRANSACTION + ".sampled.continuation"; + public static final String TRANSACTION_UNSAMPLED_NEW = TRANSACTION + ".unsampled.new"; + public static final String TRANSACTION_UNSAMPLED_CONTINUATION = TRANSACTION + ".unsampled.continuation"; private MetricMonitorValues() { } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/TransactionMetricCollector.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/TransactionMetricCollector.java index 16c3f6027..d505a228f 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/TransactionMetricCollector.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/TransactionMetricCollector.java @@ -32,22 +32,33 @@ import com.navercorp.pinpoint.thrift.dto.TTransaction; */ public class TransactionMetricCollector implements AgentStatCollector { - public static final int UNSUPPORTED_TPS_METRIC = -1; - private final Gauge tpsGauge; + public static final long UNSUPPORTED_TRANSACTION_METRIC = -1; + private static final Gauge UNSUPPORTED_GAUGE = new EmptyGauge(UNSUPPORTED_TRANSACTION_METRIC); + + private final Gauge sampledNewGauge; + private final Gauge sampledContinuationGauge; + private final Gauge unsampledNewGauge; + private final Gauge unsampledContinuationGuage; @SuppressWarnings("unchecked") public TransactionMetricCollector(TransactionMetricSet transactionMetricSet) { if (transactionMetricSet == null) { - throw new NullPointerException("tpsMetricSet must not be null"); + throw new NullPointerException("transactionMetricSet must not be null"); } Map metrics = transactionMetricSet.getMetrics(); - this.tpsGauge = (Gauge)MetricMonitorValues.getMetric(metrics, TRANSACTION_PER_SECOND, new EmptyGauge(UNSUPPORTED_TPS_METRIC)); + this.sampledNewGauge = (Gauge)MetricMonitorValues.getMetric(metrics, TRANSACTION_SAMPLED_NEW, UNSUPPORTED_GAUGE); + this.sampledContinuationGauge = (Gauge)MetricMonitorValues.getMetric(metrics, TRANSACTION_SAMPLED_CONTINUATION, UNSUPPORTED_GAUGE); + this.unsampledNewGauge = (Gauge)MetricMonitorValues.getMetric(metrics, TRANSACTION_UNSAMPLED_NEW, UNSUPPORTED_GAUGE); + this.unsampledContinuationGuage = (Gauge)MetricMonitorValues.getMetric(metrics, TRANSACTION_UNSAMPLED_NEW, UNSUPPORTED_GAUGE); } @Override public TTransaction collect() { TTransaction transaction = new TTransaction(); - transaction.setTps(this.tpsGauge.getValue()); + transaction.setSampledNewCount(this.sampledNewGauge.getValue()); + transaction.setSampledContinuationCount(this.sampledContinuationGauge.getValue()); + transaction.setUnsampledNewCount(this.unsampledNewGauge.getValue()); + transaction.setUnsampledContinuationCount(this.unsampledContinuationGuage.getValue()); return transaction; } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSet.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSet.java index a51adef7f..32889e387 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSet.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSet.java @@ -24,6 +24,7 @@ import com.codahale.metrics.Gauge; import com.codahale.metrics.Metric; import com.codahale.metrics.MetricSet; import com.navercorp.pinpoint.profiler.context.TransactionCounter; +import com.navercorp.pinpoint.profiler.context.TransactionCounter.SamplingType; import com.navercorp.pinpoint.profiler.monitor.codahale.MetricMonitorValues; /** @@ -31,19 +32,28 @@ import com.navercorp.pinpoint.profiler.monitor.codahale.MetricMonitorValues; */ public class TransactionMetricSet implements MetricSet { - private final Gauge tpsGauge; + private final Gauge sampledNewGauge; + private final Gauge sampledContinuationGauge; + private final Gauge unsampledNewGauge; + private final Gauge unsampledContinuationGuage; public TransactionMetricSet(TransactionCounter transactionCounter) { if (transactionCounter == null) { throw new NullPointerException("transactionCounter must not be null"); } - this.tpsGauge = new TpsGauge(transactionCounter); + this.sampledNewGauge = new TransactionGauge(transactionCounter, SamplingType.SAMPLED_NEW); + this.sampledContinuationGauge = new TransactionGauge(transactionCounter, SamplingType.SAMPLED_CONTINUATION); + this.unsampledNewGauge = new TransactionGauge(transactionCounter, SamplingType.UNSAMPLED_NEW); + this.unsampledContinuationGuage = new TransactionGauge(transactionCounter, SamplingType.UNSAMPLED_CONTINUATION); } @Override public Map getMetrics() { final Map gauges = new HashMap(); - gauges.put(MetricMonitorValues.TRANSACTION_PER_SECOND, this.tpsGauge); + gauges.put(MetricMonitorValues.TRANSACTION_SAMPLED_NEW, this.sampledNewGauge); + gauges.put(MetricMonitorValues.TRANSACTION_SAMPLED_CONTINUATION, this.sampledContinuationGauge); + gauges.put(MetricMonitorValues.TRANSACTION_UNSAMPLED_NEW, this.unsampledNewGauge); + gauges.put(MetricMonitorValues.TRANSACTION_UNSAMPLED_CONTINUATION, this.unsampledContinuationGuage); return Collections.unmodifiableMap(gauges); } @@ -52,50 +62,33 @@ public class TransactionMetricSet implements MetricSet { return "Default TransactionMetricSet"; } - private class TpsGauge implements Gauge { - + private class TransactionGauge implements Gauge { private static final long UNINITIALIZED = -1L; private final TransactionCounter transactionCounter; + private final SamplingType samplingType; - private long lastTickMs = UNINITIALIZED; - private long lastTransactionCount = UNINITIALIZED; + private long prevTransactionCount = UNINITIALIZED; - private TpsGauge(TransactionCounter transactionCounter) { + private TransactionGauge(TransactionCounter transactionCounter, SamplingType samplingType) { this.transactionCounter = transactionCounter; + this.samplingType = samplingType; } @Override - public Integer getValue() { - final long currentTickMs = System.currentTimeMillis(); - final long transactionCount = transactionCounter.getTotalTransactionCount(); - if (this.lastTickMs == UNINITIALIZED) { - this.lastTickMs = currentTickMs; - this.lastTransactionCount = transactionCount; - return 0; + public final Long getValue() { + final long transactionCount = this.transactionCounter.getTransactionCount(this.samplingType); + if (transactionCount < 0) { + return 0L; } - final long timeMsSinceLastTick = currentTickMs - this.lastTickMs; - final long transactionCountSinceLastTick = transactionCount - this.lastTransactionCount; - - this.lastTickMs = currentTickMs; - this.lastTransactionCount = transactionCount; - - return calculateTps(transactionCountSinceLastTick, timeMsSinceLastTick); + if (this.prevTransactionCount == UNINITIALIZED) { + this.prevTransactionCount = transactionCount; + return 0L; + } + final long transactionCountDelta = transactionCount - this.prevTransactionCount; + this.prevTransactionCount = transactionCount; + return transactionCountDelta; } - - private int calculateTps(long count, long timeMs) { - if (count <= 0 || timeMs <= 0) { - return 0; - } - // ignore improbable overflow - final long tps = (timeMs + (count * 1000) - 1) / timeMs; - if (tps > Integer.MAX_VALUE) { - return Integer.MAX_VALUE; - } else { - return (int)tps; - } - } - } } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitorTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitorTest.java index e7cb0923f..0d4c612e2 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitorTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/AgentStatMonitorTest.java @@ -60,7 +60,7 @@ public class AgentStatMonitorTest { final long collectionIntervalMs = 1000 * 1; final int numCollectionsPerBatch = 2; final int minNumBatchToTest = 2; - final long totalTestDurationMs = collectionIntervalMs * numCollectionsPerBatch * minNumBatchToTest; + final long totalTestDurationMs = collectionIntervalMs + collectionIntervalMs * numCollectionsPerBatch * minNumBatchToTest; // When System.setProperty("pinpoint.log", "test."); AgentStatCollectorFactory agentStatCollectorFactory = new AgentStatCollectorFactory(new TestableTransactionCounter()); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSetTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSetTest.java index 0165dfd17..31b01bd08 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSetTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/codahale/tps/metric/TransactionMetricSetTest.java @@ -31,134 +31,130 @@ import com.navercorp.pinpoint.profiler.monitor.codahale.MetricMonitorValues; */ public class TransactionMetricSetTest { - private static final int ACCEPTABLE_DIFF_PERCENTAGE = 1; - private TestableTransactionCounter transactionCounter; - private Gauge tpsGauge; + + private Gauge sampledNewGauge; + private Gauge sampledContinuationGauge; + private Gauge unsampledNewGauge; + private Gauge unsampledContinuationGuage; @Before @SuppressWarnings("unchecked") public void setUp() { this.transactionCounter = new TestableTransactionCounter(); TransactionMetricSet metricSet = new TransactionMetricSet(this.transactionCounter); - this.tpsGauge = (Gauge)metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_PER_SECOND); + this.sampledNewGauge = (Gauge) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_SAMPLED_NEW); + this.sampledContinuationGauge = (Gauge) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_SAMPLED_CONTINUATION); + this.unsampledNewGauge = (Gauge) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_UNSAMPLED_NEW); + this.unsampledContinuationGuage = (Gauge) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_UNSAMPLED_CONTINUATION); } @Test - public void initialTpsShouldBeZero() { - int initialTps = this.tpsGauge.getValue(); - assertEquals(0, initialTps); + public void initialTransactionCountsShouldBeZero() { + final long expectedInitialTransactionCount = 0L; + final long initialSampledNewCount = this.sampledNewGauge.getValue(); + final long initialSampledContinuationCount = this.sampledContinuationGauge.getValue(); + final long initialUnsampledNewCount = this.unsampledNewGauge.getValue(); + final long initialUnsampledContinuationCount = this.unsampledContinuationGuage.getValue(); + assertEquals(expectedInitialTransactionCount, initialSampledNewCount); + assertEquals(expectedInitialTransactionCount, initialSampledContinuationCount); + assertEquals(expectedInitialTransactionCount, initialUnsampledNewCount); + assertEquals(expectedInitialTransactionCount, initialUnsampledContinuationCount); } @Test - public void checkCalculationFor_0_Tps() throws Exception { + public void checkCalculationFor_0_Transaction() throws Exception { // Given - final int expectedTps = 0; - final int expectedExecutionTimeInSeconds = 1; - final int expectedNumberOfTransactions = expectedTps * expectedExecutionTimeInSeconds; + final long expectedNumberOfTransactions = 0L; // When initializeGauge(); this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedNumberOfTransactions); - Thread.sleep(expectedExecutionTimeInSeconds * 1000); - final int actualTps = this.tpsGauge.getValue(); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, expectedNumberOfTransactions); // Then - assertApproximatelyEquals(expectedTps, actualTps); + assertEquals(expectedNumberOfTransactions, (long) this.sampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.sampledContinuationGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledContinuationGuage.getValue()); } @Test - public void checkCalculationFor_1_Tps() throws Exception { + public void checkCalculationFor_1_Transaction() throws Exception { // Given - final int expectedTps = 1; - final int expectedExecutionTimeInSeconds = 1; - final int expectedNumberOfTransactions = expectedTps * expectedExecutionTimeInSeconds; + final long expectedNumberOfTransactions = 1L; // When initializeGauge(); this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedNumberOfTransactions); - Thread.sleep(expectedExecutionTimeInSeconds * 1000); - final int actualTps = this.tpsGauge.getValue(); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, expectedNumberOfTransactions); // Then - assertApproximatelyEquals(expectedTps, actualTps); + assertEquals(expectedNumberOfTransactions, (long) this.sampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.sampledContinuationGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledContinuationGuage.getValue()); } @Test - public void checkCalculationFor_100_Tps() throws Exception { + public void checkCalculationFor_100_Transaction() throws Exception { // Given - final int expectedTps = 100; - final int expectedExecutionTimeInSeconds = 1; - final int expectedNumberOfTransactions = expectedTps * expectedExecutionTimeInSeconds; + final long expectedNumberOfTransactions = 100L; // When initializeGauge(); this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedNumberOfTransactions); - Thread.sleep(expectedExecutionTimeInSeconds * 1000); - final int actualTps = this.tpsGauge.getValue(); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, expectedNumberOfTransactions); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, expectedNumberOfTransactions); // Then - assertApproximatelyEquals(expectedTps, actualTps); + assertEquals(expectedNumberOfTransactions, (long) this.sampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.sampledContinuationGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledContinuationGuage.getValue()); } @Test - public void checkCalculationFor_1000_Tps() throws Exception { + public void negative_Transaction_should_return_0() throws Exception { // Given - final int expectedTps = 1000; - final int expectedExecutionTimeInSeconds = 2; - final int expectedNumberOfTransactions = expectedTps * expectedExecutionTimeInSeconds; + final long expectedNumberOfTransactions = 0L; // When initializeGauge(); - this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedNumberOfTransactions); - Thread.sleep(expectedExecutionTimeInSeconds * 1000); - final int actualTps = this.tpsGauge.getValue(); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, -1000L); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, -1000L); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, -1000L); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, -1000L); // Then - assertApproximatelyEquals(expectedTps, actualTps); + assertEquals(expectedNumberOfTransactions, (long) this.sampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.sampledContinuationGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactions, (long) this.unsampledContinuationGuage.getValue()); } - + @Test - public void checkContinuousTpsCalculation() throws Exception { + public void checkContinuousTransactions() throws Exception { // Given - final long oneSecond = 1 * 1000L; - final int expectedTpsForFirstSecond = 1; - final int expectedTpsForSecondSecond = 1000; - final int expectedTpsForThirdSecond = 500; - final int expectedTpsForFourthSecond = 0; - final int expectedTpsForFifthSecond = 999; + final int testCnt = 10; + final long expectedNumberOfTransactionsPerCollection = 100L; // When initializeGauge(); - - this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedTpsForFirstSecond); - Thread.sleep(oneSecond); - final int actualTpsForFirstSecond = this.tpsGauge.getValue(); - - this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, expectedTpsForSecondSecond); - Thread.sleep(oneSecond); - final int actualTpsForSecondSecond = this.tpsGauge.getValue(); - - this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, expectedTpsForThirdSecond); - Thread.sleep(oneSecond); - final int actualTpsForThirdSecond = this.tpsGauge.getValue(); - - this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, expectedTpsForFourthSecond); - Thread.sleep(oneSecond); - final int actualTpsForFourthSecond = this.tpsGauge.getValue(); - - this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedTpsForFifthSecond); - Thread.sleep(oneSecond); - final int actualTpsForFifthSecond = this.tpsGauge.getValue(); - // Then - assertApproximatelyEquals(expectedTpsForFirstSecond, actualTpsForFirstSecond); - assertApproximatelyEquals(expectedTpsForSecondSecond, actualTpsForSecondSecond); - assertApproximatelyEquals(expectedTpsForThirdSecond, actualTpsForThirdSecond); - assertApproximatelyEquals(expectedTpsForFourthSecond, actualTpsForFourthSecond); - assertApproximatelyEquals(expectedTpsForFifthSecond, actualTpsForFifthSecond); + for (int i = 0; i < testCnt; ++i) { + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_NEW, expectedNumberOfTransactionsPerCollection); + this.transactionCounter.addTransactionCount(SamplingType.SAMPLED_CONTINUATION, expectedNumberOfTransactionsPerCollection); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_NEW, expectedNumberOfTransactionsPerCollection); + this.transactionCounter.addTransactionCount(SamplingType.UNSAMPLED_CONTINUATION, expectedNumberOfTransactionsPerCollection); + // Then + assertEquals(expectedNumberOfTransactionsPerCollection, (long) this.sampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactionsPerCollection, (long) this.sampledContinuationGauge.getValue()); + assertEquals(expectedNumberOfTransactionsPerCollection, (long) this.unsampledNewGauge.getValue()); + assertEquals(expectedNumberOfTransactionsPerCollection, (long) this.unsampledContinuationGuage.getValue()); + } } private void initializeGauge() { - this.tpsGauge.getValue(); - } - - private void assertApproximatelyEquals(int expected, int actual) { - int lowerBound = (expected * 100) - (expected * ACCEPTABLE_DIFF_PERCENTAGE); - int upperBound = (expected * 100) + (expected * ACCEPTABLE_DIFF_PERCENTAGE); - int actualValueForComparison = actual * 100; - assertTrue("expected:[" + expected + "], actual:[" + actual + "]", lowerBound <= actualValueForComparison - && actualValueForComparison <= upperBound); + this.sampledNewGauge.getValue(); + this.sampledContinuationGauge.getValue(); + this.unsampledNewGauge.getValue(); + this.unsampledContinuationGuage.getValue(); } } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/thrift/dto/TAgentStat.java b/thrift/src/main/java/com/navercorp/pinpoint/thrift/dto/TAgentStat.java index 614e6ab18..00287c94c 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/thrift/dto/TAgentStat.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/thrift/dto/TAgentStat.java @@ -34,13 +34,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-10-12") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-10-27") public class TAgentStat implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TAgentStat"); private static final org.apache.thrift.protocol.TField AGENT_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("agentId", org.apache.thrift.protocol.TType.STRING, (short)1); private static final org.apache.thrift.protocol.TField START_TIMESTAMP_FIELD_DESC = new org.apache.thrift.protocol.TField("startTimestamp", org.apache.thrift.protocol.TType.I64, (short)2); private static final org.apache.thrift.protocol.TField TIMESTAMP_FIELD_DESC = new org.apache.thrift.protocol.TField("timestamp", org.apache.thrift.protocol.TType.I64, (short)3); + private static final org.apache.thrift.protocol.TField COLLECT_INTERVAL_FIELD_DESC = new org.apache.thrift.protocol.TField("collectInterval", org.apache.thrift.protocol.TType.I64, (short)4); private static final org.apache.thrift.protocol.TField GC_FIELD_DESC = new org.apache.thrift.protocol.TField("gc", org.apache.thrift.protocol.TType.STRUCT, (short)10); private static final org.apache.thrift.protocol.TField CPU_LOAD_FIELD_DESC = new org.apache.thrift.protocol.TField("cpuLoad", org.apache.thrift.protocol.TType.STRUCT, (short)20); private static final org.apache.thrift.protocol.TField TRANSACTION_FIELD_DESC = new org.apache.thrift.protocol.TField("transaction", org.apache.thrift.protocol.TType.STRUCT, (short)30); @@ -55,6 +56,7 @@ public class TAgentStat implements org.apache.thrift.TBase metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -150,6 +156,8 @@ public class TAgentStat implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TTransaction"); - private static final org.apache.thrift.protocol.TField TPS_FIELD_DESC = new org.apache.thrift.protocol.TField("tps", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("version", org.apache.thrift.protocol.TType.I16, (short)1); + private static final org.apache.thrift.protocol.TField SAMPLED_NEW_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("sampledNewCount", org.apache.thrift.protocol.TType.I64, (short)2); + private static final org.apache.thrift.protocol.TField SAMPLED_CONTINUATION_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("sampledContinuationCount", org.apache.thrift.protocol.TType.I64, (short)3); + private static final org.apache.thrift.protocol.TField UNSAMPLED_NEW_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("unsampledNewCount", org.apache.thrift.protocol.TType.I64, (short)4); + private static final org.apache.thrift.protocol.TField UNSAMPLED_CONTINUATION_COUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("unsampledContinuationCount", org.apache.thrift.protocol.TType.I64, (short)5); private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); static { @@ -46,11 +50,19 @@ public class TTransaction implements org.apache.thrift.TBase byName = new HashMap(); @@ -65,8 +77,16 @@ public class TTransaction implements org.apache.thrift.TBase metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.TPS, new org.apache.thrift.meta_data.FieldMetaData("tps", org.apache.thrift.TFieldRequirementType.OPTIONAL, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.VERSION, new org.apache.thrift.meta_data.FieldMetaData("version", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); + tmpMap.put(_Fields.SAMPLED_NEW_COUNT, new org.apache.thrift.meta_data.FieldMetaData("sampledNewCount", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.SAMPLED_CONTINUATION_COUNT, new org.apache.thrift.meta_data.FieldMetaData("sampledContinuationCount", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.UNSAMPLED_NEW_COUNT, new org.apache.thrift.meta_data.FieldMetaData("unsampledNewCount", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.UNSAMPLED_CONTINUATION_COUNT, new org.apache.thrift.meta_data.FieldMetaData("unsampledContinuationCount", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TTransaction.class, metaDataMap); } public TTransaction() { + this.version = (short)0; + + } + + public TTransaction( + short version) + { + this(); + this.version = version; + setVersionIsSet(true); } /** @@ -127,7 +169,11 @@ public class TTransaction implements org.apache.thrift.TBase list = new ArrayList(); - boolean present_tps = true && (isSetTps()); - list.add(present_tps); - if (present_tps) - list.add(tps); + boolean present_version = true; + list.add(present_version); + if (present_version) + list.add(version); + + boolean present_sampledNewCount = true && (isSetSampledNewCount()); + list.add(present_sampledNewCount); + if (present_sampledNewCount) + list.add(sampledNewCount); + + boolean present_sampledContinuationCount = true && (isSetSampledContinuationCount()); + list.add(present_sampledContinuationCount); + if (present_sampledContinuationCount) + list.add(sampledContinuationCount); + + boolean present_unsampledNewCount = true && (isSetUnsampledNewCount()); + list.add(present_unsampledNewCount); + if (present_unsampledNewCount) + list.add(unsampledNewCount); + + boolean present_unsampledContinuationCount = true && (isSetUnsampledContinuationCount()); + list.add(present_unsampledContinuationCount); + if (present_unsampledContinuationCount) + list.add(unsampledContinuationCount); return list.hashCode(); } @@ -242,12 +492,52 @@ public class TTransaction implements org.apache.thrift.TBase> { final String agentId = BytesUtils.toString(rowKey, 0, AGENT_NAME_MAX_LEN).trim(); final long reverseTimestamp = BytesUtils.bytesToLong(rowKey, AGENT_NAME_MAX_LEN); final long timestamp = TimeUtils.recoveryTimeMillis(reverseTimestamp); - NavigableMap qualifierMap = result.getFamilyMap(AGENT_STAT_CF_STATISTICS); if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_V1)) { @@ -75,39 +74,54 @@ public class AgentStatMapper implements RowMapper> { // FIXME (2015.10) Legacy column for storing serialzied Bos separately. return readSerializedBos(agentId, timestamp, qualifierMap); } - + AgentStat agentStat = new AgentStat(agentId, timestamp); - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_GC_TYPE)) { - agentStat.setGcType(Bytes.toString(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_GC_TYPE))); + if (qualifierMap.containsKey(AGENT_STAT_COL_INTERVAL)) { + agentStat.setCollectInterval(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_INTERVAL))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_COUNT)) { - agentStat.setGcOldCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_COUNT))); + if (qualifierMap.containsKey(AGENT_STAT_COL_GC_TYPE)) { + agentStat.setGcType(Bytes.toString(qualifierMap.get(AGENT_STAT_COL_GC_TYPE))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_TIME)) { - agentStat.setGcOldTime(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_TIME))); + if (qualifierMap.containsKey(AGENT_STAT_COL_GC_OLD_COUNT)) { + agentStat.setGcOldCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_GC_OLD_COUNT))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_HEAP_USED)) { - agentStat.setHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_HEAP_USED))); + if (qualifierMap.containsKey(AGENT_STAT_COL_GC_OLD_TIME)) { + agentStat.setGcOldTime(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_GC_OLD_TIME))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_HEAP_MAX)) { - agentStat.setHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_HEAP_MAX))); + if (qualifierMap.containsKey(AGENT_STAT_COL_HEAP_USED)) { + agentStat.setHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_HEAP_USED))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_USED)) { - agentStat.setNonHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_USED))); + if (qualifierMap.containsKey(AGENT_STAT_COL_HEAP_MAX)) { + agentStat.setHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_HEAP_MAX))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_MAX)) { - agentStat.setNonHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_MAX))); + if (qualifierMap.containsKey(AGENT_STAT_COL_NON_HEAP_USED)) { + agentStat.setNonHeapUsed(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_NON_HEAP_USED))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_JVM_CPU)) { - agentStat.setJvmCpuUsage(Bytes.toDouble(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_JVM_CPU))); + if (qualifierMap.containsKey(AGENT_STAT_COL_NON_HEAP_MAX)) { + agentStat.setNonHeapMax(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_NON_HEAP_MAX))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_SYS_CPU)) { - agentStat.setSystemCpuUsage(Bytes.toDouble(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_SYS_CPU))); + if (qualifierMap.containsKey(AGENT_STAT_COL_JVM_CPU)) { + agentStat.setJvmCpuUsage(Bytes.toDouble(qualifierMap.get(AGENT_STAT_COL_JVM_CPU))); } - if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_COL_TPS)) { - agentStat.setTps(Bytes.toInt(qualifierMap.get(AGENT_STAT_CF_STATISTICS_COL_TPS))); + if (qualifierMap.containsKey(AGENT_STAT_COL_SYS_CPU)) { + agentStat.setSystemCpuUsage(Bytes.toDouble(qualifierMap.get(AGENT_STAT_COL_SYS_CPU))); } - + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_VERSION)) { + agentStat.setTransactionVersion(Bytes.toShort(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_VERSION))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW)) { + agentStat.setSampledNewCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION)) { + agentStat.setSampledContinuationCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW)) { + agentStat.setUnsampledNewCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW))); + } + if (qualifierMap.containsKey(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION)) { + agentStat.setUnsampledContinuationCount(Bytes.toLong(qualifierMap.get(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION))); + } + List agentStats = new ArrayList(); agentStats.add(agentStat); return agentStats; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java index a157c9a9a..d5d9bd862 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentStat.java @@ -26,6 +26,8 @@ public class AgentStat { private final String agentId; private final long timestamp; + private long collectInterval; + private String gcType; private long gcOldCount = NOT_COLLECTED; private long gcOldTime = NOT_COLLECTED; @@ -33,9 +35,15 @@ public class AgentStat { private long heapMax = NOT_COLLECTED; private long nonHeapUsed = NOT_COLLECTED; private long nonHeapMax = NOT_COLLECTED; + private double jvmCpuUsage = NOT_COLLECTED; private double systemCpuUsage = NOT_COLLECTED; - private int tps = NOT_COLLECTED; + + private short transactionVersion; + private long sampledNewCount = NOT_COLLECTED; + private long sampledContinuationCount = NOT_COLLECTED; + private long unsampledNewCount = NOT_COLLECTED; + private long unsampledContinuationCount = NOT_COLLECTED; public AgentStat(String agentId, long timestamp) { if (agentId == null) { @@ -55,6 +63,14 @@ public class AgentStat { public long getTimestamp() { return this.timestamp; } + + public long getCollectInterval() { + return this.collectInterval; + } + + public void setCollectInterval(long collectInterval) { + this.collectInterval = collectInterval; + } public String getGcType() { return gcType; @@ -128,17 +144,55 @@ public class AgentStat { this.systemCpuUsage = systemCpuUsage; } - public int getTps() { - return tps; + public short getTransactionVersion() { + return transactionVersion; } - public void setTps(int tps) { - this.tps = tps; + public void setTransactionVersion(short transactionVersion) { + this.transactionVersion = transactionVersion; + } + + public long getSampledNewCount() { + return sampledNewCount; + } + + public void setSampledNewCount(long sampledNewCount) { + this.sampledNewCount = sampledNewCount; + } + + public long getSampledContinuationCount() { + return sampledContinuationCount; + } + + public void setSampledContinuationCount(long sampledContinuationCount) { + this.sampledContinuationCount = sampledContinuationCount; + } + + public long getUnsampledNewCount() { + return unsampledNewCount; + } + + public void setUnsampledNewCount(long unsampledNewCount) { + this.unsampledNewCount = unsampledNewCount; + } + + public long getUnsampledContinuationCount() { + return unsampledContinuationCount; + } + + public void setUnsampledContinuationCount(long unsampledContinuationCount) { + this.unsampledContinuationCount = unsampledContinuationCount; } @Override public String toString() { - return "AgentStat [agentId=" + agentId + ", timestamp=" + timestamp + ", tps=" + tps + "]"; + return "AgentStat [agentId=" + agentId + ", timestamp=" + timestamp + ", collectInterval=" + collectInterval + + ", gcType=" + gcType + ", gcOldCount=" + gcOldCount + ", gcOldTime=" + gcOldTime + + ", heapUsed=" + heapUsed + ", heapMax=" + heapMax + ", nonHeapUsed=" + nonHeapUsed + + ", nonHeapMax=" + nonHeapMax + ", jvmCpuUsage=" + jvmCpuUsage + ", systemCpuUsage="+ systemCpuUsage + + ", transactionVersion=" + transactionVersion + ", sampledNewCount=" + sampledNewCount + + ", sampledContinuationCount=" + sampledContinuationCount + ", unsampledNewCount=" + unsampledNewCount + + ", unsampledContinuationCount=" + unsampledContinuationCount + "]"; } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java index ca4533fe4..714910a7d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/SampledTimeSeriesDoubleChartBuilder.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo.linechart; +import java.math.BigDecimal; import java.util.List; import com.navercorp.pinpoint.web.util.TimeWindow; @@ -24,30 +25,46 @@ import com.navercorp.pinpoint.web.util.TimeWindow; * @author hyungil.jeong */ public class SampledTimeSeriesDoubleChartBuilder extends SampledTimeSeriesChartBuilder { - + private static final Double DEFAULT_VALUE = 0D; - + private static final int DEFAULT_SCALE = 2; + + private final int scale; + public SampledTimeSeriesDoubleChartBuilder(TimeWindow timeWindow) { - super(timeWindow, DEFAULT_VALUE); + this(timeWindow, DEFAULT_VALUE, DEFAULT_SCALE); } - + public SampledTimeSeriesDoubleChartBuilder(TimeWindow timeWindow, double defaultValue) { - super(timeWindow, defaultValue); + this(timeWindow, defaultValue, DEFAULT_SCALE); } - + + public SampledTimeSeriesDoubleChartBuilder(TimeWindow timeWindow, double defaultValue, int scale) { + super(timeWindow, defaultValue); + if (scale < 1) { + this.scale = DEFAULT_SCALE; + } else { + this.scale = scale; + } + } + @Override protected Double sampleMin(List sampleBuffer) { - return DownSamplers.MIN.sampleDouble(sampleBuffer); + return roundToScale(DownSamplers.MIN.sampleDouble(sampleBuffer)); } @Override protected Double sampleMax(List sampleBuffer) { - return DownSamplers.MAX.sampleDouble(sampleBuffer); + return roundToScale(DownSamplers.MAX.sampleDouble(sampleBuffer)); } @Override protected Double sampleAvg(List sampleBuffer) { - return DownSamplers.AVG.sampleDouble(sampleBuffer); + return roundToScale(DownSamplers.AVG.sampleDouble(sampleBuffer)); + } + + private double roundToScale(double value) { + return new BigDecimal(value).setScale(this.scale, BigDecimal.ROUND_HALF_UP).doubleValue(); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java index a87dc0262..68ab2da58 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/linechart/agentstat/AgentStatChartGroup.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo.linechart.agentstat; +import java.math.BigDecimal; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -25,7 +26,6 @@ import com.navercorp.pinpoint.web.vo.AgentStat; import com.navercorp.pinpoint.web.vo.linechart.Chart; import com.navercorp.pinpoint.web.vo.linechart.DataPoint; import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesDoubleChartBuilder; -import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesIntegerChartBuilder; import com.navercorp.pinpoint.web.vo.linechart.SampledTimeSeriesLongChartBuilder; import com.navercorp.pinpoint.web.vo.linechart.Chart.ChartBuilder; @@ -37,24 +37,28 @@ public class AgentStatChartGroup { private static enum ChartType { JVM_MEMORY_HEAP_USED, - JVM_MEMORY_HEAP_MAX, - JVM_MEMORY_NON_HEAP_USED, - JVM_MEMORY_NON_HEAP_MAX, - JVM_GC_OLD_COUNT, - JVM_GC_OLD_TIME, - CPU_LOAD_JVM, + JVM_MEMORY_HEAP_MAX, + JVM_MEMORY_NON_HEAP_USED, + JVM_MEMORY_NON_HEAP_MAX, + JVM_GC_OLD_COUNT, + JVM_GC_OLD_TIME, + CPU_LOAD_JVM, CPU_LOAD_SYSTEM, - TPS + TPS_SAMPLED_NEW, + TPS_SAMPLED_CONTINUATION, + TPS_UNSAMPLED_NEW, + TPS_UNSAMPLED_CONTINUATION, + TPS_TOTAL } - + private static final int UNCOLLECTED_DATA = AgentStat.NOT_COLLECTED; private String type; private final Map> chartBuilders; - + private final Map charts; - + public AgentStatChartGroup(TimeWindow timeWindow) { this.chartBuilders = new EnumMap>(ChartType.class); this.chartBuilders.put(ChartType.JVM_MEMORY_HEAP_USED, new SampledTimeSeriesLongChartBuilder(timeWindow, UNCOLLECTED_DATA)); @@ -65,7 +69,11 @@ public class AgentStatChartGroup { this.chartBuilders.put(ChartType.JVM_GC_OLD_TIME, new SampledTimeSeriesLongChartBuilder(timeWindow, UNCOLLECTED_DATA)); this.chartBuilders.put(ChartType.CPU_LOAD_JVM, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA)); this.chartBuilders.put(ChartType.CPU_LOAD_SYSTEM, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA)); - this.chartBuilders.put(ChartType.TPS, new SampledTimeSeriesIntegerChartBuilder(timeWindow, UNCOLLECTED_DATA)); + this.chartBuilders.put(ChartType.TPS_SAMPLED_NEW, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA, 1)); + this.chartBuilders.put(ChartType.TPS_SAMPLED_CONTINUATION, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA, 1)); + this.chartBuilders.put(ChartType.TPS_UNSAMPLED_NEW, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA, 1)); + this.chartBuilders.put(ChartType.TPS_UNSAMPLED_CONTINUATION, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA, 1)); + this.chartBuilders.put(ChartType.TPS_TOTAL, new SampledTimeSeriesDoubleChartBuilder(timeWindow, UNCOLLECTED_DATA, 1)); this.charts = new EnumMap(ChartType.class); } @@ -88,25 +96,45 @@ public class AgentStatChartGroup { private void addMemoryGcData(AgentStat agentStat) { this.type = agentStat.getGcType(); long timestamp = agentStat.getTimestamp(); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_USED)).addDataPoint(new DataPoint(timestamp, agentStat.getHeapUsed())); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_MAX)).addDataPoint(new DataPoint(timestamp, agentStat.getHeapMax())); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_USED)).addDataPoint(new DataPoint(timestamp, agentStat.getNonHeapUsed())); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_MAX)).addDataPoint(new DataPoint(timestamp, agentStat.getNonHeapMax())); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_GC_OLD_COUNT)).addDataPoint(new DataPoint(timestamp, agentStat.getGcOldCount())); - ((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_GC_OLD_TIME)).addDataPoint(new DataPoint(timestamp, agentStat.getGcOldTime())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_USED)).addDataPoint(new DataPoint(timestamp, agentStat.getHeapUsed())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_MAX)).addDataPoint(new DataPoint(timestamp, agentStat.getHeapMax())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_USED)).addDataPoint(new DataPoint(timestamp, agentStat.getNonHeapUsed())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_MAX)).addDataPoint(new DataPoint(timestamp, agentStat.getNonHeapMax())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_COUNT)).addDataPoint(new DataPoint(timestamp, agentStat.getGcOldCount())); + ((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_TIME)).addDataPoint(new DataPoint(timestamp, agentStat.getGcOldTime())); } private void addCpuLoadData(AgentStat agentStat) { long timestamp = agentStat.getTimestamp(); double jvmCpuUsagePercentage = agentStat.getJvmCpuUsage() * 100; double systemCpuUsagePercentage = agentStat.getSystemCpuUsage() * 100; - ((SampledTimeSeriesDoubleChartBuilder)this.chartBuilders.get(ChartType.CPU_LOAD_JVM)).addDataPoint(new DataPoint(timestamp, jvmCpuUsagePercentage)); - ((SampledTimeSeriesDoubleChartBuilder)this.chartBuilders.get(ChartType.CPU_LOAD_SYSTEM)).addDataPoint(new DataPoint(timestamp, systemCpuUsagePercentage)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_JVM)).addDataPoint(new DataPoint(timestamp, jvmCpuUsagePercentage)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_SYSTEM)).addDataPoint(new DataPoint(timestamp, systemCpuUsagePercentage)); } private void addTransactionData(AgentStat agentStat) { long timestamp = agentStat.getTimestamp(); - ((SampledTimeSeriesIntegerChartBuilder)this.chartBuilders.get(ChartType.TPS)).addDataPoint(new DataPoint(timestamp, agentStat.getTps())); + long interval = agentStat.getCollectInterval(); + if (interval > 0) { + double sampledNewTps = calculateTps(agentStat.getSampledNewCount(), interval); + double sampledContinuationTps = calculateTps(agentStat.getSampledContinuationCount(), interval); + double unsampledNewTps = calculateTps(agentStat.getUnsampledNewCount(), interval); + double unsampledContinuationTps = calculateTps(agentStat.getUnsampledContinuationCount(), interval); + double totalTps = sampledNewTps + sampledContinuationTps + unsampledNewTps + unsampledContinuationTps; + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_SAMPLED_NEW)).addDataPoint(new DataPoint(timestamp, sampledNewTps)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_SAMPLED_CONTINUATION)).addDataPoint(new DataPoint(timestamp, sampledContinuationTps)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_NEW)).addDataPoint(new DataPoint(timestamp, unsampledNewTps)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_CONTINUATION)).addDataPoint(new DataPoint(timestamp, unsampledContinuationTps)); + ((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_TOTAL)).addDataPoint(new DataPoint(timestamp, totalTps)); + } + } + + private double calculateTps(long count, long intervalMs) { + final int numDecimal = 1; + if (count == UNCOLLECTED_DATA) { + return UNCOLLECTED_DATA; + } + return new BigDecimal(count / (intervalMs / 1000D)).setScale(numDecimal, BigDecimal.ROUND_HALF_UP).doubleValue(); } public String getType() { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java index bb5f0de64..166b08633 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/mapper/AgentStatMapperTest.java @@ -64,6 +64,8 @@ public class AgentStatMapperTest { private static final long TIMESTAMP = System.currentTimeMillis(); private static final byte[] ROW_KEY = RowKeyUtils.concatFixedByteAndLong(BytesUtils.toBytes(AGENT_ID), AGENT_NAME_MAX_LEN, TimeUtils.reverseTimeMillis(TIMESTAMP)); + private static final long COLLECT_INTERVAL = 5000L; + private static final TJvmGcType GC_TYPE = TJvmGcType.G1; private static final long GC_OLD_COUNT = 0L; private static final long GC_OLD_TIME = Long.MAX_VALUE; @@ -75,7 +77,11 @@ public class AgentStatMapperTest { private static final double JVM_CPU_USAGE = 10; private static final double SYS_CPU_USAGE = 20; - private static final int TPS = 100; + private static final short TRANSACTION_VERSION = 1; + private static final long SAMPLED_NEW_COUNT = 100L; + private static final long SAMPLED_CONTINUATION_COUNT = 200L; + private static final long UNSAMPLED_NEW_COUNT = 50L; + private static final long UNSAMPLED_CONTINUATION_COUNT = 150L; @Mock private RowKeyDistributorByHashPrefix rowKeyDistributorByHashPrefix; @@ -93,16 +99,21 @@ public class AgentStatMapperTest { public void test_current() throws Exception { // Given final Result result = Result.create(Arrays.asList( - createCell(AGENT_STAT_CF_STATISTICS_COL_GC_TYPE, Bytes.toBytes(GC_TYPE.name())), - createCell(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_COUNT, Bytes.toBytes(GC_OLD_COUNT)), - createCell(AGENT_STAT_CF_STATISTICS_COL_GC_OLD_TIME, Bytes.toBytes(GC_OLD_TIME)), - createCell(AGENT_STAT_CF_STATISTICS_COL_HEAP_USED, Bytes.toBytes(HEAP_USED)), - createCell(AGENT_STAT_CF_STATISTICS_COL_HEAP_MAX, Bytes.toBytes(HEAP_MAX)), - createCell(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_USED, Bytes.toBytes(NON_HEAP_USED)), - createCell(AGENT_STAT_CF_STATISTICS_COL_NON_HEAP_MAX, Bytes.toBytes(NON_HEAP_MAX)), - createCell(AGENT_STAT_CF_STATISTICS_COL_JVM_CPU, Bytes.toBytes(JVM_CPU_USAGE)), - createCell(AGENT_STAT_CF_STATISTICS_COL_SYS_CPU, Bytes.toBytes(SYS_CPU_USAGE)), - createCell(AGENT_STAT_CF_STATISTICS_COL_TPS, Bytes.toBytes(TPS)) + createCell(AGENT_STAT_COL_INTERVAL, Bytes.toBytes(COLLECT_INTERVAL)), + createCell(AGENT_STAT_COL_GC_TYPE, Bytes.toBytes(GC_TYPE.name())), + createCell(AGENT_STAT_COL_GC_OLD_COUNT, Bytes.toBytes(GC_OLD_COUNT)), + createCell(AGENT_STAT_COL_GC_OLD_TIME, Bytes.toBytes(GC_OLD_TIME)), + createCell(AGENT_STAT_COL_HEAP_USED, Bytes.toBytes(HEAP_USED)), + createCell(AGENT_STAT_COL_HEAP_MAX, Bytes.toBytes(HEAP_MAX)), + createCell(AGENT_STAT_COL_NON_HEAP_USED, Bytes.toBytes(NON_HEAP_USED)), + createCell(AGENT_STAT_COL_NON_HEAP_MAX, Bytes.toBytes(NON_HEAP_MAX)), + createCell(AGENT_STAT_COL_JVM_CPU, Bytes.toBytes(JVM_CPU_USAGE)), + createCell(AGENT_STAT_COL_SYS_CPU, Bytes.toBytes(SYS_CPU_USAGE)), + createCell(AGENT_STAT_COL_TRANSACTION_VERSION, Bytes.toBytes(TRANSACTION_VERSION)), + createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_NEW, Bytes.toBytes(SAMPLED_NEW_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_SAMPLED_CONTINUATION, Bytes.toBytes(SAMPLED_CONTINUATION_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_NEW, Bytes.toBytes(UNSAMPLED_NEW_COUNT)), + createCell(AGENT_STAT_COL_TRANSACTION_UNSAMPLED_CONTINUATION, Bytes.toBytes(UNSAMPLED_CONTINUATION_COUNT)) )); // When List agentStats = this.mapper.mapRow(result, 0); @@ -111,6 +122,7 @@ public class AgentStatMapperTest { assertThat(agentStats.size(), is(1)); AgentStat agentStat = agentStats.get(0); + assertEquals(COLLECT_INTERVAL, agentStat.getCollectInterval()); assertJvmGc(agentStat); assertCpuUsage(agentStat); assertTransaction(agentStat); @@ -127,10 +139,15 @@ public class AgentStatMapperTest { assertThat(agentStats.size(), is(1)); AgentStat agentStat = agentStats.get(0); + assertEquals(0, agentStat.getCollectInterval()); assertJvmGc(agentStat); assertEquals(AgentStat.NOT_COLLECTED, agentStat.getJvmCpuUsage(), DELTA); assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSystemCpuUsage(), DELTA); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getTps()); + assertEquals(0, agentStat.getTransactionVersion()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); } @Test @@ -144,9 +161,14 @@ public class AgentStatMapperTest { assertThat(agentStats.size(), is(1)); AgentStat agentStat = agentStats.get(0); + assertEquals(0, agentStat.getCollectInterval()); assertJvmGc(agentStat); assertCpuUsage(agentStat); - assertEquals(AgentStat.NOT_COLLECTED, agentStat.getTps()); + assertEquals(0, agentStat.getTransactionVersion()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getSampledContinuationCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledNewCount()); + assertEquals(AgentStat.NOT_COLLECTED, agentStat.getUnsampledContinuationCount()); } private void assertJvmGc(AgentStat agentStat) { @@ -167,7 +189,11 @@ public class AgentStatMapperTest { } private void assertTransaction(AgentStat agentStat) { - assertEquals(TPS, agentStat.getTps()); + assertEquals(TRANSACTION_VERSION, agentStat.getTransactionVersion()); + assertEquals(SAMPLED_NEW_COUNT, agentStat.getSampledNewCount()); + assertEquals(SAMPLED_CONTINUATION_COUNT, agentStat.getSampledContinuationCount()); + assertEquals(UNSAMPLED_NEW_COUNT, agentStat.getUnsampledNewCount()); + assertEquals(UNSAMPLED_CONTINUATION_COUNT, agentStat.getUnsampledContinuationCount()); } private Result createResultForLegacyWith_AGENT_STAT_CF_STATISTICS_V1() throws TException {