use of org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo in project incubator-skywalking by apache.
the class InstanceEsUIDAO method buildAppServerInfo.
private List<AppServerInfo> buildAppServerInfo(SearchHit[] searchHits) {
List<AppServerInfo> appServerInfos = new LinkedList<>();
for (SearchHit searchHit : searchHits) {
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(((Number) searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
appServerInfo.setApplicationId(((Number) searchHit.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
appServerInfo.setOsInfo((String) searchHit.getSource().get(InstanceTable.COLUMN_OS_INFO));
appServerInfos.add(appServerInfo);
}
return appServerInfos;
}
use of org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo in project incubator-skywalking by apache.
the class InstanceMetricEsUIDAO method getServerThroughput.
@Override
public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket, long endTimeBucket, int secondBetween, int topN, MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(InstanceMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
if (applicationId != 0) {
boolQuery.must().add(QueryBuilders.termQuery(InstanceMetricTable.COLUMN_APPLICATION_ID, applicationId));
}
boolQuery.must().add(QueryBuilders.termQuery(InstanceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(InstanceMetricTable.COLUMN_INSTANCE_ID).field(InstanceMetricTable.COLUMN_INSTANCE_ID).size(2000);
aggregationBuilder.subAggregation(AggregationBuilders.sum(InstanceMetricTable.COLUMN_TRANSACTION_CALLS).field(InstanceMetricTable.COLUMN_TRANSACTION_CALLS));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<AppServerInfo> appServerInfos = new LinkedList<>();
Terms instanceIdTerms = searchResponse.getAggregations().get(InstanceMetricTable.COLUMN_INSTANCE_ID);
instanceIdTerms.getBuckets().forEach(instanceIdTerm -> {
int instanceId = instanceIdTerm.getKeyAsNumber().intValue();
Sum callSum = instanceIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS);
long calls = (long) callSum.getValue();
int callsPerSec = (int) (secondBetween == 0 ? 0 : calls / secondBetween);
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(instanceId);
appServerInfo.setCallsPerSec(callsPerSec);
appServerInfos.add(appServerInfo);
});
appServerInfos.sort((first, second) -> first.getCallsPerSec() > second.getCallsPerSec() ? -1 : 1);
if (appServerInfos.size() <= topN) {
return appServerInfos;
} else {
List<AppServerInfo> newCollection = new LinkedList<>();
for (int i = 0; i < topN; i++) {
newCollection.add(appServerInfos.get(i));
}
return newCollection;
}
}
use of org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo in project incubator-skywalking by apache.
the class ServerService method getServerThroughput.
public List<AppServerInfo> getServerThroughput(int applicationId, Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
int secondBetween = secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket);
List<AppServerInfo> serverThroughput = instanceMetricUIDAO.getServerThroughput(applicationId, step, startTimeBucket, endTimeBucket, secondBetween, topN, MetricSource.Callee);
serverThroughput.forEach(appServerInfo -> {
appServerInfo.setApplicationId(instanceCacheService.getApplicationId(appServerInfo.getId()));
String applicationCode = applicationCacheService.getApplicationById(appServerInfo.getApplicationId()).getApplicationCode();
appServerInfo.setApplicationCode(applicationCode);
Instance instance = instanceUIDAO.getInstance(appServerInfo.getId());
appServerInfo.setOsInfo(instance.getOsInfo());
});
buildAppServerInfo(serverThroughput);
return serverThroughput;
}
use of org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo in project incubator-skywalking by apache.
the class ServerService method searchServer.
public List<AppServerInfo> searchServer(String keyword, long startSecondTimeBucket, long endSecondTimeBucket) {
List<AppServerInfo> serverInfos = instanceUIDAO.searchServer(keyword, startSecondTimeBucket, endSecondTimeBucket);
for (int i = serverInfos.size() - 1; i >= 0; i--) {
if (serverInfos.get(i).getId() == Const.NONE_INSTANCE_ID) {
serverInfos.remove(i);
}
}
buildAppServerInfo(serverInfos);
return serverInfos;
}
use of org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo in project incubator-skywalking by apache.
the class InstanceH2UIDAO method buildAppServerInfo.
private List<AppServerInfo> buildAppServerInfo(String sql, Object[] params) {
H2Client client = getClient();
List<AppServerInfo> appServerInfos = new LinkedList<>();
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
AppServerInfo appServerInfo = new AppServerInfo();
appServerInfo.setId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
appServerInfo.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
appServerInfos.add(appServerInfo);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return appServerInfos;
}
Aggregations