Search in sources :

Example 1 with AppServerInfo

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;
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) SearchHit(org.elasticsearch.search.SearchHit) LinkedList(java.util.LinkedList)

Example 2 with AppServerInfo

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;
    }
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) LinkedList(java.util.LinkedList) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 3 with AppServerInfo

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;
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 4 with AppServerInfo

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;
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 5 with AppServerInfo

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;
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) LinkedList(java.util.LinkedList)

Aggregations

AppServerInfo (org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo)5 LinkedList (java.util.LinkedList)3 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)3 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 SearchHit (org.elasticsearch.search.SearchHit)1 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)1 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)1