#1069 Add transaction metric support

This commit is contained in:
HyunGil Jeong
2015-10-28 16:26:26 +09:00
parent 31ade18329
commit b6367f53cf
16 changed files with 965 additions and 301 deletions
@@ -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);
@@ -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";
@@ -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<TAgentStat> agentStats;
private CollectJob(int numStatsPerBatch) {
@@ -118,9 +119,14 @@ public class AgentStatMonitor {
this.agentStats = new ArrayList<TAgentStat>(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<TAgentStat>(this.numStatsPerBatch);
if (isTrace) {
@@ -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() {
}
@@ -32,22 +32,33 @@ import com.navercorp.pinpoint.thrift.dto.TTransaction;
*/
public class TransactionMetricCollector implements AgentStatCollector<TTransaction> {
public static final int UNSUPPORTED_TPS_METRIC = -1;
private final Gauge<Integer> tpsGauge;
public static final long UNSUPPORTED_TRANSACTION_METRIC = -1;
private static final Gauge<Long> UNSUPPORTED_GAUGE = new EmptyGauge<Long>(UNSUPPORTED_TRANSACTION_METRIC);
private final Gauge<Long> sampledNewGauge;
private final Gauge<Long> sampledContinuationGauge;
private final Gauge<Long> unsampledNewGauge;
private final Gauge<Long> 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<String, Metric> metrics = transactionMetricSet.getMetrics();
this.tpsGauge = (Gauge<Integer>)MetricMonitorValues.getMetric(metrics, TRANSACTION_PER_SECOND, new EmptyGauge<Integer>(UNSUPPORTED_TPS_METRIC));
this.sampledNewGauge = (Gauge<Long>)MetricMonitorValues.getMetric(metrics, TRANSACTION_SAMPLED_NEW, UNSUPPORTED_GAUGE);
this.sampledContinuationGauge = (Gauge<Long>)MetricMonitorValues.getMetric(metrics, TRANSACTION_SAMPLED_CONTINUATION, UNSUPPORTED_GAUGE);
this.unsampledNewGauge = (Gauge<Long>)MetricMonitorValues.getMetric(metrics, TRANSACTION_UNSAMPLED_NEW, UNSUPPORTED_GAUGE);
this.unsampledContinuationGuage = (Gauge<Long>)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;
}
}
@@ -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<Integer> tpsGauge;
private final Gauge<Long> sampledNewGauge;
private final Gauge<Long> sampledContinuationGauge;
private final Gauge<Long> unsampledNewGauge;
private final Gauge<Long> 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<String, Metric> getMetrics() {
final Map<String, Metric> gauges = new HashMap<String, Metric>();
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<Integer> {
private class TransactionGauge implements Gauge<Long> {
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;
}
}
}
}
@@ -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());
@@ -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<Integer> tpsGauge;
private Gauge<Long> sampledNewGauge;
private Gauge<Long> sampledContinuationGauge;
private Gauge<Long> unsampledNewGauge;
private Gauge<Long> unsampledContinuationGuage;
@Before
@SuppressWarnings("unchecked")
public void setUp() {
this.transactionCounter = new TestableTransactionCounter();
TransactionMetricSet metricSet = new TransactionMetricSet(this.transactionCounter);
this.tpsGauge = (Gauge<Integer>)metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_PER_SECOND);
this.sampledNewGauge = (Gauge<Long>) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_SAMPLED_NEW);
this.sampledContinuationGauge = (Gauge<Long>) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_SAMPLED_CONTINUATION);
this.unsampledNewGauge = (Gauge<Long>) metricSet.getMetrics().get(MetricMonitorValues.TRANSACTION_UNSAMPLED_NEW);
this.unsampledContinuationGuage = (Gauge<Long>) 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();
}
}
@@ -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<TAgentStat, TAgentStat._Fields>, java.io.Serializable, Cloneable, Comparable<TAgentStat> {
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<TAgentStat, TAgentSta
private String agentId; // optional
private long startTimestamp; // optional
private long timestamp; // optional
private long collectInterval; // optional
private TJvmGc gc; // optional
private TCpuLoad cpuLoad; // optional
private TTransaction transaction; // optional
@@ -65,6 +67,7 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
AGENT_ID((short)1, "agentId"),
START_TIMESTAMP((short)2, "startTimestamp"),
TIMESTAMP((short)3, "timestamp"),
COLLECT_INTERVAL((short)4, "collectInterval"),
GC((short)10, "gc"),
CPU_LOAD((short)20, "cpuLoad"),
TRANSACTION((short)30, "transaction"),
@@ -89,6 +92,8 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
return START_TIMESTAMP;
case 3: // TIMESTAMP
return TIMESTAMP;
case 4: // COLLECT_INTERVAL
return COLLECT_INTERVAL;
case 10: // GC
return GC;
case 20: // CPU_LOAD
@@ -139,8 +144,9 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
// isset id assignments
private static final int __STARTTIMESTAMP_ISSET_ID = 0;
private static final int __TIMESTAMP_ISSET_ID = 1;
private static final int __COLLECTINTERVAL_ISSET_ID = 2;
private byte __isset_bitfield = 0;
private static final _Fields optionals[] = {_Fields.AGENT_ID,_Fields.START_TIMESTAMP,_Fields.TIMESTAMP,_Fields.GC,_Fields.CPU_LOAD,_Fields.TRANSACTION,_Fields.METADATA};
private static final _Fields optionals[] = {_Fields.AGENT_ID,_Fields.START_TIMESTAMP,_Fields.TIMESTAMP,_Fields.COLLECT_INTERVAL,_Fields.GC,_Fields.CPU_LOAD,_Fields.TRANSACTION,_Fields.METADATA};
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> 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<TAgentStat, TAgentSta
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
tmpMap.put(_Fields.TIMESTAMP, new org.apache.thrift.meta_data.FieldMetaData("timestamp", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
tmpMap.put(_Fields.COLLECT_INTERVAL, new org.apache.thrift.meta_data.FieldMetaData("collectInterval", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
tmpMap.put(_Fields.GC, new org.apache.thrift.meta_data.FieldMetaData("gc", org.apache.thrift.TFieldRequirementType.OPTIONAL,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TJvmGc.class)));
tmpMap.put(_Fields.CPU_LOAD, new org.apache.thrift.meta_data.FieldMetaData("cpuLoad", org.apache.thrift.TFieldRequirementType.OPTIONAL,
@@ -175,6 +183,7 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
}
this.startTimestamp = other.startTimestamp;
this.timestamp = other.timestamp;
this.collectInterval = other.collectInterval;
if (other.isSetGc()) {
this.gc = new TJvmGc(other.gc);
}
@@ -200,6 +209,8 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
this.startTimestamp = 0;
setTimestampIsSet(false);
this.timestamp = 0;
setCollectIntervalIsSet(false);
this.collectInterval = 0;
this.gc = null;
this.cpuLoad = null;
this.transaction = null;
@@ -273,6 +284,28 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TIMESTAMP_ISSET_ID, value);
}
public long getCollectInterval() {
return this.collectInterval;
}
public void setCollectInterval(long collectInterval) {
this.collectInterval = collectInterval;
setCollectIntervalIsSet(true);
}
public void unsetCollectInterval() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __COLLECTINTERVAL_ISSET_ID);
}
/** Returns true if field collectInterval is set (has been assigned a value) and false otherwise */
public boolean isSetCollectInterval() {
return EncodingUtils.testBit(__isset_bitfield, __COLLECTINTERVAL_ISSET_ID);
}
public void setCollectIntervalIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __COLLECTINTERVAL_ISSET_ID, value);
}
public TJvmGc getGc() {
return this.gc;
}
@@ -391,6 +424,14 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
}
break;
case COLLECT_INTERVAL:
if (value == null) {
unsetCollectInterval();
} else {
setCollectInterval((Long)value);
}
break;
case GC:
if (value == null) {
unsetGc();
@@ -437,6 +478,9 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
case TIMESTAMP:
return Long.valueOf(getTimestamp());
case COLLECT_INTERVAL:
return Long.valueOf(getCollectInterval());
case GC:
return getGc();
@@ -466,6 +510,8 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
return isSetStartTimestamp();
case TIMESTAMP:
return isSetTimestamp();
case COLLECT_INTERVAL:
return isSetCollectInterval();
case GC:
return isSetGc();
case CPU_LOAD:
@@ -518,6 +564,15 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
return false;
}
boolean this_present_collectInterval = true && this.isSetCollectInterval();
boolean that_present_collectInterval = true && that.isSetCollectInterval();
if (this_present_collectInterval || that_present_collectInterval) {
if (!(this_present_collectInterval && that_present_collectInterval))
return false;
if (this.collectInterval != that.collectInterval)
return false;
}
boolean this_present_gc = true && this.isSetGc();
boolean that_present_gc = true && that.isSetGc();
if (this_present_gc || that_present_gc) {
@@ -576,6 +631,11 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
if (present_timestamp)
list.add(timestamp);
boolean present_collectInterval = true && (isSetCollectInterval());
list.add(present_collectInterval);
if (present_collectInterval)
list.add(collectInterval);
boolean present_gc = true && (isSetGc());
list.add(present_gc);
if (present_gc)
@@ -637,6 +697,16 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetCollectInterval()).compareTo(other.isSetCollectInterval());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetCollectInterval()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.collectInterval, other.collectInterval);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetGc()).compareTo(other.isSetGc());
if (lastComparison != 0) {
return lastComparison;
@@ -718,6 +788,12 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
sb.append(this.timestamp);
first = false;
}
if (isSetCollectInterval()) {
if (!first) sb.append(", ");
sb.append("collectInterval:");
sb.append(this.collectInterval);
first = false;
}
if (isSetGc()) {
if (!first) sb.append(", ");
sb.append("gc:");
@@ -836,6 +912,14 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 4: // COLLECT_INTERVAL
if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
struct.collectInterval = iprot.readI64();
struct.setCollectIntervalIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 10: // GC
if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
struct.gc = new TJvmGc();
@@ -901,6 +985,11 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
oprot.writeI64(struct.timestamp);
oprot.writeFieldEnd();
}
if (struct.isSetCollectInterval()) {
oprot.writeFieldBegin(COLLECT_INTERVAL_FIELD_DESC);
oprot.writeI64(struct.collectInterval);
oprot.writeFieldEnd();
}
if (struct.gc != null) {
if (struct.isSetGc()) {
oprot.writeFieldBegin(GC_FIELD_DESC);
@@ -956,19 +1045,22 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
if (struct.isSetTimestamp()) {
optionals.set(2);
}
if (struct.isSetGc()) {
if (struct.isSetCollectInterval()) {
optionals.set(3);
}
if (struct.isSetCpuLoad()) {
if (struct.isSetGc()) {
optionals.set(4);
}
if (struct.isSetTransaction()) {
if (struct.isSetCpuLoad()) {
optionals.set(5);
}
if (struct.isSetMetadata()) {
if (struct.isSetTransaction()) {
optionals.set(6);
}
oprot.writeBitSet(optionals, 7);
if (struct.isSetMetadata()) {
optionals.set(7);
}
oprot.writeBitSet(optionals, 8);
if (struct.isSetAgentId()) {
oprot.writeString(struct.agentId);
}
@@ -978,6 +1070,9 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
if (struct.isSetTimestamp()) {
oprot.writeI64(struct.timestamp);
}
if (struct.isSetCollectInterval()) {
oprot.writeI64(struct.collectInterval);
}
if (struct.isSetGc()) {
struct.gc.write(oprot);
}
@@ -995,7 +1090,7 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, TAgentStat struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(7);
BitSet incoming = iprot.readBitSet(8);
if (incoming.get(0)) {
struct.agentId = iprot.readString();
struct.setAgentIdIsSet(true);
@@ -1009,21 +1104,25 @@ public class TAgentStat implements org.apache.thrift.TBase<TAgentStat, TAgentSta
struct.setTimestampIsSet(true);
}
if (incoming.get(3)) {
struct.collectInterval = iprot.readI64();
struct.setCollectIntervalIsSet(true);
}
if (incoming.get(4)) {
struct.gc = new TJvmGc();
struct.gc.read(iprot);
struct.setGcIsSet(true);
}
if (incoming.get(4)) {
if (incoming.get(5)) {
struct.cpuLoad = new TCpuLoad();
struct.cpuLoad.read(iprot);
struct.setCpuLoadIsSet(true);
}
if (incoming.get(5)) {
if (incoming.get(6)) {
struct.transaction = new TTransaction();
struct.transaction.read(iprot);
struct.setTransactionIsSet(true);
}
if (incoming.get(6)) {
if (incoming.get(7)) {
struct.metadata = iprot.readString();
struct.setMetadataIsSet(true);
}
@@ -34,11 +34,15 @@ 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 TTransaction implements org.apache.thrift.TBase<TTransaction, TTransaction._Fields>, java.io.Serializable, Cloneable, Comparable<TTransaction> {
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<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
@@ -46,11 +50,19 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
schemes.put(TupleScheme.class, new TTransactionTupleSchemeFactory());
}
private int tps; // optional
private short version; // required
private long sampledNewCount; // optional
private long sampledContinuationCount; // optional
private long unsampledNewCount; // optional
private long unsampledContinuationCount; // optional
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
TPS((short)1, "tps");
VERSION((short)1, "version"),
SAMPLED_NEW_COUNT((short)2, "sampledNewCount"),
SAMPLED_CONTINUATION_COUNT((short)3, "sampledContinuationCount"),
UNSAMPLED_NEW_COUNT((short)4, "unsampledNewCount"),
UNSAMPLED_CONTINUATION_COUNT((short)5, "unsampledContinuationCount");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@@ -65,8 +77,16 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
*/
public static _Fields findByThriftId(int fieldId) {
switch(fieldId) {
case 1: // TPS
return TPS;
case 1: // VERSION
return VERSION;
case 2: // SAMPLED_NEW_COUNT
return SAMPLED_NEW_COUNT;
case 3: // SAMPLED_CONTINUATION_COUNT
return SAMPLED_CONTINUATION_COUNT;
case 4: // UNSAMPLED_NEW_COUNT
return UNSAMPLED_NEW_COUNT;
case 5: // UNSAMPLED_CONTINUATION_COUNT
return UNSAMPLED_CONTINUATION_COUNT;
default:
return null;
}
@@ -107,19 +127,41 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
}
// isset id assignments
private static final int __TPS_ISSET_ID = 0;
private static final int __VERSION_ISSET_ID = 0;
private static final int __SAMPLEDNEWCOUNT_ISSET_ID = 1;
private static final int __SAMPLEDCONTINUATIONCOUNT_ISSET_ID = 2;
private static final int __UNSAMPLEDNEWCOUNT_ISSET_ID = 3;
private static final int __UNSAMPLEDCONTINUATIONCOUNT_ISSET_ID = 4;
private byte __isset_bitfield = 0;
private static final _Fields optionals[] = {_Fields.TPS};
private static final _Fields optionals[] = {_Fields.SAMPLED_NEW_COUNT,_Fields.SAMPLED_CONTINUATION_COUNT,_Fields.UNSAMPLED_NEW_COUNT,_Fields.UNSAMPLED_CONTINUATION_COUNT};
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> 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<TTransaction, TTran
*/
public TTransaction(TTransaction other) {
__isset_bitfield = other.__isset_bitfield;
this.tps = other.tps;
this.version = other.version;
this.sampledNewCount = other.sampledNewCount;
this.sampledContinuationCount = other.sampledContinuationCount;
this.unsampledNewCount = other.unsampledNewCount;
this.unsampledContinuationCount = other.unsampledContinuationCount;
}
public TTransaction deepCopy() {
@@ -136,39 +182,167 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
@Override
public void clear() {
setTpsIsSet(false);
this.tps = 0;
this.version = (short)0;
setSampledNewCountIsSet(false);
this.sampledNewCount = 0;
setSampledContinuationCountIsSet(false);
this.sampledContinuationCount = 0;
setUnsampledNewCountIsSet(false);
this.unsampledNewCount = 0;
setUnsampledContinuationCountIsSet(false);
this.unsampledContinuationCount = 0;
}
public int getTps() {
return this.tps;
public short getVersion() {
return this.version;
}
public void setTps(int tps) {
this.tps = tps;
setTpsIsSet(true);
public void setVersion(short version) {
this.version = version;
setVersionIsSet(true);
}
public void unsetTps() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TPS_ISSET_ID);
public void unsetVersion() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __VERSION_ISSET_ID);
}
/** Returns true if field tps is set (has been assigned a value) and false otherwise */
public boolean isSetTps() {
return EncodingUtils.testBit(__isset_bitfield, __TPS_ISSET_ID);
/** Returns true if field version is set (has been assigned a value) and false otherwise */
public boolean isSetVersion() {
return EncodingUtils.testBit(__isset_bitfield, __VERSION_ISSET_ID);
}
public void setTpsIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TPS_ISSET_ID, value);
public void setVersionIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __VERSION_ISSET_ID, value);
}
public long getSampledNewCount() {
return this.sampledNewCount;
}
public void setSampledNewCount(long sampledNewCount) {
this.sampledNewCount = sampledNewCount;
setSampledNewCountIsSet(true);
}
public void unsetSampledNewCount() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SAMPLEDNEWCOUNT_ISSET_ID);
}
/** Returns true if field sampledNewCount is set (has been assigned a value) and false otherwise */
public boolean isSetSampledNewCount() {
return EncodingUtils.testBit(__isset_bitfield, __SAMPLEDNEWCOUNT_ISSET_ID);
}
public void setSampledNewCountIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SAMPLEDNEWCOUNT_ISSET_ID, value);
}
public long getSampledContinuationCount() {
return this.sampledContinuationCount;
}
public void setSampledContinuationCount(long sampledContinuationCount) {
this.sampledContinuationCount = sampledContinuationCount;
setSampledContinuationCountIsSet(true);
}
public void unsetSampledContinuationCount() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SAMPLEDCONTINUATIONCOUNT_ISSET_ID);
}
/** Returns true if field sampledContinuationCount is set (has been assigned a value) and false otherwise */
public boolean isSetSampledContinuationCount() {
return EncodingUtils.testBit(__isset_bitfield, __SAMPLEDCONTINUATIONCOUNT_ISSET_ID);
}
public void setSampledContinuationCountIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SAMPLEDCONTINUATIONCOUNT_ISSET_ID, value);
}
public long getUnsampledNewCount() {
return this.unsampledNewCount;
}
public void setUnsampledNewCount(long unsampledNewCount) {
this.unsampledNewCount = unsampledNewCount;
setUnsampledNewCountIsSet(true);
}
public void unsetUnsampledNewCount() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __UNSAMPLEDNEWCOUNT_ISSET_ID);
}
/** Returns true if field unsampledNewCount is set (has been assigned a value) and false otherwise */
public boolean isSetUnsampledNewCount() {
return EncodingUtils.testBit(__isset_bitfield, __UNSAMPLEDNEWCOUNT_ISSET_ID);
}
public void setUnsampledNewCountIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __UNSAMPLEDNEWCOUNT_ISSET_ID, value);
}
public long getUnsampledContinuationCount() {
return this.unsampledContinuationCount;
}
public void setUnsampledContinuationCount(long unsampledContinuationCount) {
this.unsampledContinuationCount = unsampledContinuationCount;
setUnsampledContinuationCountIsSet(true);
}
public void unsetUnsampledContinuationCount() {
__isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __UNSAMPLEDCONTINUATIONCOUNT_ISSET_ID);
}
/** Returns true if field unsampledContinuationCount is set (has been assigned a value) and false otherwise */
public boolean isSetUnsampledContinuationCount() {
return EncodingUtils.testBit(__isset_bitfield, __UNSAMPLEDCONTINUATIONCOUNT_ISSET_ID);
}
public void setUnsampledContinuationCountIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __UNSAMPLEDCONTINUATIONCOUNT_ISSET_ID, value);
}
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case TPS:
case VERSION:
if (value == null) {
unsetTps();
unsetVersion();
} else {
setTps((Integer)value);
setVersion((Short)value);
}
break;
case SAMPLED_NEW_COUNT:
if (value == null) {
unsetSampledNewCount();
} else {
setSampledNewCount((Long)value);
}
break;
case SAMPLED_CONTINUATION_COUNT:
if (value == null) {
unsetSampledContinuationCount();
} else {
setSampledContinuationCount((Long)value);
}
break;
case UNSAMPLED_NEW_COUNT:
if (value == null) {
unsetUnsampledNewCount();
} else {
setUnsampledNewCount((Long)value);
}
break;
case UNSAMPLED_CONTINUATION_COUNT:
if (value == null) {
unsetUnsampledContinuationCount();
} else {
setUnsampledContinuationCount((Long)value);
}
break;
@@ -177,8 +351,20 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
public Object getFieldValue(_Fields field) {
switch (field) {
case TPS:
return Integer.valueOf(getTps());
case VERSION:
return Short.valueOf(getVersion());
case SAMPLED_NEW_COUNT:
return Long.valueOf(getSampledNewCount());
case SAMPLED_CONTINUATION_COUNT:
return Long.valueOf(getSampledContinuationCount());
case UNSAMPLED_NEW_COUNT:
return Long.valueOf(getUnsampledNewCount());
case UNSAMPLED_CONTINUATION_COUNT:
return Long.valueOf(getUnsampledContinuationCount());
}
throw new IllegalStateException();
@@ -191,8 +377,16 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
}
switch (field) {
case TPS:
return isSetTps();
case VERSION:
return isSetVersion();
case SAMPLED_NEW_COUNT:
return isSetSampledNewCount();
case SAMPLED_CONTINUATION_COUNT:
return isSetSampledContinuationCount();
case UNSAMPLED_NEW_COUNT:
return isSetUnsampledNewCount();
case UNSAMPLED_CONTINUATION_COUNT:
return isSetUnsampledContinuationCount();
}
throw new IllegalStateException();
}
@@ -210,12 +404,48 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
if (that == null)
return false;
boolean this_present_tps = true && this.isSetTps();
boolean that_present_tps = true && that.isSetTps();
if (this_present_tps || that_present_tps) {
if (!(this_present_tps && that_present_tps))
boolean this_present_version = true;
boolean that_present_version = true;
if (this_present_version || that_present_version) {
if (!(this_present_version && that_present_version))
return false;
if (this.tps != that.tps)
if (this.version != that.version)
return false;
}
boolean this_present_sampledNewCount = true && this.isSetSampledNewCount();
boolean that_present_sampledNewCount = true && that.isSetSampledNewCount();
if (this_present_sampledNewCount || that_present_sampledNewCount) {
if (!(this_present_sampledNewCount && that_present_sampledNewCount))
return false;
if (this.sampledNewCount != that.sampledNewCount)
return false;
}
boolean this_present_sampledContinuationCount = true && this.isSetSampledContinuationCount();
boolean that_present_sampledContinuationCount = true && that.isSetSampledContinuationCount();
if (this_present_sampledContinuationCount || that_present_sampledContinuationCount) {
if (!(this_present_sampledContinuationCount && that_present_sampledContinuationCount))
return false;
if (this.sampledContinuationCount != that.sampledContinuationCount)
return false;
}
boolean this_present_unsampledNewCount = true && this.isSetUnsampledNewCount();
boolean that_present_unsampledNewCount = true && that.isSetUnsampledNewCount();
if (this_present_unsampledNewCount || that_present_unsampledNewCount) {
if (!(this_present_unsampledNewCount && that_present_unsampledNewCount))
return false;
if (this.unsampledNewCount != that.unsampledNewCount)
return false;
}
boolean this_present_unsampledContinuationCount = true && this.isSetUnsampledContinuationCount();
boolean that_present_unsampledContinuationCount = true && that.isSetUnsampledContinuationCount();
if (this_present_unsampledContinuationCount || that_present_unsampledContinuationCount) {
if (!(this_present_unsampledContinuationCount && that_present_unsampledContinuationCount))
return false;
if (this.unsampledContinuationCount != that.unsampledContinuationCount)
return false;
}
@@ -226,10 +456,30 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
public int hashCode() {
List<Object> list = new ArrayList<Object>();
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<TTransaction, TTran
int lastComparison = 0;
lastComparison = Boolean.valueOf(isSetTps()).compareTo(other.isSetTps());
lastComparison = Boolean.valueOf(isSetVersion()).compareTo(other.isSetVersion());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetTps()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tps, other.tps);
if (isSetVersion()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.version, other.version);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetSampledNewCount()).compareTo(other.isSetSampledNewCount());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetSampledNewCount()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sampledNewCount, other.sampledNewCount);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetSampledContinuationCount()).compareTo(other.isSetSampledContinuationCount());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetSampledContinuationCount()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.sampledContinuationCount, other.sampledContinuationCount);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetUnsampledNewCount()).compareTo(other.isSetUnsampledNewCount());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetUnsampledNewCount()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unsampledNewCount, other.unsampledNewCount);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetUnsampledContinuationCount()).compareTo(other.isSetUnsampledContinuationCount());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetUnsampledContinuationCount()) {
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.unsampledContinuationCount, other.unsampledContinuationCount);
if (lastComparison != 0) {
return lastComparison;
}
@@ -272,9 +562,31 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
StringBuilder sb = new StringBuilder("TTransaction(");
boolean first = true;
if (isSetTps()) {
sb.append("tps:");
sb.append(this.tps);
sb.append("version:");
sb.append(this.version);
first = false;
if (isSetSampledNewCount()) {
if (!first) sb.append(", ");
sb.append("sampledNewCount:");
sb.append(this.sampledNewCount);
first = false;
}
if (isSetSampledContinuationCount()) {
if (!first) sb.append(", ");
sb.append("sampledContinuationCount:");
sb.append(this.sampledContinuationCount);
first = false;
}
if (isSetUnsampledNewCount()) {
if (!first) sb.append(", ");
sb.append("unsampledNewCount:");
sb.append(this.unsampledNewCount);
first = false;
}
if (isSetUnsampledContinuationCount()) {
if (!first) sb.append(", ");
sb.append("unsampledContinuationCount:");
sb.append(this.unsampledContinuationCount);
first = false;
}
sb.append(")");
@@ -322,10 +634,42 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
break;
}
switch (schemeField.id) {
case 1: // TPS
if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
struct.tps = iprot.readI32();
struct.setTpsIsSet(true);
case 1: // VERSION
if (schemeField.type == org.apache.thrift.protocol.TType.I16) {
struct.version = iprot.readI16();
struct.setVersionIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 2: // SAMPLED_NEW_COUNT
if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
struct.sampledNewCount = iprot.readI64();
struct.setSampledNewCountIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 3: // SAMPLED_CONTINUATION_COUNT
if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
struct.sampledContinuationCount = iprot.readI64();
struct.setSampledContinuationCountIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 4: // UNSAMPLED_NEW_COUNT
if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
struct.unsampledNewCount = iprot.readI64();
struct.setUnsampledNewCountIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
case 5: // UNSAMPLED_CONTINUATION_COUNT
if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
struct.unsampledContinuationCount = iprot.readI64();
struct.setUnsampledContinuationCountIsSet(true);
} else {
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
@@ -343,9 +687,27 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
if (struct.isSetTps()) {
oprot.writeFieldBegin(TPS_FIELD_DESC);
oprot.writeI32(struct.tps);
oprot.writeFieldBegin(VERSION_FIELD_DESC);
oprot.writeI16(struct.version);
oprot.writeFieldEnd();
if (struct.isSetSampledNewCount()) {
oprot.writeFieldBegin(SAMPLED_NEW_COUNT_FIELD_DESC);
oprot.writeI64(struct.sampledNewCount);
oprot.writeFieldEnd();
}
if (struct.isSetSampledContinuationCount()) {
oprot.writeFieldBegin(SAMPLED_CONTINUATION_COUNT_FIELD_DESC);
oprot.writeI64(struct.sampledContinuationCount);
oprot.writeFieldEnd();
}
if (struct.isSetUnsampledNewCount()) {
oprot.writeFieldBegin(UNSAMPLED_NEW_COUNT_FIELD_DESC);
oprot.writeI64(struct.unsampledNewCount);
oprot.writeFieldEnd();
}
if (struct.isSetUnsampledContinuationCount()) {
oprot.writeFieldBegin(UNSAMPLED_CONTINUATION_COUNT_FIELD_DESC);
oprot.writeI64(struct.unsampledContinuationCount);
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
@@ -366,22 +728,62 @@ public class TTransaction implements org.apache.thrift.TBase<TTransaction, TTran
public void write(org.apache.thrift.protocol.TProtocol prot, TTransaction struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetTps()) {
if (struct.isSetVersion()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetTps()) {
oprot.writeI32(struct.tps);
if (struct.isSetSampledNewCount()) {
optionals.set(1);
}
if (struct.isSetSampledContinuationCount()) {
optionals.set(2);
}
if (struct.isSetUnsampledNewCount()) {
optionals.set(3);
}
if (struct.isSetUnsampledContinuationCount()) {
optionals.set(4);
}
oprot.writeBitSet(optionals, 5);
if (struct.isSetVersion()) {
oprot.writeI16(struct.version);
}
if (struct.isSetSampledNewCount()) {
oprot.writeI64(struct.sampledNewCount);
}
if (struct.isSetSampledContinuationCount()) {
oprot.writeI64(struct.sampledContinuationCount);
}
if (struct.isSetUnsampledNewCount()) {
oprot.writeI64(struct.unsampledNewCount);
}
if (struct.isSetUnsampledContinuationCount()) {
oprot.writeI64(struct.unsampledContinuationCount);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, TTransaction struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(1);
BitSet incoming = iprot.readBitSet(5);
if (incoming.get(0)) {
struct.tps = iprot.readI32();
struct.setTpsIsSet(true);
struct.version = iprot.readI16();
struct.setVersionIsSet(true);
}
if (incoming.get(1)) {
struct.sampledNewCount = iprot.readI64();
struct.setSampledNewCountIsSet(true);
}
if (incoming.get(2)) {
struct.sampledContinuationCount = iprot.readI64();
struct.setSampledContinuationCountIsSet(true);
}
if (incoming.get(3)) {
struct.unsampledNewCount = iprot.readI64();
struct.setUnsampledNewCountIsSet(true);
}
if (incoming.get(4)) {
struct.unsampledContinuationCount = iprot.readI64();
struct.setUnsampledContinuationCountIsSet(true);
}
}
}
+6 -1
View File
@@ -54,13 +54,18 @@ struct TCpuLoad {
}
struct TTransaction {
1: optional i32 tps
1: i16 version = 0
2: optional i64 sampledNewCount
3: optional i64 sampledContinuationCount
4: optional i64 unsampledNewCount
5: optional i64 unsampledContinuationCount
}
struct TAgentStat {
1: optional string agentId
2: optional i64 startTimestamp
3: optional i64 timestamp
4: optional i64 collectInterval
10: optional TJvmGc gc
20: optional TCpuLoad cpuLoad
30: optional TTransaction transaction
@@ -65,7 +65,6 @@ public class AgentStatMapper implements RowMapper<List<AgentStat>> {
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<byte[], byte[]> qualifierMap = result.getFamilyMap(AGENT_STAT_CF_STATISTICS);
if (qualifierMap.containsKey(AGENT_STAT_CF_STATISTICS_V1)) {
@@ -75,39 +74,54 @@ public class AgentStatMapper implements RowMapper<List<AgentStat>> {
// 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<AgentStat> agentStats = new ArrayList<AgentStat>();
agentStats.add(agentStat);
return agentStats;
@@ -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 + "]";
}
}
@@ -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<Double> {
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<Double> sampleBuffer) {
return DownSamplers.MIN.sampleDouble(sampleBuffer);
return roundToScale(DownSamplers.MIN.sampleDouble(sampleBuffer));
}
@Override
protected Double sampleMax(List<Double> sampleBuffer) {
return DownSamplers.MAX.sampleDouble(sampleBuffer);
return roundToScale(DownSamplers.MAX.sampleDouble(sampleBuffer));
}
@Override
protected Double sampleAvg(List<Double> 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();
}
}
@@ -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<ChartType, ChartBuilder<? extends Number, ? extends Number>> chartBuilders;
private final Map<ChartType, Chart> charts;
public AgentStatChartGroup(TimeWindow timeWindow) {
this.chartBuilders = new EnumMap<ChartType, ChartBuilder<? extends Number, ? extends Number>>(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, Chart>(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<Long, Long>(timestamp, agentStat.getHeapUsed()));
((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_MAX)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getHeapMax()));
((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_USED)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getNonHeapUsed()));
((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_MAX)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getNonHeapMax()));
((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_GC_OLD_COUNT)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getGcOldCount()));
((SampledTimeSeriesLongChartBuilder)this.chartBuilders.get(ChartType.JVM_GC_OLD_TIME)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getGcOldTime()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_USED)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getHeapUsed()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_HEAP_MAX)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getHeapMax()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_USED)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getNonHeapUsed()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_MEMORY_NON_HEAP_MAX)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getNonHeapMax()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_COUNT)).addDataPoint(new DataPoint<Long, Long>(timestamp, agentStat.getGcOldCount()));
((SampledTimeSeriesLongChartBuilder) this.chartBuilders.get(ChartType.JVM_GC_OLD_TIME)).addDataPoint(new DataPoint<Long, Long>(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<Long, Double>(timestamp, jvmCpuUsagePercentage));
((SampledTimeSeriesDoubleChartBuilder)this.chartBuilders.get(ChartType.CPU_LOAD_SYSTEM)).addDataPoint(new DataPoint<Long, Double>(timestamp, systemCpuUsagePercentage));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_JVM)).addDataPoint(new DataPoint<Long, Double>(timestamp, jvmCpuUsagePercentage));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.CPU_LOAD_SYSTEM)).addDataPoint(new DataPoint<Long, Double>(timestamp, systemCpuUsagePercentage));
}
private void addTransactionData(AgentStat agentStat) {
long timestamp = agentStat.getTimestamp();
((SampledTimeSeriesIntegerChartBuilder)this.chartBuilders.get(ChartType.TPS)).addDataPoint(new DataPoint<Long, Integer>(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<Long, Double>(timestamp, sampledNewTps));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_SAMPLED_CONTINUATION)).addDataPoint(new DataPoint<Long, Double>(timestamp, sampledContinuationTps));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_NEW)).addDataPoint(new DataPoint<Long, Double>(timestamp, unsampledNewTps));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_UNSAMPLED_CONTINUATION)).addDataPoint(new DataPoint<Long, Double>(timestamp, unsampledContinuationTps));
((SampledTimeSeriesDoubleChartBuilder) this.chartBuilders.get(ChartType.TPS_TOTAL)).addDataPoint(new DataPoint<Long, Double>(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() {
@@ -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<AgentStat> 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 {