Merge pull request #836 from peng-yongsheng/feature/getClusterTopology
Feature/get cluster topology
This commit is contained in:
commit
9cd0f98b06
|
|
@ -30,4 +30,82 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
|
|||
public interface IApplicationMetricUIDAO extends DAO {
|
||||
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, int topN,
|
||||
MetricSource metricSource);
|
||||
|
||||
List<ApplicationMetric> getApplications(Step step, long startTimeBucket, long endTimeBucket,
|
||||
MetricSource metricSource);
|
||||
|
||||
class ApplicationMetric {
|
||||
private int id;
|
||||
private long calls;
|
||||
private long errorCalls;
|
||||
private long durations;
|
||||
private long errorDurations;
|
||||
private long satisfiedCount;
|
||||
private long toleratingCount;
|
||||
private long frustratedCount;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setCalls(long calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
public void setErrorCalls(long errorCalls) {
|
||||
this.errorCalls = errorCalls;
|
||||
}
|
||||
|
||||
public void setDurations(long durations) {
|
||||
this.durations = durations;
|
||||
}
|
||||
|
||||
public void setErrorDurations(long errorDurations) {
|
||||
this.errorDurations = errorDurations;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getCalls() {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public long getErrorCalls() {
|
||||
return errorCalls;
|
||||
}
|
||||
|
||||
public long getDurations() {
|
||||
return durations;
|
||||
}
|
||||
|
||||
public long getErrorDurations() {
|
||||
return errorDurations;
|
||||
}
|
||||
|
||||
public long getSatisfiedCount() {
|
||||
return satisfiedCount;
|
||||
}
|
||||
|
||||
public void setSatisfiedCount(long satisfiedCount) {
|
||||
this.satisfiedCount = satisfiedCount;
|
||||
}
|
||||
|
||||
public long getToleratingCount() {
|
||||
return toleratingCount;
|
||||
}
|
||||
|
||||
public void setToleratingCount(long toleratingCount) {
|
||||
this.toleratingCount = toleratingCount;
|
||||
}
|
||||
|
||||
public long getFrustratedCount() {
|
||||
return frustratedCount;
|
||||
}
|
||||
|
||||
public void setFrustratedCount(long frustratedCount) {
|
||||
this.frustratedCount = frustratedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,18 +21,75 @@ package org.apache.skywalking.apm.collector.storage.dao.ui;
|
|||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IApplicationReferenceMetricUIDAO extends DAO {
|
||||
List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
MetricSource metricSource);
|
||||
|
||||
List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
MetricSource metricSource);
|
||||
|
||||
List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource);
|
||||
List<ApplicationReferenceMetric> getReferences(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource);
|
||||
|
||||
class ApplicationReferenceMetric {
|
||||
private int source;
|
||||
private int target;
|
||||
private long calls;
|
||||
private long errorCalls;
|
||||
private long durations;
|
||||
private long errorDurations;
|
||||
|
||||
public int getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(int source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public int getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(int target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public long getCalls() {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public void setCalls(long calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
public long getErrorCalls() {
|
||||
return errorCalls;
|
||||
}
|
||||
|
||||
public void setErrorCalls(long errorCalls) {
|
||||
this.errorCalls = errorCalls;
|
||||
}
|
||||
|
||||
public long getDurations() {
|
||||
return durations;
|
||||
}
|
||||
|
||||
public void setDurations(long durations) {
|
||||
this.durations = durations;
|
||||
}
|
||||
|
||||
public long getErrorDurations() {
|
||||
return errorDurations;
|
||||
}
|
||||
|
||||
public void setErrorDurations(long errorDurations) {
|
||||
this.errorDurations = errorDurations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,5 +38,9 @@ public interface IInstanceUIDAO extends DAO {
|
|||
|
||||
List<AppServerInfo> searchServer(String keyword, long start, long end);
|
||||
|
||||
List<AppServerInfo> getAllServer(int applicationId, long start, long end);
|
||||
List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket);
|
||||
|
||||
long getEarliestRegisterTime(int applicationId);
|
||||
|
||||
long getLatestHeartBeatTime(int applicationId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,76 +25,76 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
|||
*/
|
||||
public class ApplicationNode extends Node {
|
||||
|
||||
private Float sla;
|
||||
private Long callsPerSec;
|
||||
private Long responseTimePerSec;
|
||||
private Float apdex;
|
||||
private Boolean isAlarm;
|
||||
private Integer numOfServer;
|
||||
private Integer numOfServerAlarm;
|
||||
private Integer numOfServiceAlarm;
|
||||
private int sla;
|
||||
private long callsPerSec;
|
||||
private long avgResponseTime;
|
||||
private int apdex;
|
||||
private boolean isAlarm;
|
||||
private int numOfServer;
|
||||
private int numOfServerAlarm;
|
||||
private int numOfServiceAlarm;
|
||||
|
||||
public Float getSla() {
|
||||
public int getSla() {
|
||||
return sla;
|
||||
}
|
||||
|
||||
public void setSla(Float sla) {
|
||||
public void setSla(int sla) {
|
||||
this.sla = sla;
|
||||
}
|
||||
|
||||
public Long getCallsPerSec() {
|
||||
public long getCallsPerSec() {
|
||||
return callsPerSec;
|
||||
}
|
||||
|
||||
public void setCallsPerSec(Long callsPerSec) {
|
||||
public void setCallsPerSec(long callsPerSec) {
|
||||
this.callsPerSec = callsPerSec;
|
||||
}
|
||||
|
||||
public Long getResponseTimePerSec() {
|
||||
return responseTimePerSec;
|
||||
public long getAvgResponseTime() {
|
||||
return avgResponseTime;
|
||||
}
|
||||
|
||||
public void setResponseTimePerSec(Long responseTimePerSec) {
|
||||
this.responseTimePerSec = responseTimePerSec;
|
||||
public void setAvgResponseTime(long avgResponseTime) {
|
||||
this.avgResponseTime = avgResponseTime;
|
||||
}
|
||||
|
||||
public Float getApdex() {
|
||||
public int getApdex() {
|
||||
return apdex;
|
||||
}
|
||||
|
||||
public void setApdex(Float apdex) {
|
||||
public void setApdex(int apdex) {
|
||||
this.apdex = apdex;
|
||||
}
|
||||
|
||||
public Boolean getAlarm() {
|
||||
public boolean isAlarm() {
|
||||
return isAlarm;
|
||||
}
|
||||
|
||||
public void setAlarm(Boolean alarm) {
|
||||
public void setAlarm(boolean alarm) {
|
||||
isAlarm = alarm;
|
||||
}
|
||||
|
||||
public Integer getNumOfServer() {
|
||||
public int getNumOfServer() {
|
||||
return numOfServer;
|
||||
}
|
||||
|
||||
public void setNumOfServer(Integer numOfServer) {
|
||||
public void setNumOfServer(int numOfServer) {
|
||||
this.numOfServer = numOfServer;
|
||||
}
|
||||
|
||||
public Integer getNumOfServerAlarm() {
|
||||
public int getNumOfServerAlarm() {
|
||||
return numOfServerAlarm;
|
||||
}
|
||||
|
||||
public void setNumOfServerAlarm(Integer numOfServerAlarm) {
|
||||
public void setNumOfServerAlarm(int numOfServerAlarm) {
|
||||
this.numOfServerAlarm = numOfServerAlarm;
|
||||
}
|
||||
|
||||
public Integer getNumOfServiceAlarm() {
|
||||
public int getNumOfServiceAlarm() {
|
||||
return numOfServiceAlarm;
|
||||
}
|
||||
|
||||
public void setNumOfServiceAlarm(Integer numOfServiceAlarm) {
|
||||
public void setNumOfServiceAlarm(int numOfServiceAlarm) {
|
||||
this.numOfServiceAlarm = numOfServiceAlarm;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,8 @@ public class Call {
|
|||
private String targetName;
|
||||
private boolean isAlert;
|
||||
private String callType;
|
||||
private long calls;
|
||||
private long callsPerSec;
|
||||
private long responseTimes;
|
||||
private long responseTimePerSec;
|
||||
private long avgResponseTime;
|
||||
|
||||
public int getSource() {
|
||||
return source;
|
||||
|
|
@ -81,14 +79,6 @@ public class Call {
|
|||
this.callType = callType;
|
||||
}
|
||||
|
||||
public long getCalls() {
|
||||
return calls;
|
||||
}
|
||||
|
||||
public void setCalls(long calls) {
|
||||
this.calls = calls;
|
||||
}
|
||||
|
||||
public long getCallsPerSec() {
|
||||
return callsPerSec;
|
||||
}
|
||||
|
|
@ -97,19 +87,11 @@ public class Call {
|
|||
this.callsPerSec = callsPerSec;
|
||||
}
|
||||
|
||||
public long getResponseTimes() {
|
||||
return responseTimes;
|
||||
public long getAvgResponseTime() {
|
||||
return avgResponseTime;
|
||||
}
|
||||
|
||||
public void setResponseTimes(long responseTimes) {
|
||||
this.responseTimes = responseTimes;
|
||||
}
|
||||
|
||||
public long getResponseTimePerSec() {
|
||||
return responseTimePerSec;
|
||||
}
|
||||
|
||||
public void setResponseTimePerSec(long responseTimePerSec) {
|
||||
this.responseTimePerSec = responseTimePerSec;
|
||||
public void setAvgResponseTime(long avgResponseTime) {
|
||||
this.avgResponseTime = avgResponseTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ public class InstanceHeartBeatEsPersistenceDAO extends EsDAO implements IInstanc
|
|||
instance.setId(id);
|
||||
instance.setInstanceId(((Number)source.get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
|
||||
instance.setHeartBeatTime(((Number)source.get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
|
||||
logger.debug("getId: {} is exists", id);
|
||||
logger.debug("getApplicationId: {} is exists", id);
|
||||
return instance;
|
||||
} else {
|
||||
logger.debug("getId: {} is not exists", id);
|
||||
logger.debug("getApplicationId: {} is not exists", id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class SegmentDurationEsPersistenceDAO extends EsDAO implements ISegmentDu
|
|||
}
|
||||
|
||||
@Override public IndexRequestBuilder prepareBatchInsert(SegmentDuration data) {
|
||||
logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId());
|
||||
logger.debug("segment cost prepareBatchInsert, getApplicationId: {}", data.getId());
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(SegmentDurationTable.COLUMN_SEGMENT_ID, data.getSegmentId());
|
||||
source.put(SegmentDurationTable.COLUMN_APPLICATION_ID, data.getApplicationId());
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class ApplicationRegisterEsDAO extends EsDAO implements IApplicationRegis
|
|||
}
|
||||
|
||||
@Override public void save(Application application) {
|
||||
logger.debug("save application register info, application getId: {}, application code: {}", application.getId(), application.getApplicationCode());
|
||||
logger.debug("save application register info, application getApplicationId: {}, application code: {}", application.getId(), application.getApplicationCode());
|
||||
ElasticSearchClient client = getClient();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
|
||||
|
|
@ -59,6 +59,6 @@ public class ApplicationRegisterEsDAO extends EsDAO implements IApplicationRegis
|
|||
source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
|
||||
|
||||
IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
logger.debug("save application register info, application getId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
|
||||
logger.debug("save application register info, application getApplicationId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO
|
|||
}
|
||||
|
||||
@Override public void save(Instance instance) {
|
||||
logger.debug("save instance register info, application getId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
|
||||
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
|
||||
ElasticSearchClient client = getClient();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId());
|
||||
|
|
@ -65,7 +65,7 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO
|
|||
source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress());
|
||||
|
||||
IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
logger.debug("save instance register info, application getId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
|
||||
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
|
||||
}
|
||||
|
||||
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class NetworkAddressRegisterEsDAO extends EsDAO implements INetworkAddres
|
|||
}
|
||||
|
||||
@Override public void save(NetworkAddress networkAddress) {
|
||||
logger.debug("save network address register info, address getId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
|
||||
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
|
||||
ElasticSearchClient client = getClient();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress());
|
||||
|
|
@ -59,7 +59,7 @@ public class NetworkAddressRegisterEsDAO extends EsDAO implements INetworkAddres
|
|||
source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, networkAddress.getServerType());
|
||||
|
||||
IndexResponse response = client.prepareIndex(NetworkAddressTable.TABLE, networkAddress.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
logger.debug("save network address register info, address getId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
|
||||
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
|
||||
}
|
||||
|
||||
@Override public void update(String id, int spanLayer, int serverType) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class ServiceNameRegisterEsDAO extends EsDAO implements IServiceNameRegis
|
|||
}
|
||||
|
||||
@Override public void save(ServiceName serviceName) {
|
||||
logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
|
||||
logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
|
||||
ElasticSearchClient client = getClient();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
|
||||
|
|
@ -58,6 +58,6 @@ public class ServiceNameRegisterEsDAO extends EsDAO implements IServiceNameRegis
|
|||
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
|
||||
|
||||
IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
logger.debug("save service name register info, application getId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
|
||||
logger.debug("save service name register info, application getApplicationId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.elasticsearch.script.Script;
|
|||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
||||
import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders;
|
||||
|
||||
|
|
@ -88,17 +89,72 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
|
|||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<ApplicationTPS> applicationTPSs = new LinkedList<>();
|
||||
Terms serviceIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
|
||||
serviceIdTerms.getBuckets().forEach(serviceIdTerm -> {
|
||||
int applicationId = serviceIdTerm.getKeyAsNumber().intValue();
|
||||
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
|
||||
applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
|
||||
int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
|
||||
|
||||
ApplicationTPS serviceMetric = new ApplicationTPS();
|
||||
InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_TPS);
|
||||
ApplicationTPS applicationTPS = new ApplicationTPS();
|
||||
InternalSimpleValue simpleValue = applicationIdTerm.getAggregations().get(AVG_TPS);
|
||||
|
||||
serviceMetric.setApplicationId(applicationId);
|
||||
serviceMetric.setTps((int)simpleValue.getValue());
|
||||
applicationTPSs.add(serviceMetric);
|
||||
applicationTPS.setApplicationId(applicationId);
|
||||
applicationTPS.setTps((int)simpleValue.getValue());
|
||||
applicationTPSs.add(applicationTPS);
|
||||
});
|
||||
return applicationTPSs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationMetric> getApplications(Step step, long startTimeBucket, long endTimeBucket,
|
||||
MetricSource metricSource) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ApplicationMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ApplicationMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationMetricTable.COLUMN_APPLICATION_ID).field(ApplicationMetricTable.COLUMN_APPLICATION_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_SATISFIED_COUNT).field(ApplicationMetricTable.COLUMN_SATISFIED_COUNT));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TOLERATING_COUNT).field(ApplicationMetricTable.COLUMN_TOLERATING_COUNT));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT).field(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<ApplicationMetric> applicationMetrics = new LinkedList<>();
|
||||
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
|
||||
applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
|
||||
int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
|
||||
|
||||
Sum calls = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum errorCalls = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
Sum durations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
Sum errorDurations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
Sum satisfiedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_SATISFIED_COUNT);
|
||||
Sum toleratingCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TOLERATING_COUNT);
|
||||
Sum frustratedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT);
|
||||
|
||||
ApplicationMetric applicationMetric = new ApplicationMetric();
|
||||
applicationMetric.setId(applicationId);
|
||||
applicationMetric.setCalls((long)calls.getValue());
|
||||
applicationMetric.setErrorCalls((long)errorCalls.getValue());
|
||||
applicationMetric.setDurations((long)durations.getValue());
|
||||
applicationMetric.setErrorDurations((long)errorDurations.getValue());
|
||||
applicationMetric.setSatisfiedCount((long)satisfiedCount.getValue());
|
||||
applicationMetric.setToleratingCount((long)toleratingCount.getValue());
|
||||
applicationMetric.setToleratingCount((long)frustratedCount.getValue());
|
||||
applicationMetrics.add(applicationMetric);
|
||||
});
|
||||
return applicationMetrics;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceM
|
|||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
|
|
@ -47,7 +46,8 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
@Override public List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime,
|
||||
long endTime,
|
||||
MetricSource metricSource) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
|
||||
|
||||
|
|
@ -63,32 +63,12 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
|
|||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Call> nodes = new LinkedList<>();
|
||||
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
|
||||
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
|
||||
int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
Sum calls = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum responseTimes = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
|
||||
Call call = new Call();
|
||||
call.setSource(frontApplicationId);
|
||||
call.setTarget(applicationId);
|
||||
call.setCalls((int)calls.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
nodes.add(call);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
return buildMetrics(searchRequestBuilder);
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
@Override
|
||||
public List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime,
|
||||
long endTime,
|
||||
MetricSource metricSource) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
|
||||
|
||||
|
|
@ -104,32 +84,11 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
|
|||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Call> nodes = new LinkedList<>();
|
||||
Terms behindApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
|
||||
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
|
||||
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
|
||||
Call call = new Call();
|
||||
call.setTarget(behindApplicationId);
|
||||
call.setSource(applicationId);
|
||||
call.setCalls((int)calls.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
nodes.add(call);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
return buildMetrics(searchRequestBuilder);
|
||||
}
|
||||
|
||||
@Override public List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource) {
|
||||
@Override public List<ApplicationReferenceMetric> getReferences(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
|
|
@ -143,35 +102,46 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
|
|||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100)
|
||||
.subAggregation(AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
return buildMetrics(searchRequestBuilder);
|
||||
}
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
private List<ApplicationReferenceMetric> buildMetrics(SearchRequestBuilder searchRequestBuilder) {
|
||||
TermsAggregationBuilder frontAggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100);
|
||||
TermsAggregationBuilder behindAggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100);
|
||||
frontAggregationBuilder.subAggregation(behindAggregationBuilder);
|
||||
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
|
||||
|
||||
searchRequestBuilder.addAggregation(frontAggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
List<ApplicationReferenceMetric> referenceMetrics = new LinkedList<>();
|
||||
Terms sourceApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
|
||||
for (Terms.Bucket sourceApplicationIdBucket : sourceApplicationIdTerms.getBuckets()) {
|
||||
int sourceApplicationId = sourceApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
|
||||
List<Call> nodes = new LinkedList<>();
|
||||
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
|
||||
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
|
||||
int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
Terms targetApplicationIdTerms = sourceApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
|
||||
for (Terms.Bucket targetApplicationIdBucket : targetApplicationIdTerms.getBuckets()) {
|
||||
int targetApplicationId = targetApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
|
||||
Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
|
||||
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
|
||||
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
|
||||
Sum calls = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum errorCalls = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
Sum durations = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
Sum errorDurations = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
|
||||
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
|
||||
Call call = new Call();
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
call.setSource(frontApplicationId);
|
||||
call.setTarget(behindApplicationId);
|
||||
call.setCalls((int)calls.getValue());
|
||||
nodes.add(call);
|
||||
ApplicationReferenceMetric referenceMetric = new ApplicationReferenceMetric();
|
||||
referenceMetric.setSource(sourceApplicationId);
|
||||
referenceMetric.setTarget(targetApplicationId);
|
||||
referenceMetric.setCalls((long)calls.getValue());
|
||||
referenceMetric.setErrorCalls((long)errorCalls.getValue());
|
||||
referenceMetric.setDurations((long)durations.getValue());
|
||||
referenceMetric.setErrorDurations((long)errorDurations.getValue());
|
||||
referenceMetrics.add(referenceMetric);
|
||||
}
|
||||
}
|
||||
|
||||
return nodes;
|
||||
return referenceMetrics;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,15 +171,18 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
|
|||
return buildAppServerInfo(searchHits);
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
|
||||
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
|
||||
@Override
|
||||
public List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket) {
|
||||
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, startSecondTimeBucket, endSecondTimeBucket);
|
||||
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(start).lte(end));
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).gte(startSecondTimeBucket).lte(endSecondTimeBucket));
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startSecondTimeBucket));
|
||||
|
||||
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
|
|
@ -190,6 +193,46 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
|
|||
return buildAppServerInfo(searchHits);
|
||||
}
|
||||
|
||||
@Override public long getEarliestRegisterTime(int applicationId) {
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
|
||||
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
searchRequestBuilder.setSize(1);
|
||||
|
||||
searchRequestBuilder.setQuery(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
|
||||
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_REGISTER_TIME).sortMode(SortMode.MIN));
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
if (searchHits.length > 0) {
|
||||
return ((Number)searchHits[0].getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue();
|
||||
}
|
||||
|
||||
return Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override public long getLatestHeartBeatTime(int applicationId) {
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
|
||||
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
searchRequestBuilder.setSize(1);
|
||||
|
||||
searchRequestBuilder.setQuery(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
|
||||
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_HEARTBEAT_TIME).sortMode(SortMode.MAX));
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
if (searchHits.length > 0) {
|
||||
return ((Number)searchHits[0].getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue();
|
||||
}
|
||||
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
private List<AppServerInfo> buildAppServerInfo(SearchHit[] searchHits) {
|
||||
List<AppServerInfo> appServerInfos = new LinkedList<>();
|
||||
for (SearchHit searchHit : searchHits) {
|
||||
|
|
|
|||
|
|
@ -177,8 +177,8 @@ public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceRefe
|
|||
Call call = new Call();
|
||||
call.setSource(frontServiceId);
|
||||
call.setTarget(behindServiceId);
|
||||
call.setCalls((int)callsSum.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
// call.setCalls((int)callsSum.getValue());
|
||||
// call.setResponseTimes((int)responseTimes.getValue());
|
||||
calls.add(call);
|
||||
});
|
||||
}
|
||||
|
|
@ -192,8 +192,8 @@ public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceRefe
|
|||
Call call = new Call();
|
||||
call.setTarget(behindServiceId);
|
||||
call.setSource(frontServiceId);
|
||||
call.setCalls((int)callsSum.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
// call.setCalls((int)callsSum.getValue());
|
||||
// call.setResponseTimes((int)responseTimes.getValue());
|
||||
calls.add(call);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class SegmentDurationH2PersistenceDAO extends H2DAO implements ISegmentDu
|
|||
}
|
||||
|
||||
@Override public H2SqlEntity prepareBatchInsert(SegmentDuration data) {
|
||||
logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId());
|
||||
logger.debug("segment cost prepareBatchInsert, getApplicationId: {}", data.getId());
|
||||
H2SqlEntity entity = new H2SqlEntity();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(SegmentDurationTable.COLUMN_ID, data.getId());
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class ServiceNameRegisterH2DAO extends H2DAO implements IServiceNameRegis
|
|||
|
||||
@Override
|
||||
public void save(ServiceName serviceName) {
|
||||
logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
|
||||
logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
|
||||
H2Client client = getClient();
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put(ServiceNameTable.COLUMN_ID, serviceName.getId());
|
||||
|
|
|
|||
|
|
@ -44,4 +44,9 @@ public class ApplicationMetricH2UIDAO extends H2DAO implements IApplicationMetri
|
|||
int topN, MetricSource metricSource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<ApplicationMetric> getApplications(Step step, long startTimeBucket,
|
||||
long endTimeBucket, MetricSource metricSource) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -42,7 +41,8 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
@Override public List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime,
|
||||
long endTime,
|
||||
MetricSource metricSource) {
|
||||
H2Client client = getClient();
|
||||
JsonArray applicationReferenceMetricArray = new JsonArray();
|
||||
|
|
@ -74,12 +74,16 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
|
||||
@Override
|
||||
public List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime,
|
||||
long endTime,
|
||||
MetricSource metricSource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource) {
|
||||
@Override
|
||||
public List<ApplicationReferenceMetric> getReferences(Step step, long startTime,
|
||||
long endTime, MetricSource metricSource) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,11 +139,12 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
|||
return buildAppServerInfo(sql, params);
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
|
||||
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
|
||||
String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} = ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
|
||||
Object[] params = new Object[] {applicationId, start, end, BooleanUtils.FALSE};
|
||||
@Override
|
||||
public List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket) {
|
||||
logger.debug("get instances info, applicationId: {}, startSecondTimeBucket: {}, endSecondTimeBucket: {}", applicationId, startSecondTimeBucket, endSecondTimeBucket);
|
||||
String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} >= ? and {4} = ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_REGISTER_TIME, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
|
||||
Object[] params = new Object[] {applicationId, startSecondTimeBucket, endSecondTimeBucket, startSecondTimeBucket, BooleanUtils.FALSE};
|
||||
return buildAppServerInfo(sql, params);
|
||||
}
|
||||
|
||||
|
|
@ -163,4 +164,14 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
|||
}
|
||||
return appServerInfos;
|
||||
}
|
||||
|
||||
//TODO
|
||||
@Override public long getEarliestRegisterTime(int applicationId) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO
|
||||
@Override public long getLatestHeartBeatTime(int applicationId) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,10 +89,13 @@ public class OverViewLayerQuery implements Query {
|
|||
}
|
||||
|
||||
public Topology getClusterTopology(Duration duration) throws ParseException {
|
||||
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
|
||||
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
|
||||
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
|
||||
|
||||
return getClusterTopologyService().getClusterTopology(duration.getStep(), start, end);
|
||||
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
|
||||
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
|
||||
|
||||
return getClusterTopologyService().getClusterTopology(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
|
||||
}
|
||||
|
||||
public ClusterBrief getClusterBrief(Duration duration) throws ParseException {
|
||||
|
|
|
|||
|
|
@ -20,20 +20,15 @@ package org.apache.skywalking.apm.collector.ui.service;
|
|||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -66,64 +61,64 @@ public class ApplicationTopologyService {
|
|||
Map<Integer, String> components = new HashMap<>();
|
||||
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
|
||||
|
||||
List<Call> callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller);
|
||||
callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller));
|
||||
|
||||
callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
|
||||
|
||||
List<Call> calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee);
|
||||
calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee));
|
||||
|
||||
calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
|
||||
|
||||
Set<Integer> mappings = new HashSet<>();
|
||||
applicationMappings.forEach(mapping -> {
|
||||
if (applicationId == mapping.getApplicationId()) {
|
||||
mappings.add(mapping.getMappingApplicationId());
|
||||
}
|
||||
});
|
||||
|
||||
mappings.forEach(mappingApplicationId -> {
|
||||
List<Call> frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
|
||||
frontCallerApplications.forEach(call -> {
|
||||
call.setCallType(components.get(call.getTarget()));
|
||||
call.setTarget(applicationId);
|
||||
callerCalls.add(call);
|
||||
});
|
||||
|
||||
List<Call> behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
|
||||
behindCallerApplications.forEach(call -> {
|
||||
call.setCallType(components.get(call.getTarget()));
|
||||
call.setSource(applicationId);
|
||||
callerCalls.add(call);
|
||||
});
|
||||
|
||||
List<Call> frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
|
||||
frontCalleeApplications.forEach(call -> {
|
||||
call.setCallType(components.get(call.getTarget()));
|
||||
call.setTarget(applicationId);
|
||||
calleeCalls.add(call);
|
||||
});
|
||||
|
||||
List<Call> behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
|
||||
behindCalleeApplications.forEach(call -> {
|
||||
call.setCallType(components.get(call.getTarget()));
|
||||
call.setSource(applicationId);
|
||||
calleeCalls.add(call);
|
||||
});
|
||||
});
|
||||
// List<Call> callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller);
|
||||
// callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller));
|
||||
//
|
||||
// callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
|
||||
//
|
||||
// List<Call> calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee);
|
||||
// calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee));
|
||||
//
|
||||
// calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
|
||||
//
|
||||
// Set<Integer> mappings = new HashSet<>();
|
||||
// applicationMappings.forEach(mapping -> {
|
||||
// if (applicationId == mapping.getApplicationId()) {
|
||||
// mappings.add(mapping.getMappingApplicationId());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// mappings.forEach(mappingApplicationId -> {
|
||||
// List<Call> frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
|
||||
// frontCallerApplications.forEach(call -> {
|
||||
// call.setCallType(components.get(call.getTarget()));
|
||||
// call.setTarget(applicationId);
|
||||
// callerCalls.add(call);
|
||||
// });
|
||||
//
|
||||
// List<Call> behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
|
||||
// behindCallerApplications.forEach(call -> {
|
||||
// call.setCallType(components.get(call.getTarget()));
|
||||
// call.setSource(applicationId);
|
||||
// callerCalls.add(call);
|
||||
// });
|
||||
//
|
||||
// List<Call> frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
|
||||
// frontCalleeApplications.forEach(call -> {
|
||||
// call.setCallType(components.get(call.getTarget()));
|
||||
// call.setTarget(applicationId);
|
||||
// calleeCalls.add(call);
|
||||
// });
|
||||
//
|
||||
// List<Call> behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
|
||||
// behindCalleeApplications.forEach(call -> {
|
||||
// call.setCallType(components.get(call.getTarget()));
|
||||
// call.setSource(applicationId);
|
||||
// calleeCalls.add(call);
|
||||
// });
|
||||
// });
|
||||
|
||||
TopologyBuilder builder = new TopologyBuilder(moduleManager);
|
||||
|
||||
long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
|
||||
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
|
||||
|
||||
topology.getCalls().forEach(call -> {
|
||||
long calls = call.getCalls();
|
||||
long responseTimes = call.getResponseTimes();
|
||||
call.setCallsPerSec(calls / secondsBetween);
|
||||
call.setResponseTimePerSec(responseTimes / secondsBetween);
|
||||
});
|
||||
return topology;
|
||||
// long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
|
||||
// Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
|
||||
//
|
||||
// topology.getCalls().forEach(call -> {
|
||||
// long calls = call.getCalls();
|
||||
// long responseTimes = call.getResponseTimes();
|
||||
// call.setCallsPerSec(calls / secondsBetween);
|
||||
// call.setAvgResponseTime(responseTimes / secondsBetween);
|
||||
// });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,11 @@ import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
|||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -45,6 +44,7 @@ public class ClusterTopologyService {
|
|||
|
||||
private final IApplicationComponentUIDAO applicationComponentUIDAO;
|
||||
private final IApplicationMappingUIDAO applicationMappingUIDAO;
|
||||
private final IApplicationMetricUIDAO applicationMetricUIDAO;
|
||||
private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO;
|
||||
private final ModuleManager moduleManager;
|
||||
|
||||
|
|
@ -52,35 +52,26 @@ public class ClusterTopologyService {
|
|||
this.moduleManager = moduleManager;
|
||||
this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class);
|
||||
this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class);
|
||||
this.applicationMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMetricUIDAO.class);
|
||||
this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class);
|
||||
}
|
||||
|
||||
public Topology getClusterTopology(Step step, long startTime, long endTime) throws ParseException {
|
||||
logger.debug("startTime: {}, endTime: {}", startTime, endTime);
|
||||
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTime, endTime);
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTime, endTime);
|
||||
public Topology getClusterTopology(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket,
|
||||
long endSecondTimeBucket) throws ParseException {
|
||||
logger.debug("startTimeBucket: {}, endTimeBucket: {}, startSecondTimeBucket: {}, endSecondTimeBucket: {}", startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
|
||||
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
|
||||
|
||||
Map<Integer, String> components = new HashMap<>();
|
||||
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
|
||||
|
||||
List<Call> callerCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Caller);
|
||||
callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
|
||||
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics = applicationMetricUIDAO.getApplications(step, startTimeBucket, endTimeBucket, MetricSource.Callee);
|
||||
|
||||
List<Call> calleeCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Callee);
|
||||
|
||||
calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Caller);
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Callee);
|
||||
|
||||
TopologyBuilder builder = new TopologyBuilder(moduleManager);
|
||||
|
||||
long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
|
||||
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
|
||||
|
||||
topology.getCalls().forEach(call -> {
|
||||
long calls = call.getCalls();
|
||||
long responseTimes = call.getResponseTimes();
|
||||
call.setCallsPerSec(calls / secondsBetween);
|
||||
call.setResponseTimePerSec(responseTimes / secondsBetween);
|
||||
});
|
||||
return topology;
|
||||
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, startSecondTimeBucket, endSecondTimeBucket);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.ui.service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Seconds;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
class SecondBetweenService {
|
||||
|
||||
private final IInstanceUIDAO instanceUIDAO;
|
||||
|
||||
SecondBetweenService(ModuleManager moduleManager) {
|
||||
this.instanceUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
|
||||
}
|
||||
|
||||
int calculate(int applicationId, long startSecondTimeBucket,
|
||||
long endSecondTimeBucket) throws ParseException {
|
||||
long registerTime = instanceUIDAO.getEarliestRegisterTime(applicationId);
|
||||
if (startSecondTimeBucket < registerTime) {
|
||||
startSecondTimeBucket = registerTime;
|
||||
}
|
||||
|
||||
long heartBeatTime = instanceUIDAO.getLatestHeartBeatTime(applicationId);
|
||||
if (endSecondTimeBucket > heartBeatTime) {
|
||||
endSecondTimeBucket = heartBeatTime;
|
||||
}
|
||||
|
||||
Date startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(startSecondTimeBucket));
|
||||
Date endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(endSecondTimeBucket));
|
||||
|
||||
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
|
||||
}
|
||||
}
|
||||
|
|
@ -18,12 +18,11 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.ui.service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.skywalking.apm.collector.cache.CacheModule;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
|
|
@ -31,6 +30,8 @@ import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
|
|||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.Application;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode;
|
||||
|
|
@ -38,72 +39,134 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
|||
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.ApdexCalculator;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.SLACalculator;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
class TopologyBuilder {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(TopologyBuilder.class);
|
||||
|
||||
private final ApplicationCacheService applicationCacheService;
|
||||
private final ServerService serverService;
|
||||
private final SecondBetweenService secondBetweenService;
|
||||
|
||||
TopologyBuilder(ModuleManager moduleManager) {
|
||||
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
|
||||
this.serverService = new ServerService(moduleManager);
|
||||
this.secondBetweenService = new SecondBetweenService(moduleManager);
|
||||
}
|
||||
|
||||
Topology build(List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents,
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings, List<Call> callerCalls,
|
||||
List<Call> calleeCalls, long secondsBetween) {
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings,
|
||||
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics,
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric,
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric,
|
||||
long startSecondTimeBucket, long endSecondTimeBucket) {
|
||||
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
|
||||
Map<String, String> mappings = changeMapping2Map(applicationMappings);
|
||||
Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
|
||||
|
||||
List<Call> calls = buildCalls(callerCalls, calleeCalls);
|
||||
|
||||
Set<Integer> nodeIds = new HashSet<>();
|
||||
calls.forEach(call -> {
|
||||
String sourceName = applicationCacheService.getApplicationById(call.getSource()).getApplicationCode();
|
||||
String targetName = applicationCacheService.getApplicationById(call.getTarget()).getApplicationCode();
|
||||
|
||||
call.setSourceName(sourceName);
|
||||
call.setTargetName(targetName);
|
||||
|
||||
nodeIds.add(call.getSource());
|
||||
nodeIds.add(call.getTarget());
|
||||
});
|
||||
calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
|
||||
|
||||
List<Node> nodes = new LinkedList<>();
|
||||
nodeIds.forEach(nodeId -> {
|
||||
Application application = applicationCacheService.getApplicationById(nodeId);
|
||||
if (BooleanUtils.valueToBoolean(application.getAddressId())) {
|
||||
ConjecturalNode conjecturalNode = new ConjecturalNode();
|
||||
conjecturalNode.setId(nodeId);
|
||||
conjecturalNode.setName(application.getApplicationCode());
|
||||
conjecturalNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
|
||||
nodes.add(conjecturalNode);
|
||||
} else {
|
||||
if (nodeId == Const.NONE_APPLICATION_ID) {
|
||||
VisualUserNode node = new VisualUserNode();
|
||||
node.setId(nodeId);
|
||||
node.setName(Const.USER_CODE);
|
||||
node.setType(Const.USER_CODE.toUpperCase());
|
||||
nodes.add(node);
|
||||
} else {
|
||||
ApplicationNode applicationNode = new ApplicationNode();
|
||||
applicationNode.setId(nodeId);
|
||||
applicationNode.setName(application.getApplicationCode());
|
||||
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
|
||||
applicationMetrics.forEach(applicationMetric -> {
|
||||
int applicationId = applicationMetric.getId();
|
||||
Application application = applicationCacheService.getApplicationById(applicationId);
|
||||
ApplicationNode applicationNode = new ApplicationNode();
|
||||
applicationNode.setId(applicationId);
|
||||
applicationNode.setName(application.getApplicationCode());
|
||||
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
|
||||
|
||||
calleeCalls.forEach(call -> {
|
||||
if (call.getTarget() == nodeId) {
|
||||
call.setCallsPerSec(call.getCalls() / secondsBetween);
|
||||
call.setResponseTimePerSec(call.getResponseTimes() / secondsBetween);
|
||||
}
|
||||
});
|
||||
applicationNode.setCallsPerSec(100L);
|
||||
applicationNode.setResponseTimePerSec(100L);
|
||||
nodes.add(applicationNode);
|
||||
}
|
||||
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
|
||||
try {
|
||||
applicationNode.setCallsPerSec(applicationMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
|
||||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
applicationNode.setAvgResponseTime((applicationMetric.getDurations() - applicationMetric.getErrorDurations()) / (applicationMetric.getCalls() - applicationMetric.getErrorCalls()));
|
||||
applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
|
||||
applicationNode.setAlarm(false);
|
||||
applicationNode.setNumOfServer(serverService.getAllServer(applicationId, startSecondTimeBucket, endSecondTimeBucket).size());
|
||||
applicationNode.setNumOfServerAlarm(1);
|
||||
applicationNode.setNumOfServiceAlarm(1);
|
||||
nodes.add(applicationNode);
|
||||
});
|
||||
|
||||
List<Call> calls = new LinkedList<>();
|
||||
callerReferenceMetric.forEach(referenceMetric -> {
|
||||
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
|
||||
Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
|
||||
|
||||
if (BooleanUtils.valueToBoolean(target.getIsAddress()) && !mappings.containsKey(target.getApplicationId())) {
|
||||
ConjecturalNode conjecturalNode = new ConjecturalNode();
|
||||
conjecturalNode.setId(target.getApplicationId());
|
||||
conjecturalNode.setName(target.getApplicationCode());
|
||||
conjecturalNode.setType(components.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
|
||||
nodes.add(conjecturalNode);
|
||||
}
|
||||
|
||||
Call call = new Call();
|
||||
call.setSource(source.getApplicationId());
|
||||
call.setSourceName(source.getApplicationCode());
|
||||
|
||||
int actualTargetId = mappings.getOrDefault(target.getApplicationId(), target.getApplicationId());
|
||||
call.setTarget(actualTargetId);
|
||||
call.setTargetName(applicationCacheService.getApplicationById(actualTargetId).getApplicationCode());
|
||||
call.setAlert(true);
|
||||
call.setCallType(components.get(referenceMetric.getTarget()));
|
||||
try {
|
||||
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
|
||||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
|
||||
calls.add(call);
|
||||
});
|
||||
|
||||
calleeReferenceMetric.forEach(referenceMetric -> {
|
||||
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
|
||||
Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
|
||||
|
||||
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
|
||||
VisualUserNode visualUserNode = new VisualUserNode();
|
||||
visualUserNode.setId(source.getApplicationId());
|
||||
visualUserNode.setName(Const.USER_CODE);
|
||||
visualUserNode.setType(Const.USER_CODE.toUpperCase());
|
||||
nodes.add(visualUserNode);
|
||||
}
|
||||
|
||||
if (BooleanUtils.valueToBoolean(source.getIsAddress())) {
|
||||
ConjecturalNode conjecturalNode = new ConjecturalNode();
|
||||
conjecturalNode.setId(source.getApplicationId());
|
||||
conjecturalNode.setName(source.getApplicationCode());
|
||||
conjecturalNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
|
||||
nodes.add(conjecturalNode);
|
||||
}
|
||||
|
||||
Call call = new Call();
|
||||
call.setSource(source.getApplicationId());
|
||||
call.setSourceName(source.getApplicationCode());
|
||||
call.setTarget(target.getApplicationId());
|
||||
call.setTargetName(target.getApplicationCode());
|
||||
call.setAlert(true);
|
||||
|
||||
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
|
||||
call.setCallType(Const.EMPTY_STRING);
|
||||
} else {
|
||||
call.setCallType(components.get(referenceMetric.getTarget()));
|
||||
}
|
||||
try {
|
||||
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
|
||||
} catch (ParseException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
|
||||
calls.add(call);
|
||||
});
|
||||
|
||||
Topology topology = new Topology();
|
||||
|
|
@ -112,14 +175,24 @@ class TopologyBuilder {
|
|||
return topology;
|
||||
}
|
||||
|
||||
private Map<String, String> changeMapping2Map(
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings) {
|
||||
Map<String, String> mappings = new HashMap<>();
|
||||
applicationMappings.forEach(applicationMapping -> {
|
||||
String applicationCode = applicationCacheService.getApplicationById(applicationMapping.getApplicationId()).getApplicationCode();
|
||||
String address = applicationCacheService.getApplicationById(applicationMapping.getMappingApplicationId()).getApplicationCode();
|
||||
mappings.put(address, applicationCode);
|
||||
private List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetricFilter(
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric) {
|
||||
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> filteredMetrics = new LinkedList<>();
|
||||
|
||||
calleeReferenceMetric.forEach(referenceMetric -> {
|
||||
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
|
||||
if (BooleanUtils.valueToBoolean(source.getIsAddress()) || source.getApplicationId() == Const.NONE_APPLICATION_ID) {
|
||||
filteredMetrics.add(referenceMetric);
|
||||
}
|
||||
});
|
||||
|
||||
return filteredMetrics;
|
||||
}
|
||||
|
||||
private Map<Integer, Integer> changeMapping2Map(
|
||||
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings) {
|
||||
Map<Integer, Integer> mappings = new HashMap<>();
|
||||
applicationMappings.forEach(applicationMapping -> mappings.put(applicationMapping.getMappingApplicationId(), applicationMapping.getApplicationId()));
|
||||
return mappings;
|
||||
}
|
||||
|
||||
|
|
@ -132,24 +205,4 @@ class TopologyBuilder {
|
|||
});
|
||||
return components;
|
||||
}
|
||||
|
||||
private List<Call> buildCalls(List<Call> callerCalls, List<Call> calleeCalls) {
|
||||
List<Call> calls = new LinkedList<>();
|
||||
|
||||
Set<String> distinctCalls = new HashSet<>();
|
||||
callerCalls.forEach(callerCall -> {
|
||||
distinctCalls.add(callerCall.getSource() + Const.ID_SPLIT + callerCall.getTarget());
|
||||
calls.add(callerCall);
|
||||
});
|
||||
|
||||
calleeCalls.forEach(calleeCall -> {
|
||||
String call = calleeCall.getSource() + Const.ID_SPLIT + calleeCall.getTarget();
|
||||
if (!distinctCalls.contains(call)) {
|
||||
distinctCalls.add(call);
|
||||
calls.add(calleeCall);
|
||||
}
|
||||
});
|
||||
|
||||
return calls;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.ui.utils;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public enum ApdexCalculator {
|
||||
INSTANCE;
|
||||
|
||||
public int calculate(long satisfiedCount, long toleratingCount, long frustratedCount) {
|
||||
return (int)(((satisfiedCount + toleratingCount / 2) * 100) / (satisfiedCount + toleratingCount + frustratedCount));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.ui.utils;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public enum SLACalculator {
|
||||
INSTANCE;
|
||||
|
||||
public int calculate(long errorCalls, long calls) {
|
||||
return (int)(((calls - errorCalls) * 100) / calls);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ type ApplicationNode implements Node {
|
|||
# The number of incoming calls
|
||||
callsPerSec: Long!
|
||||
# Unit: millisecond
|
||||
responseTimePerSec: Long!
|
||||
avgResponseTime: Long!
|
||||
# ref: http://www.apdex.org/
|
||||
# Max value is 100
|
||||
# 2 Digits after floating point in UI, need to division by 100. 100 -> 1.00
|
||||
|
|
|
|||
|
|
@ -106,5 +106,5 @@ type Call {
|
|||
callType: String!
|
||||
callsPerSec: Long!
|
||||
# Unit: millisecond
|
||||
responseTimePerSec: Long!
|
||||
avgResponseTime: Long!
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue