提交 7ac93aff 编写于 作者: P pengys5

delete the s5TimeBucket column

上级 7aac7365
......@@ -38,29 +38,29 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
private final Logger logger = LoggerFactory.getLogger(JVMMetricsServiceHandler.class);
@Override public void collect(JVMMetrics request, StreamObserver<Downstream> responseObserver) {
int applicationInstanceId = request.getApplicationInstanceId();
logger.debug("receive the jvm metric from application instance, id: {}", applicationInstanceId);
int instanceId = request.getApplicationInstanceId();
logger.debug("receive the jvm metric from application instance, id: {}", instanceId);
StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME);
request.getMetricsList().forEach(metric -> {
long time = TimeBucketUtils.INSTANCE.getSecondTimeBucket(metric.getTime());
senToInstanceHeartBeatPersistenceWorker(context, applicationInstanceId, metric.getTime());
sendToCpuMetricPersistenceWorker(context, applicationInstanceId, time, metric.getCpu());
sendToMemoryMetricPersistenceWorker(context, applicationInstanceId, time, metric.getMemoryList());
sendToMemoryPoolMetricPersistenceWorker(context, applicationInstanceId, time, metric.getMemoryPoolList());
sendToGCMetricPersistenceWorker(context, applicationInstanceId, time, metric.getGcList());
senToInstanceHeartBeatPersistenceWorker(context, instanceId, metric.getTime());
sendToCpuMetricPersistenceWorker(context, instanceId, time, metric.getCpu());
sendToMemoryMetricPersistenceWorker(context, instanceId, time, metric.getMemoryList());
sendToMemoryPoolMetricPersistenceWorker(context, instanceId, time, metric.getMemoryPoolList());
sendToGCMetricPersistenceWorker(context, instanceId, time, metric.getGcList());
});
responseObserver.onNext(Downstream.newBuilder().build());
responseObserver.onCompleted();
}
private void senToInstanceHeartBeatPersistenceWorker(StreamModuleContext context, int applicationInstanceId,
private void senToInstanceHeartBeatPersistenceWorker(StreamModuleContext context, int instanceId,
long heartBeatTime) {
InstanceHeartBeatDataDefine.InstanceHeartBeat heartBeat = new InstanceHeartBeatDataDefine.InstanceHeartBeat();
heartBeat.setId(String.valueOf(applicationInstanceId));
heartBeat.setId(String.valueOf(instanceId));
heartBeat.setHeartBeatTime(TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartBeatTime));
heartBeat.setInstanceId(applicationInstanceId);
heartBeat.setInstanceId(instanceId);
try {
logger.debug("send to instance heart beat persistence worker, id: {}", heartBeat.getId());
context.getClusterWorkerContext().lookup(InstHeartBeatPersistenceWorker.WorkerRole.INSTANCE).tell(heartBeat.toData());
......@@ -69,11 +69,11 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
}
}
private void sendToCpuMetricPersistenceWorker(StreamModuleContext context, int applicationInstanceId,
private void sendToCpuMetricPersistenceWorker(StreamModuleContext context, int instanceId,
long timeBucket, CPU cpu) {
CpuMetricDataDefine.CpuMetric cpuMetric = new CpuMetricDataDefine.CpuMetric();
cpuMetric.setId(timeBucket + Const.ID_SPLIT + applicationInstanceId);
cpuMetric.setApplicationInstanceId(applicationInstanceId);
cpuMetric.setId(timeBucket + Const.ID_SPLIT + instanceId);
cpuMetric.setInstanceId(instanceId);
cpuMetric.setUsagePercent(cpu.getUsagePercent());
cpuMetric.setTimeBucket(timeBucket);
try {
......@@ -84,13 +84,13 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
}
}
private void sendToMemoryMetricPersistenceWorker(StreamModuleContext context, int applicationInstanceId,
private void sendToMemoryMetricPersistenceWorker(StreamModuleContext context, int instanceId,
long timeBucket, List<Memory> memories) {
memories.forEach(memory -> {
MemoryMetricDataDefine.MemoryMetric memoryMetric = new MemoryMetricDataDefine.MemoryMetric();
memoryMetric.setId(timeBucket + Const.ID_SPLIT + applicationInstanceId + Const.ID_SPLIT + String.valueOf(memory.getIsHeap()));
memoryMetric.setApplicationInstanceId(applicationInstanceId);
memoryMetric.setId(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(memory.getIsHeap()));
memoryMetric.setApplicationInstanceId(instanceId);
memoryMetric.setHeap(memory.getIsHeap());
memoryMetric.setInit(memory.getInit());
memoryMetric.setMax(memory.getMax());
......@@ -106,13 +106,13 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
});
}
private void sendToMemoryPoolMetricPersistenceWorker(StreamModuleContext context, int applicationInstanceId,
private void sendToMemoryPoolMetricPersistenceWorker(StreamModuleContext context, int instanceId,
long timeBucket, List<MemoryPool> memoryPools) {
memoryPools.forEach(memoryPool -> {
MemoryPoolMetricDataDefine.MemoryPoolMetric memoryPoolMetric = new MemoryPoolMetricDataDefine.MemoryPoolMetric();
memoryPoolMetric.setId(timeBucket + Const.ID_SPLIT + applicationInstanceId + Const.ID_SPLIT + memoryPool.getIsHeap() + Const.ID_SPLIT + String.valueOf(memoryPool.getType().getNumber()));
memoryPoolMetric.setApplicationInstanceId(applicationInstanceId);
memoryPoolMetric.setId(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + memoryPool.getIsHeap() + Const.ID_SPLIT + String.valueOf(memoryPool.getType().getNumber()));
memoryPoolMetric.setInstanceId(instanceId);
memoryPoolMetric.setPoolType(memoryPool.getType().getNumber());
memoryPoolMetric.setHeap(memoryPool.getIsHeap());
memoryPoolMetric.setInit(memoryPool.getInit());
......@@ -129,17 +129,16 @@ public class JVMMetricsServiceHandler extends JVMMetricsServiceGrpc.JVMMetricsSe
});
}
private void sendToGCMetricPersistenceWorker(StreamModuleContext context, int applicationInstanceId,
private void sendToGCMetricPersistenceWorker(StreamModuleContext context, int instanceId,
long timeBucket, List<GC> gcs) {
gcs.forEach(gc -> {
GCMetricDataDefine.GCMetric gcMetric = new GCMetricDataDefine.GCMetric();
gcMetric.setId(timeBucket + Const.ID_SPLIT + applicationInstanceId + Const.ID_SPLIT + String.valueOf(gc.getPhraseValue()));
gcMetric.setApplicationInstanceId(applicationInstanceId);
gcMetric.setId(timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + String.valueOf(gc.getPhraseValue()));
gcMetric.setInstanceId(instanceId);
gcMetric.setPhrase(gc.getPhraseValue());
gcMetric.setCount(gc.getCount());
gcMetric.setTime(gc.getTime());
gcMetric.setTimeBucket(timeBucket);
gcMetric.setS5TimeBucket(TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(timeBucket));
try {
logger.debug("send to gc metric persistence worker, id: {}", gcMetric.getId());
context.getClusterWorkerContext().lookup(GCMetricPersistenceWorker.WorkerRole.INSTANCE).tell(gcMetric.toData());
......
......@@ -25,7 +25,7 @@ public class CpuMetricEsDAO extends EsDAO implements ICpuMetricDAO, IPersistence
@Override public IndexRequestBuilder prepareBatchInsert(Data data) {
Map<String, Object> source = new HashMap<>();
source.put(CpuMetricTable.COLUMN_APPLICATION_INSTANCE_ID, data.getDataInteger(0));
source.put(CpuMetricTable.COLUMN_INSTANCE_ID, data.getDataInteger(0));
source.put(CpuMetricTable.COLUMN_USAGE_PERCENT, data.getDataDouble(0));
source.put(CpuMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(0));
......
......@@ -26,7 +26,7 @@ public class CpuMetricEsTableDefine extends ElasticSearchTableDefine {
}
@Override public void initialize() {
addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_APPLICATION_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, ElasticSearchColumnDefine.Type.Double.name()));
addColumn(new ElasticSearchColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
......
......@@ -15,7 +15,7 @@ public class CpuMetricH2TableDefine extends H2TableDefine {
@Override public void initialize() {
addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_APPLICATION_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_USAGE_PERCENT, H2ColumnDefine.Type.Double.name()));
addColumn(new H2ColumnDefine(CpuMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
......
......@@ -21,12 +21,11 @@ public class GCMetricEsDAO extends EsDAO implements IGCMetricDAO, IPersistenceDA
@Override public IndexRequestBuilder prepareBatchInsert(Data data) {
Map<String, Object> source = new HashMap<>();
source.put(GCMetricTable.COLUMN_APPLICATION_INSTANCE_ID, data.getDataInteger(0));
source.put(GCMetricTable.COLUMN_INSTANCE_ID, data.getDataInteger(0));
source.put(GCMetricTable.COLUMN_PHRASE, data.getDataInteger(1));
source.put(GCMetricTable.COLUMN_COUNT, data.getDataLong(0));
source.put(GCMetricTable.COLUMN_TIME, data.getDataLong(1));
source.put(GCMetricTable.COLUMN_TIME_BUCKET, data.getDataLong(2));
source.put(GCMetricTable.COLUMN_5S_TIME_BUCKET, data.getDataLong(3));
return getClient().prepareIndex(GCMetricTable.TABLE, data.getDataString(0)).setSource(source);
}
......
......@@ -26,11 +26,10 @@ public class GCMetricEsTableDefine extends ElasticSearchTableDefine {
}
@Override public void initialize() {
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_APPLICATION_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_PHRASE, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_COUNT, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(GCMetricTable.COLUMN_5S_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
}
......@@ -15,11 +15,10 @@ public class GCMetricH2TableDefine extends H2TableDefine {
@Override public void initialize() {
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_APPLICATION_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_PHRASE, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_COUNT, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(GCMetricTable.COLUMN_5S_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
}
......@@ -21,7 +21,7 @@ public class MemoryPoolMetricEsDAO extends EsDAO implements IMemoryPoolMetricDAO
@Override public IndexRequestBuilder prepareBatchInsert(Data data) {
Map<String, Object> source = new HashMap<>();
source.put(MemoryPoolMetricTable.COLUMN_APPLICATION_INSTANCE_ID, data.getDataInteger(0));
source.put(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, data.getDataInteger(0));
source.put(MemoryPoolMetricTable.COLUMN_POOL_TYPE, data.getDataInteger(1));
source.put(MemoryPoolMetricTable.COLUMN_IS_HEAP, data.getDataBoolean(0));
source.put(MemoryPoolMetricTable.COLUMN_INIT, data.getDataLong(0));
......
......@@ -26,7 +26,7 @@ public class MemoryPoolMetricEsTableDefine extends ElasticSearchTableDefine {
}
@Override public void initialize() {
addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_APPLICATION_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_IS_HEAP, ElasticSearchColumnDefine.Type.Boolean.name()));
addColumn(new ElasticSearchColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, ElasticSearchColumnDefine.Type.Long.name()));
......
......@@ -15,7 +15,7 @@ public class MemoryPoolMetricH2TableDefine extends H2TableDefine {
@Override public void initialize() {
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_APPLICATION_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_POOL_TYPE, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_IS_HEAP, H2ColumnDefine.Type.Boolean.name()));
addColumn(new H2ColumnDefine(MemoryPoolMetricTable.COLUMN_INIT, H2ColumnDefine.Type.Bigint.name()));
......
......@@ -5,6 +5,7 @@ import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.GlobalTraceIdsListener;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.global.GlobalTraceDataDefine;
import org.skywalking.apm.collector.stream.StreamModuleContext;
......@@ -52,7 +53,7 @@ public class GlobalTraceSpanListener implements FirstSpanListener, GlobalTraceId
for (String globalTraceId : globalTraceIds) {
GlobalTraceDataDefine.GlobalTrace globalTrace = new GlobalTraceDataDefine.GlobalTrace();
globalTrace.setGlobalTraceId(globalTraceId);
globalTrace.setId(segmentId + globalTraceId);
globalTrace.setId(segmentId + Const.ID_SPLIT + globalTraceId);
globalTrace.setSegmentId(segmentId);
globalTrace.setTimeBucket(timeBucket);
try {
......
......@@ -22,7 +22,7 @@ public class InstPerformanceSpanListener implements EntrySpanListener, FirstSpan
private final Logger logger = LoggerFactory.getLogger(InstPerformanceSpanListener.class);
private int applicationId;
private int applicationInstanceId;
private int instanceId;
private long cost;
private long timeBucket;
......@@ -33,7 +33,7 @@ public class InstPerformanceSpanListener implements EntrySpanListener, FirstSpan
@Override
public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
this.applicationId = applicationId;
this.applicationInstanceId = applicationInstanceId;
this.instanceId = applicationInstanceId;
this.cost = spanObject.getEndTime() - spanObject.getStartTime();
timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanObject.getStartTime());
}
......@@ -42,13 +42,12 @@ public class InstPerformanceSpanListener implements EntrySpanListener, FirstSpan
StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME);
InstPerformanceDataDefine.InstPerformance instPerformance = new InstPerformanceDataDefine.InstPerformance();
instPerformance.setId(timeBucket + Const.ID_SPLIT + applicationInstanceId);
instPerformance.setId(timeBucket + Const.ID_SPLIT + instanceId);
instPerformance.setApplicationId(applicationId);
instPerformance.setInstanceId(applicationInstanceId);
instPerformance.setCallTimes(1);
instPerformance.setInstanceId(instanceId);
instPerformance.setCalls(1);
instPerformance.setCostTotal(cost);
instPerformance.setTimeBucket(timeBucket);
instPerformance.setS5TimeBucket(TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(timeBucket));
try {
logger.debug("send to instance performance persistence worker, id: {}", instPerformance.getId());
......
......@@ -28,10 +28,9 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO,
Map<String, Object> source = getResponse.getSource();
data.setDataInteger(0, (Integer)source.get(InstPerformanceTable.COLUMN_APPLICATION_ID));
data.setDataInteger(1, (Integer)source.get(InstPerformanceTable.COLUMN_INSTANCE_ID));
data.setDataInteger(2, (Integer)source.get(InstPerformanceTable.COLUMN_CALL_TIMES));
data.setDataInteger(2, (Integer)source.get(InstPerformanceTable.COLUMN_CALLS));
data.setDataLong(0, ((Number)source.get(InstPerformanceTable.COLUMN_COST_TOTAL)).longValue());
data.setDataLong(1, ((Number)source.get(InstPerformanceTable.COLUMN_TIME_BUCKET)).longValue());
data.setDataLong(2, ((Number)source.get(InstPerformanceTable.COLUMN_5S_TIME_BUCKET)).longValue());
return data;
} else {
return null;
......@@ -42,10 +41,9 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO,
Map<String, Object> source = new HashMap<>();
source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0));
source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1));
source.put(InstPerformanceTable.COLUMN_CALL_TIMES, data.getDataInteger(2));
source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2));
source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0));
source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1));
source.put(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, data.getDataLong(2));
return getClient().prepareIndex(InstPerformanceTable.TABLE, data.getDataString(0)).setSource(source);
}
......@@ -54,10 +52,9 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO,
Map<String, Object> source = new HashMap<>();
source.put(InstPerformanceTable.COLUMN_APPLICATION_ID, data.getDataInteger(0));
source.put(InstPerformanceTable.COLUMN_INSTANCE_ID, data.getDataInteger(1));
source.put(InstPerformanceTable.COLUMN_CALL_TIMES, data.getDataInteger(2));
source.put(InstPerformanceTable.COLUMN_CALLS, data.getDataInteger(2));
source.put(InstPerformanceTable.COLUMN_COST_TOTAL, data.getDataLong(0));
source.put(InstPerformanceTable.COLUMN_TIME_BUCKET, data.getDataLong(1));
source.put(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, data.getDataLong(2));
return getClient().prepareUpdate(InstPerformanceTable.TABLE, data.getDataString(0)).setDoc(source);
}
......
......@@ -28,9 +28,8 @@ public class InstPerformanceEsTableDefine extends ElasticSearchTableDefine {
@Override public void initialize() {
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_INSTANCE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_CALL_TIMES, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_CALLS, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_COST_TOTAL, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
addColumn(new ElasticSearchColumnDefine(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name()));
}
}
......@@ -17,9 +17,8 @@ public class InstPerformanceH2TableDefine extends H2TableDefine {
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_INSTANCE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_CALL_TIMES, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_CALLS, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_COST_TOTAL, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
addColumn(new H2ColumnDefine(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name()));
}
}
......@@ -67,15 +67,18 @@ public enum TimeBucketUtils {
}
}
public long getFiveSecondTimeBucket(long secondTimeBucket) {
long mantissa = secondTimeBucket % 10;
if (mantissa < 5) {
return (secondTimeBucket / 10) * 10;
} else if (mantissa == 5) {
return secondTimeBucket;
} else {
return ((secondTimeBucket / 10) + 1) * 10;
public long[] getFiveSecondTimeBuckets(long secondTimeBucket) {
long timeStamp = changeTimeBucket2TimeStamp(TimeBucketType.SECOND.name(), secondTimeBucket);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeStamp);
long[] timeBuckets = new long[5];
timeBuckets[0] = secondTimeBucket;
for (int i = 0; i < 4; i++) {
calendar.add(Calendar.SECOND, -1);
timeBuckets[i + 1] = getSecondTimeBucket(calendar.getTimeInMillis());
}
return timeBuckets;
}
public long changeToUTCTimeBucket(long timeBucket) {
......
......@@ -11,14 +11,12 @@ public class TimeBucketUtilsTestCase {
@Test
public void testGetFiveSecondTimeBucket() {
long fiveSecondTimeBucket = TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(20170804224812L);
Assert.assertEquals(20170804224810L, fiveSecondTimeBucket);
fiveSecondTimeBucket = TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(20170804224818L);
Assert.assertEquals(20170804224820L, fiveSecondTimeBucket);
fiveSecondTimeBucket = TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(20170804224815L);
Assert.assertEquals(20170804224815L, fiveSecondTimeBucket);
long[] timeBuckets = TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(20170804224810L);
Assert.assertEquals(20170804224810L, timeBuckets[0]);
Assert.assertEquals(20170804224809L, timeBuckets[1]);
Assert.assertEquals(20170804224808L, timeBuckets[2]);
Assert.assertEquals(20170804224807L, timeBuckets[3]);
Assert.assertEquals(20170804224806L, timeBuckets[4]);
}
@Test
......
......@@ -8,5 +8,4 @@ public class CommonTable {
public static final String COLUMN_ID = "id";
public static final String COLUMN_AGG = "agg";
public static final String COLUMN_TIME_BUCKET = "time_bucket";
public static final String COLUMN_5S_TIME_BUCKET = "s5_time_bucket";
}
......@@ -16,17 +16,16 @@ import org.skywalking.apm.collector.storage.define.DataDefine;
public class InstPerformanceDataDefine extends DataDefine {
@Override protected int initialCapacity() {
return 7;
return 6;
}
@Override protected void attributeDefine() {
addAttribute(0, new Attribute(InstPerformanceTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
addAttribute(1, new Attribute(InstPerformanceTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(2, new Attribute(InstPerformanceTable.COLUMN_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(3, new Attribute(InstPerformanceTable.COLUMN_CALL_TIMES, AttributeType.INTEGER, new AddOperation()));
addAttribute(3, new Attribute(InstPerformanceTable.COLUMN_CALLS, AttributeType.INTEGER, new AddOperation()));
addAttribute(4, new Attribute(InstPerformanceTable.COLUMN_COST_TOTAL, AttributeType.LONG, new AddOperation()));
addAttribute(5, new Attribute(InstPerformanceTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
addAttribute(6, new Attribute(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
}
@Override public Object deserialize(RemoteData remoteData) {
......@@ -41,21 +40,18 @@ public class InstPerformanceDataDefine extends DataDefine {
private String id;
private int applicationId;
private int instanceId;
private int callTimes;
private int calls;
private long costTotal;
private long timeBucket;
private long s5TimeBucket;
public InstPerformance(String id, int applicationId, int instanceId, int callTimes, long costTotal,
long timeBucket,
long s5TimeBucket) {
public InstPerformance(String id, int applicationId, int instanceId, int calls, long costTotal,
long timeBucket) {
this.id = id;
this.applicationId = applicationId;
this.instanceId = instanceId;
this.callTimes = callTimes;
this.calls = calls;
this.costTotal = costTotal;
this.timeBucket = timeBucket;
this.s5TimeBucket = s5TimeBucket;
}
public InstPerformance() {
......@@ -67,10 +63,9 @@ public class InstPerformanceDataDefine extends DataDefine {
data.setDataString(0, this.id);
data.setDataInteger(0, this.applicationId);
data.setDataInteger(1, this.instanceId);
data.setDataInteger(2, this.callTimes);
data.setDataInteger(2, this.calls);
data.setDataLong(0, this.costTotal);
data.setDataLong(1, this.timeBucket);
data.setDataLong(2, this.s5TimeBucket);
return data;
}
......@@ -78,10 +73,9 @@ public class InstPerformanceDataDefine extends DataDefine {
this.id = data.getDataString(0);
this.applicationId = data.getDataInteger(0);
this.instanceId = data.getDataInteger(1);
this.callTimes = data.getDataInteger(2);
this.calls = data.getDataInteger(2);
this.costTotal = data.getDataLong(0);
this.timeBucket = data.getDataLong(1);
this.s5TimeBucket = data.getDataLong(2);
return this;
}
......@@ -101,12 +95,12 @@ public class InstPerformanceDataDefine extends DataDefine {
this.instanceId = instanceId;
}
public int getCallTimes() {
return callTimes;
public int getCalls() {
return calls;
}
public void setCallTimes(int callTimes) {
this.callTimes = callTimes;
public void setCalls(int calls) {
this.calls = calls;
}
public long getCostTotal() {
......@@ -132,13 +126,5 @@ public class InstPerformanceDataDefine extends DataDefine {
public void setApplicationId(int applicationId) {
this.applicationId = applicationId;
}
public long getS5TimeBucket() {
return s5TimeBucket;
}
public void setS5TimeBucket(long s5TimeBucket) {
this.s5TimeBucket = s5TimeBucket;
}
}
}
......@@ -9,6 +9,6 @@ public class InstPerformanceTable extends CommonTable {
public static final String TABLE = "instance_performance";
public static final String COLUMN_APPLICATION_ID = "application_id";
public static final String COLUMN_INSTANCE_ID = "instance_id";
public static final String COLUMN_CALL_TIMES = "call_times";
public static final String COLUMN_CALLS = "calls";
public static final String COLUMN_COST_TOTAL = "cost_total";
}
......@@ -21,7 +21,7 @@ public class CpuMetricDataDefine extends DataDefine {
@Override protected void attributeDefine() {
addAttribute(0, new Attribute(CpuMetricTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
addAttribute(1, new Attribute(CpuMetricTable.COLUMN_APPLICATION_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(1, new Attribute(CpuMetricTable.COLUMN_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(2, new Attribute(CpuMetricTable.COLUMN_USAGE_PERCENT, AttributeType.DOUBLE, new CoverOperation()));
addAttribute(3, new Attribute(CpuMetricTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
}
......@@ -36,13 +36,13 @@ public class CpuMetricDataDefine extends DataDefine {
public static class CpuMetric implements Transform<CpuMetric> {
private String id;
private int applicationInstanceId;
private int instanceId;
private double usagePercent;
private long timeBucket;
public CpuMetric(String id, int applicationInstanceId, double usagePercent, long timeBucket) {
public CpuMetric(String id, int instanceId, double usagePercent, long timeBucket) {
this.id = id;
this.applicationInstanceId = applicationInstanceId;
this.instanceId = instanceId;
this.usagePercent = usagePercent;
this.timeBucket = timeBucket;
}
......@@ -54,7 +54,7 @@ public class CpuMetricDataDefine extends DataDefine {
CpuMetricDataDefine define = new CpuMetricDataDefine();
Data data = define.build(id);
data.setDataString(0, this.id);
data.setDataInteger(0, this.applicationInstanceId);
data.setDataInteger(0, this.instanceId);
data.setDataDouble(0, this.usagePercent);
data.setDataLong(0, this.timeBucket);
return data;
......@@ -62,7 +62,7 @@ public class CpuMetricDataDefine extends DataDefine {
@Override public CpuMetric toSelf(Data data) {
this.id = data.getDataString(0);
this.applicationInstanceId = data.getDataInteger(0);
this.instanceId = data.getDataInteger(0);
this.usagePercent = data.getDataDouble(0);
this.timeBucket = data.getDataLong(0);
return this;
......@@ -72,8 +72,8 @@ public class CpuMetricDataDefine extends DataDefine {
this.id = id;
}
public void setApplicationInstanceId(int applicationInstanceId) {
this.applicationInstanceId = applicationInstanceId;
public void setInstanceId(int instanceId) {
this.instanceId = instanceId;
}
public void setUsagePercent(double usagePercent) {
......@@ -88,8 +88,8 @@ public class CpuMetricDataDefine extends DataDefine {
return id;
}
public int getApplicationInstanceId() {
return applicationInstanceId;
public int getInstanceId() {
return instanceId;
}
public double getUsagePercent() {
......
......@@ -7,6 +7,6 @@ import org.skywalking.apm.collector.storage.define.CommonTable;
*/
public class CpuMetricTable extends CommonTable {
public static final String TABLE = "cpu_metric";
public static final String COLUMN_APPLICATION_INSTANCE_ID = "application_instance_id";
public static final String COLUMN_INSTANCE_ID = "instance_id";
public static final String COLUMN_USAGE_PERCENT = "usage_percent";
}
......@@ -16,17 +16,16 @@ import org.skywalking.apm.collector.storage.define.DataDefine;
public class GCMetricDataDefine extends DataDefine {
@Override protected int initialCapacity() {
return 7;
return 6;
}
@Override protected void attributeDefine() {
addAttribute(0, new Attribute(GCMetricTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
addAttribute(1, new Attribute(GCMetricTable.COLUMN_APPLICATION_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(1, new Attribute(GCMetricTable.COLUMN_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(2, new Attribute(GCMetricTable.COLUMN_PHRASE, AttributeType.INTEGER, new CoverOperation()));
addAttribute(3, new Attribute(GCMetricTable.COLUMN_COUNT, AttributeType.LONG, new CoverOperation()));
addAttribute(4, new Attribute(GCMetricTable.COLUMN_TIME, AttributeType.LONG, new CoverOperation()));
addAttribute(5, new Attribute(GCMetricTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
addAttribute(6, new Attribute(GCMetricTable.COLUMN_5S_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
}
@Override public Object deserialize(RemoteData remoteData) {
......@@ -39,22 +38,19 @@ public class GCMetricDataDefine extends DataDefine {
public static class GCMetric implements Transform<GCMetric> {
private String id;
private int applicationInstanceId;
private int instanceId;
private int phrase;
private long count;
private long time;
private long timeBucket;
private long s5TimeBucket;
public GCMetric(String id, int applicationInstanceId, int phrase, long count, long time, long timeBucket,
long s5TimeBucket) {
public GCMetric(String id, int instanceId, int phrase, long count, long time, long timeBucket) {
this.id = id;
this.applicationInstanceId = applicationInstanceId;
this.instanceId = instanceId;
this.phrase = phrase;
this.count = count;
this.time = time;
this.timeBucket = timeBucket;
this.s5TimeBucket = s5TimeBucket;
}
public GCMetric() {
......@@ -64,23 +60,21 @@ public class GCMetricDataDefine extends DataDefine {
GCMetricDataDefine define = new GCMetricDataDefine();
Data data = define.build(id);
data.setDataString(0, this.id);
data.setDataInteger(0, this.applicationInstanceId);
data.setDataInteger(0, this.instanceId);
data.setDataInteger(1, this.phrase);
data.setDataLong(0, this.count);
data.setDataLong(1, this.time);
data.setDataLong(2, this.timeBucket);
data.setDataLong(3, this.s5TimeBucket);
return data;
}
@Override public GCMetric toSelf(Data data) {
this.id = data.getDataString(0);
this.applicationInstanceId = data.getDataInteger(0);
this.instanceId = data.getDataInteger(0);
this.phrase = data.getDataInteger(1);
this.count = data.getDataLong(0);
this.time = data.getDataLong(1);
this.timeBucket = data.getDataLong(2);
this.s5TimeBucket = data.getDataLong(3);
return this;
}
......@@ -88,8 +82,8 @@ public class GCMetricDataDefine extends DataDefine {
this.id = id;
}
public void setApplicationInstanceId(int applicationInstanceId) {
this.applicationInstanceId = applicationInstanceId;
public void setInstanceId(int instanceId) {
this.instanceId = instanceId;
}
public void setTimeBucket(long timeBucket) {
......@@ -100,8 +94,8 @@ public class GCMetricDataDefine extends DataDefine {
return id;
}
public int getApplicationInstanceId() {
return applicationInstanceId;
public int getInstanceId() {
return instanceId;
}
public long getTimeBucket() {
......@@ -131,13 +125,5 @@ public class GCMetricDataDefine extends DataDefine {
public void setTime(long time) {
this.time = time;
}
public long getS5TimeBucket() {
return s5TimeBucket;
}
public void setS5TimeBucket(long s5TimeBucket) {
this.s5TimeBucket = s5TimeBucket;
}
}
}
......@@ -7,7 +7,7 @@ import org.skywalking.apm.collector.storage.define.CommonTable;
*/
public class GCMetricTable extends CommonTable {
public static final String TABLE = "gc_metric";
public static final String COLUMN_APPLICATION_INSTANCE_ID = "application_instance_id";
public static final String COLUMN_INSTANCE_ID = "instance_id";
public static final String COLUMN_PHRASE = "phrase";
public static final String COLUMN_COUNT = "count";
public static final String COLUMN_TIME = "time";
......
......@@ -21,7 +21,7 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
@Override protected void attributeDefine() {
addAttribute(0, new Attribute(MemoryPoolMetricTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
addAttribute(1, new Attribute(MemoryPoolMetricTable.COLUMN_APPLICATION_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(1, new Attribute(MemoryPoolMetricTable.COLUMN_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(2, new Attribute(MemoryPoolMetricTable.COLUMN_POOL_TYPE, AttributeType.INTEGER, new CoverOperation()));
addAttribute(3, new Attribute(MemoryPoolMetricTable.COLUMN_IS_HEAP, AttributeType.BOOLEAN, new CoverOperation()));
addAttribute(4, new Attribute(MemoryPoolMetricTable.COLUMN_INIT, AttributeType.LONG, new CoverOperation()));
......@@ -41,7 +41,7 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
public static class MemoryPoolMetric implements Transform<MemoryPoolMetric> {
private String id;
private int applicationInstanceId;
private int instanceId;
private int poolType;
private boolean isHeap;
private long init;
......@@ -50,10 +50,10 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
private long committed;
private long timeBucket;
public MemoryPoolMetric(String id, int applicationInstanceId, int poolType, boolean isHeap, long init, long max,
public MemoryPoolMetric(String id, int instanceId, int poolType, boolean isHeap, long init, long max,
long used, long committed, long timeBucket) {
this.id = id;
this.applicationInstanceId = applicationInstanceId;
this.instanceId = instanceId;
this.poolType = poolType;
this.isHeap = isHeap;
this.init = init;
......@@ -70,7 +70,7 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
MemoryPoolMetricDataDefine define = new MemoryPoolMetricDataDefine();
Data data = define.build(id);
data.setDataString(0, this.id);
data.setDataInteger(0, this.applicationInstanceId);
data.setDataInteger(0, this.instanceId);
data.setDataInteger(1, this.poolType);
data.setDataBoolean(0, this.isHeap);
data.setDataLong(0, this.init);
......@@ -83,7 +83,7 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
@Override public MemoryPoolMetric toSelf(Data data) {
this.id = data.getDataString(0);
this.applicationInstanceId = data.getDataInteger(0);
this.instanceId = data.getDataInteger(0);
this.poolType = data.getDataInteger(1);
this.isHeap = data.getDataBoolean(0);
this.init = data.getDataLong(0);
......@@ -98,8 +98,8 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
this.id = id;
}
public void setApplicationInstanceId(int applicationInstanceId) {
this.applicationInstanceId = applicationInstanceId;
public void setInstanceId(int instanceId) {
this.instanceId = instanceId;
}
public void setPoolType(int poolType) {
......@@ -134,8 +134,8 @@ public class MemoryPoolMetricDataDefine extends DataDefine {
return id;
}
public int getApplicationInstanceId() {
return applicationInstanceId;
public int getInstanceId() {
return instanceId;
}
public long getTimeBucket() {
......
......@@ -7,7 +7,7 @@ import org.skywalking.apm.collector.storage.define.CommonTable;
*/
public class MemoryPoolMetricTable extends CommonTable {
public static final String TABLE = "memory_pool_metric";
public static final String COLUMN_APPLICATION_INSTANCE_ID = "application_instance_id";
public static final String COLUMN_INSTANCE_ID = "instance_id";
public static final String COLUMN_POOL_TYPE = "pool_type";
public static final String COLUMN_IS_HEAP = "is_heap";
public static final String COLUMN_INIT = "init";
......
......@@ -10,7 +10,6 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
......@@ -30,18 +29,15 @@ public class GCMetricEsDAO extends EsDAO implements IGCMetricDAO {
private final Logger logger = LoggerFactory.getLogger(GCMetricEsDAO.class);
@Override public GCCount getGCCount(long s5TimeBucket, int instanceId) {
logger.debug("get gc count, s5TimeBucket: {}, instanceId: {}", s5TimeBucket, instanceId);
@Override public GCCount getGCCount(long[] timeBuckets, int instanceId) {
logger.debug("get gc count, timeBuckets: {}, instanceId: {}", timeBuckets, instanceId);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GCMetricTable.TABLE);
searchRequestBuilder.setTypes(GCMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
MatchQueryBuilder matchApplicationId = QueryBuilders.matchQuery(GCMetricTable.COLUMN_APPLICATION_INSTANCE_ID, instanceId);
MatchQueryBuilder matchTimeBucket = QueryBuilders.matchQuery(GCMetricTable.COLUMN_5S_TIME_BUCKET, s5TimeBucket);
boolQuery.must().add(matchApplicationId);
boolQuery.must().add(matchTimeBucket);
boolQuery.must().add(QueryBuilders.termQuery(GCMetricTable.COLUMN_INSTANCE_ID, instanceId));
boolQuery.must().add(QueryBuilders.termsQuery(GCMetricTable.COLUMN_TIME_BUCKET, timeBuckets));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
......
......@@ -8,7 +8,7 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
*/
public class GCMetricH2DAO extends H2DAO implements IGCMetricDAO {
@Override public GCCount getGCCount(long timestamp, int instanceId) {
@Override public GCCount getGCCount(long[] timeBuckets, int instanceId) {
return null;
}
......
......@@ -7,7 +7,7 @@ import com.google.gson.JsonObject;
*/
public interface IGCMetricDAO {
GCCount getGCCount(long timestamp, int instanceId);
GCCount getGCCount(long[] timeBuckets, int instanceId);
JsonObject getMetric(int instanceId, long timeBucket);
......
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.util.List;
/**
* @author pengys5
*/
public interface IInstPerformanceDAO {
List<InstPerformance> getMultiple(long timeBucket, int applicationId);
InstPerformance get(long[] timeBuckets, int instanceId);
int getTpsMetric(int instanceId, long timeBucket);
......@@ -19,12 +18,12 @@ public interface IInstPerformanceDAO {
class InstPerformance {
private final int instanceId;
private final int callTimes;
private final int calls;
private final long costTotal;
public InstPerformance(int instanceId, int callTimes, long costTotal) {
public InstPerformance(int instanceId, int calls, long costTotal) {
this.instanceId = instanceId;
this.callTimes = callTimes;
this.calls = calls;
this.costTotal = costTotal;
}
......@@ -32,8 +31,8 @@ public interface IInstPerformanceDAO {
return instanceId;
}
public int getCallTimes() {
return callTimes;
public int getCalls() {
return calls;
}
public long getCostTotal() {
......
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
/**
......@@ -15,6 +16,8 @@ public interface IInstanceDAO {
InstanceDataDefine.Instance getInstance(int instanceId);
List<InstanceDataDefine.Instance> getInstances(int applicationId, long timeBucket);
class Application {
private final int applicationId;
private final long count;
......
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.util.LinkedList;
import java.util.List;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetRequestBuilder;
......@@ -11,10 +9,8 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
......@@ -26,46 +22,25 @@ import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
*/
public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO {
@Override public List<InstPerformance> getMultiple(long timeBucket, int applicationId) {
@Override public InstPerformance get(long[] timeBuckets, int instanceId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstPerformanceTable.TABLE);
searchRequestBuilder.setTypes(InstPerformanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
MatchQueryBuilder matchApplicationId = QueryBuilders.matchQuery(InstPerformanceTable.COLUMN_APPLICATION_ID, applicationId);
MatchQueryBuilder matchTimeBucket = QueryBuilders.matchQuery(InstPerformanceTable.COLUMN_5S_TIME_BUCKET, timeBucket);
boolQuery.must().add(matchApplicationId);
boolQuery.must().add(matchTimeBucket);
boolQuery.must().add(QueryBuilders.termQuery(InstPerformanceTable.COLUMN_INSTANCE_ID, instanceId));
boolQuery.must().add(QueryBuilders.termsQuery(InstPerformanceTable.COLUMN_TIME_BUCKET, timeBuckets));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(
AggregationBuilders.terms(InstPerformanceTable.COLUMN_INSTANCE_ID).field(InstPerformanceTable.COLUMN_INSTANCE_ID)
.subAggregation(
AggregationBuilders.terms(InstPerformanceTable.COLUMN_5S_TIME_BUCKET).field(InstPerformanceTable.COLUMN_5S_TIME_BUCKET)
.subAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_CALL_TIMES).field(InstPerformanceTable.COLUMN_CALL_TIMES))
.subAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_COST_TOTAL).field(InstPerformanceTable.COLUMN_COST_TOTAL))));
searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_CALLS).field(InstPerformanceTable.COLUMN_CALLS));
searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstPerformanceTable.COLUMN_COST_TOTAL).field(InstPerformanceTable.COLUMN_COST_TOTAL));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms instanceTerms = searchResponse.getAggregations().get(InstPerformanceTable.COLUMN_INSTANCE_ID);
List<InstPerformance> instPerformances = new LinkedList<>();
for (Terms.Bucket instanceBucket : instanceTerms.getBuckets()) {
int instanceId = instanceBucket.getKeyAsNumber().intValue();
Terms timeBucketTerms = instanceBucket.getAggregations().get(InstPerformanceTable.COLUMN_5S_TIME_BUCKET);
for (Terms.Bucket timeBucketBucket : timeBucketTerms.getBuckets()) {
long count = timeBucketBucket.getDocCount();
Sum sumCallTimes = timeBucketBucket.getAggregations().get(InstPerformanceTable.COLUMN_CALL_TIMES);
Sum sumCostTotal = timeBucketBucket.getAggregations().get(InstPerformanceTable.COLUMN_COST_TOTAL);
int avgCallTimes = (int)(sumCallTimes.getValue() / count);
int avgCost = (int)(sumCostTotal.getValue() / count);
instPerformances.add(new InstPerformance(instanceId, avgCallTimes, avgCost));
}
}
return instPerformances;
Sum sumCalls = searchResponse.getAggregations().get(InstPerformanceTable.COLUMN_CALLS);
Sum sumCostTotal = searchResponse.getAggregations().get(InstPerformanceTable.COLUMN_CALLS);
return new InstPerformance(instanceId, (int)sumCalls.getValue(), (long)sumCostTotal.getValue());
}
@Override public int getTpsMetric(int instanceId, long timeBucket) {
......@@ -73,7 +48,7 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO {
GetResponse getResponse = getClient().prepareGet(InstPerformanceTable.TABLE, id).get();
if (getResponse.isExists()) {
return ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALL_TIMES)).intValue();
return ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
}
return 0;
}
......@@ -93,7 +68,7 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO {
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
metrics.add(((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALL_TIMES)).intValue());
metrics.add(((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue());
} else {
metrics.add(0);
}
......@@ -106,7 +81,7 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO {
GetResponse getResponse = getClient().prepareGet(InstPerformanceTable.TABLE, id).get();
if (getResponse.isExists()) {
int callTimes = ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALL_TIMES)).intValue();
int callTimes = ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
int costTotal = ((Number)getResponse.getSource().get(InstPerformanceTable.COLUMN_COST_TOTAL)).intValue();
return costTotal / callTimes;
}
......@@ -130,7 +105,7 @@ public class InstPerformanceEsDAO extends EsDAO implements IInstPerformanceDAO {
MultiGetResponse multiGetResponse = prepareMultiGet.get();
for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
if (response.getResponse().isExists()) {
int callTimes = ((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALL_TIMES)).intValue();
int callTimes = ((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_CALLS)).intValue();
int costTotal = ((Number)response.getResponse().getSource().get(InstPerformanceTable.COLUMN_COST_TOTAL)).intValue();
metrics.add(costTotal / callTimes);
} else {
......
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
/**
......@@ -9,7 +8,7 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
*/
public class InstPerformanceH2DAO extends H2DAO implements IInstPerformanceDAO {
@Override public List<InstPerformance> getMultiple(long timestamp, int applicationId) {
@Override public InstPerformance get(long[] timeBuckets, int instanceId) {
return null;
}
......
......@@ -2,6 +2,8 @@ package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
......@@ -9,7 +11,6 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
......@@ -45,10 +46,8 @@ public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gt(fiveMinuteBefore);
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(InstanceTable.COLUMN_INSTANCE_ID, applicationInstanceId);
boolQueryBuilder.must(rangeQueryBuilder);
boolQueryBuilder.must(matchQueryBuilder);
boolQueryBuilder.must(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gt(fiveMinuteBefore));
boolQueryBuilder.must(QueryBuilders.termQuery(InstanceTable.COLUMN_INSTANCE_ID, applicationInstanceId));
return heartBeatTime(boolQueryBuilder);
}
......@@ -118,4 +117,30 @@ public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
}
return null;
}
@Override public List<InstanceDataDefine.Instance> getInstances(int applicationId, long timeBucket) {
logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1000);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(timeBucket));
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
searchRequestBuilder.setQuery(boolQuery);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<InstanceDataDefine.Instance> instanceList = new LinkedList<>();
for (SearchHit searchHit : searchHits) {
InstanceDataDefine.Instance instance = new InstanceDataDefine.Instance();
instance.setApplicationId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
instance.setHeartBeatTime(((Number)searchHit.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
instance.setInstanceId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
instanceList.add(instance);
}
return instanceList;
}
}
package org.skywalking.apm.collector.ui.dao;
import com.google.gson.JsonArray;
import java.util.List;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
......@@ -23,4 +24,8 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public InstanceDataDefine.Instance getInstance(int instanceId) {
return null;
}
@Override public List<InstanceDataDefine.Instance> getInstances(int applicationId, long timeBucket) {
return null;
}
}
......@@ -28,12 +28,18 @@ public class AllInstanceLastTimeGetHandler extends JettyHandler {
Long timeBucket = service.allInstanceLastTime();
logger.debug("all instance last time: {}", timeBucket);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket));
calendar.add(Calendar.SECOND, -5);
long instanceTimeBucket;
if (timeBucket == 0) {
instanceTimeBucket = 0;
} else {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket));
calendar.add(Calendar.SECOND, -5);
instanceTimeBucket = calendar.getTimeInMillis();
}
JsonObject timeJson = new JsonObject();
timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(calendar.getTimeInMillis()));
timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(instanceTimeBucket));
return timeJson;
}
......
......@@ -5,9 +5,11 @@ import com.google.gson.JsonObject;
import java.util.List;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.collector.ui.dao.IGCMetricDAO;
import org.skywalking.apm.collector.ui.dao.IInstPerformanceDAO;
import org.skywalking.apm.collector.ui.dao.IInstanceDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -21,23 +23,29 @@ public class InstanceHealthService {
public JsonObject getInstances(long timeBucket, int applicationId) {
JsonObject response = new JsonObject();
long s5TimeBucket = TimeBucketUtils.INSTANCE.getFiveSecondTimeBucket(timeBucket);
long[] timeBuckets = TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(timeBucket);
long halfHourBeforeTimeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, -60 * 30);
IInstanceDAO instanceDAO = (IInstanceDAO)DAOContainer.INSTANCE.get(IInstanceDAO.class.getName());
List<InstanceDataDefine.Instance> instanceList = instanceDAO.getInstances(applicationId, halfHourBeforeTimeBucket);
IInstPerformanceDAO instPerformanceDAO = (IInstPerformanceDAO)DAOContainer.INSTANCE.get(IInstPerformanceDAO.class.getName());
List<IInstPerformanceDAO.InstPerformance> performances = instPerformanceDAO.getMultiple(s5TimeBucket, applicationId);
instanceList.forEach(instance -> {
JsonArray instances = new JsonArray();
response.addProperty("applicationCode", ApplicationCache.getForUI(applicationId));
response.addProperty("applicationId", applicationId);
response.add("instances", instances);
JsonArray instances = new JsonArray();
response.addProperty("applicationCode", ApplicationCache.getForUI(applicationId));
response.addProperty("applicationId", applicationId);
response.add("instances", instances);
IInstPerformanceDAO instPerformanceDAO = (IInstPerformanceDAO)DAOContainer.INSTANCE.get(IInstPerformanceDAO.class.getName());
IInstPerformanceDAO.InstPerformance performance = instPerformanceDAO.get(timeBuckets, instance.getInstanceId());
IGCMetricDAO gcMetricDAO = (IGCMetricDAO)DAOContainer.INSTANCE.get(IGCMetricDAO.class.getName());
performances.forEach(instance -> {
IGCMetricDAO gcMetricDAO = (IGCMetricDAO)DAOContainer.INSTANCE.get(IGCMetricDAO.class.getName());
JsonObject instanceJson = new JsonObject();
instanceJson.addProperty("id", instance.getInstanceId());
instanceJson.addProperty("tps", instance.getCallTimes());
instanceJson.addProperty("tps", performance.getCalls());
int avg = (int)(instance.getCostTotal() / instance.getCallTimes());
int avg = 0;
if (performance.getCalls() != 0) {
avg = (int)(performance.getCostTotal() / performance.getCalls());
}
instanceJson.addProperty("avg", avg);
if (avg > 5000) {
......@@ -50,14 +58,22 @@ public class InstanceHealthService {
instanceJson.addProperty("healthLevel", 3);
}
instanceJson.addProperty("status", 0);
long heartBeatTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), instance.getHeartBeatTime());
long currentTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket);
IGCMetricDAO.GCCount gcCount = gcMetricDAO.getGCCount(s5TimeBucket, instance.getInstanceId());
if (currentTime - heartBeatTime < 1000 * 60 * 2) {
instanceJson.addProperty("status", 0);
} else {
instanceJson.addProperty("status", 1);
}
IGCMetricDAO.GCCount gcCount = gcMetricDAO.getGCCount(timeBuckets, instance.getInstanceId());
instanceJson.addProperty("ygc", gcCount.getYoung());
instanceJson.addProperty("ogc", gcCount.getOld());
instances.add(instanceJson);
});
return response;
}
}
......@@ -27,18 +27,18 @@ message ApplicationInstance {
message ApplicationInstanceMapping {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
int32 instanceId = 2;
}
message ApplicationInstanceRecover {
int32 applicationId = 1;
int32 applicationInstanceId = 2;
int32 instanceId = 2;
int64 registerTime = 3;
OSInfo osinfo = 4;
}
message ApplicationInstanceHeartbeat {
int32 applicationInstanceId = 1;
int32 instanceId = 1;
int64 heartbeatTime = 2;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册