Search in sources :

Example 16 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class ApplicationMetricEsUIDAO method getTopNApplicationThroughput.

@Override
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket, int betweenSecond, int topN, 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(2000);
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS));
    searchRequestBuilder.addAggregation(aggregationBuilder);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    List<ApplicationTPS> applicationTPSs = new LinkedList<>();
    Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
    applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
        int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
        Sum callSum = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS);
        long calls = (long) callSum.getValue();
        int callsPerSec = (int) (betweenSecond == 0 ? 0 : calls / betweenSecond);
        ApplicationTPS applicationTPS = new ApplicationTPS();
        applicationTPS.setApplicationId(applicationId);
        applicationTPS.setCallsPerSec(callsPerSec);
        applicationTPSs.add(applicationTPS);
    });
    applicationTPSs.sort((first, second) -> first.getCallsPerSec() > second.getCallsPerSec() ? -1 : 1);
    if (applicationTPSs.size() <= topN) {
        return applicationTPSs;
    } else {
        List<ApplicationTPS> newCollection = new LinkedList<>();
        for (int i = 0; i < topN; i++) {
            newCollection.add(applicationTPSs.get(i));
        }
        return newCollection;
    }
}
Also used : 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) ApplicationTPS(org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 17 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class ApplicationMetricEsUIDAO method getApplications.

@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;
}
Also used : 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) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 18 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class ApplicationReferenceMetricEsUIDAO method buildMetrics.

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();
        Terms targetApplicationIdTerms = sourceApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
        for (Terms.Bucket targetApplicationIdBucket : targetApplicationIdTerms.getBuckets()) {
            int targetApplicationId = targetApplicationIdBucket.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);
            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 referenceMetrics;
}
Also used : TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Sum(org.elasticsearch.search.aggregations.metrics.sum.Sum) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 19 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder 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 20 with TermsAggregationBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder in project incubator-skywalking by apache.

the class ServiceReferenceEsMetricUIDAO method getBehindServices.

@Override
public List<ServiceReferenceMetric> getBehindServices(Step step, long startTimeBucket, long endTimeBucket, MetricSource metricSource, int frontServiceId) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
    searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
    boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, frontServiceId));
    boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
    searchRequestBuilder.setQuery(boolQuery);
    searchRequestBuilder.setSize(0);
    TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100);
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
    aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
    searchRequestBuilder.addAggregation(aggregationBuilder);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    List<ServiceReferenceMetric> referenceMetrics = new LinkedList<>();
    Terms behindServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID);
    buildNodeByFrontServiceId(referenceMetrics, behindServiceIdTerms, frontServiceId);
    return referenceMetrics;
}
Also used : 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) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)64 SignificantTermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder)20 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)14 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)13 Test (org.junit.Test)11 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)8 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)8 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)8 LinkedList (java.util.LinkedList)7 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)6 IncludeExclude (org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude)6 Arrays (java.util.Arrays)4 Map (java.util.Map)4 SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)4 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)4 AggregationBuilders (org.elasticsearch.search.aggregations.AggregationBuilders)4 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)4 Nullable (javax.annotation.Nullable)3 Bucket (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket)3