Search in sources :

Example 1 with ServiceMetric

use of org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric in project incubator-skywalking by apache.

the class ServiceMetricEsUIDAO method getSlowService.

@Override
public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket, Integer topN, MetricSource metricSource) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
    searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
    if (applicationId != 0) {
        boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_APPLICATION_ID, applicationId));
    }
    boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
    searchRequestBuilder.setQuery(boolQuery);
    searchRequestBuilder.setSize(topN * 60);
    searchRequestBuilder.addSort(SortBuilders.fieldSort(ServiceMetricTable.COLUMN_TRANSACTION_AVERAGE_DURATION).order(SortOrder.DESC));
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    SearchHit[] searchHits = searchResponse.getHits().getHits();
    Set<Integer> serviceIds = new HashSet<>();
    List<ServiceMetric> serviceMetrics = new LinkedList<>();
    for (SearchHit searchHit : searchHits) {
        int serviceId = ((Number) searchHit.getSource().get(ServiceMetricTable.COLUMN_SERVICE_ID)).intValue();
        if (!serviceIds.contains(serviceId)) {
            ServiceMetric serviceMetric = new ServiceMetric();
            serviceMetric.setId(serviceId);
            serviceMetric.setCalls(((Number) searchHit.getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue());
            serviceMetric.setAvgResponseTime(((Number) searchHit.getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_AVERAGE_DURATION)).intValue());
            serviceMetrics.add(serviceMetric);
            serviceIds.add(serviceId);
        }
        if (topN == serviceIds.size()) {
            break;
        }
    }
    return serviceMetrics;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) ServiceMetric(org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) SearchResponse(org.elasticsearch.action.search.SearchResponse) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 2 with ServiceMetric

use of org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric in project incubator-skywalking by apache.

the class ApplicationService method getSlowService.

public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
    List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
    slowServices.forEach(slowService -> {
        ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
        try {
            slowService.setCallsPerSec((int) (slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        slowService.setName(serviceName.getServiceName());
    });
    return slowServices;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ParseException(java.text.ParseException) ServiceMetric(org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)

Example 3 with ServiceMetric

use of org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric in project incubator-skywalking by apache.

the class ServiceNameService method getSlowService.

public List<ServiceMetric> getSlowService(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) throws ParseException {
    List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
    slowServices.forEach(slowService -> {
        ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
        slowService.setName(serviceName.getServiceName());
        try {
            slowService.setCallsPerSec((int) (slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
    });
    return slowServices;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) ParseException(java.text.ParseException) ServiceMetric(org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)

Aggregations

ServiceMetric (org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric)3 ParseException (java.text.ParseException)2 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)2 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)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