Search in sources :

Example 6 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class CpuMetricEsUIDAO method getCPUTrend.

@Override
public List<Integer> getCPUTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, CpuMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId;
            this.add(tableName, CpuMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> cpuTrends = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
        if (response.getResponse().isExists()) {
            double cpuUsed = ((Number) response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue();
            long times = ((Number) response.getResponse().getSource().get(CpuMetricTable.COLUMN_TIMES)).longValue();
            cpuTrends.add((int) ((cpuUsed / times) * 100));
        } else {
            cpuTrends.add(0);
        }
    }
    return cpuTrends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) LinkedList(java.util.LinkedList) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 7 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class GCMetricEsUIDAO method getGCTrend.

private List<Integer> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
    String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE);
    MultiGetRequestBuilder youngPrepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase;
            add(tableName, GCMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> gcTrends = new LinkedList<>();
    MultiGetResponse multiGetResponse = youngPrepareMultiGet.get();
    for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) {
        if (itemResponse.getResponse().isExists()) {
            long count = ((Number) itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).longValue();
            long times = ((Number) itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_TIMES)).intValue();
            gcTrends.add((int) (count / times));
        } else {
            gcTrends.add(0);
        }
    }
    return gcTrends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) LinkedList(java.util.LinkedList) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 8 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class InstanceMetricEsUIDAO method getServerTPSTrend.

@Override
public List<Integer> getServerTPSTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
            add(tableName, InstanceMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> throughputTrend = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    for (int i = 0; i < multiGetResponse.getResponses().length; i++) {
        MultiGetItemResponse response = multiGetResponse.getResponses()[i];
        if (response.getResponse().isExists()) {
            long callTimes = ((Number) response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
            throughputTrend.add((int) (callTimes / durationPoints.get(i).getSecondsBetween()));
        } else {
            throughputTrend.add(0);
        }
    }
    return throughputTrend;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) LinkedList(java.util.LinkedList) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 9 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class InstanceMetricEsUIDAO method getResponseTimeTrend.

@Override
public List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
            add(tableName, InstanceMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> responseTimeTrends = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
        if (response.getResponse().isExists()) {
            long callTimes = ((Number) response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
            long errorCallTimes = ((Number) response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue();
            long durationSum = ((Number) response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue();
            long errorDurationSum = ((Number) response.getResponse().getSource().get(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM)).longValue();
            long correctCallTimes = callTimes - errorCallTimes;
            if (correctCallTimes != 0L) {
                responseTimeTrends.add((int) ((durationSum - errorDurationSum) / correctCallTimes));
            } else {
                responseTimeTrends.add(0);
            }
        } else {
            responseTimeTrends.add(0);
        }
    }
    return responseTimeTrends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) LinkedList(java.util.LinkedList) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Example 10 with MultiGetResponse

use of org.elasticsearch.action.get.MultiGetResponse in project incubator-skywalking by apache.

the class ServiceMetricEsUIDAO method getServiceSLATrend.

@Override
public List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
    String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
    MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(durationPoints, new ElasticSearchClient.MultiGetRowHandler<DurationPoint>() {

        @Override
        public void accept(DurationPoint durationPoint) {
            String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
            add(tableName, ServiceMetricTable.TABLE_TYPE, id);
        }
    });
    List<Integer> trends = new LinkedList<>();
    MultiGetResponse multiGetResponse = prepareMultiGet.get();
    for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
        if (response.getResponse().isExists()) {
            long calls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
            long errorCalls = ((Number) response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue();
            trends.add((int) (((calls - errorCalls) / calls)) * 10000);
        } else {
            trends.add(10000);
        }
    }
    return trends;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint)

Aggregations

MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)30 MultiGetItemResponse (org.elasticsearch.action.get.MultiGetItemResponse)15 MultiGetRequestBuilder (org.elasticsearch.action.get.MultiGetRequestBuilder)13 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)9 ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)8 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)8 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)4 HashMap (java.util.HashMap)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 JsonRawRestResponse (alien4cloud.rest.model.JsonRawRestResponse)2 ApiOperation (io.swagger.annotations.ApiOperation)2 List (java.util.List)2 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 Item (org.elasticsearch.action.get.MultiGetRequest.Item)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2