Search in sources :

Example 1 with AlarmItem

use of org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem in project incubator-skywalking by apache.

the class ApplicationAlarmEsUIDAO method loadAlarmList.

@Override
public Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationAlarmTable.TABLE);
    searchRequestBuilder.setTypes(ApplicationAlarmTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must().add(QueryBuilders.rangeQuery(ApplicationAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
    if (StringUtils.isNotEmpty(keyword)) {
        boolQueryBuilder.must().add(QueryBuilders.matchQuery(ApplicationAlarmTable.COLUMN_ALARM_CONTENT, keyword));
    }
    searchRequestBuilder.setQuery(boolQueryBuilder);
    searchRequestBuilder.setSize(limit);
    searchRequestBuilder.setFrom(from);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    SearchHit[] searchHits = searchResponse.getHits().getHits();
    Alarm alarm = new Alarm();
    alarm.setTotal((int) searchResponse.getHits().getTotalHits());
    for (SearchHit searchHit : searchHits) {
        AlarmItem alarmItem = new AlarmItem();
        alarmItem.setId(((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_APPLICATION_ID)).intValue());
        alarmItem.setContent((String) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_ALARM_CONTENT));
        long lastTimeBucket = ((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue();
        alarmItem.setStartTime(TimeBucketUtils.INSTANCE.formatMinuteTimeBucket(lastTimeBucket));
        alarmItem.setAlarmType(AlarmType.APPLICATION);
        int alarmType = ((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_ALARM_TYPE)).intValue();
        if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.SLOW_RTT.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.SLOW_RESPONSE);
        } else if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.ERROR_RATE.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.LOW_SUCCESS_RATE);
        }
        alarm.getItems().add(alarmItem);
    }
    return alarm;
}
Also used : AlarmItem(org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 2 with AlarmItem

use of org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem in project incubator-skywalking by apache.

the class ServiceAlarmEsUIDAO method loadAlarmList.

@Override
public Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceAlarmTable.TABLE);
    searchRequestBuilder.setTypes(ServiceAlarmTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must().add(QueryBuilders.rangeQuery(ServiceAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
    if (StringUtils.isNotEmpty(keyword)) {
        boolQueryBuilder.must().add(QueryBuilders.matchQuery(ServiceAlarmTable.COLUMN_ALARM_CONTENT, keyword));
    }
    searchRequestBuilder.setQuery(boolQueryBuilder);
    searchRequestBuilder.setSize(limit);
    searchRequestBuilder.setFrom(from);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    SearchHit[] searchHits = searchResponse.getHits().getHits();
    Alarm alarm = new Alarm();
    alarm.setTotal((int) searchResponse.getHits().getTotalHits());
    for (SearchHit searchHit : searchHits) {
        AlarmItem alarmItem = new AlarmItem();
        alarmItem.setId(((Number) searchHit.getSource().get(ServiceAlarmTable.COLUMN_SERVICE_ID)).intValue());
        alarmItem.setTitle((String) searchHit.getSource().get(ServiceAlarmTable.COLUMN_ALARM_CONTENT));
        alarmItem.setContent((String) searchHit.getSource().get(ServiceAlarmTable.COLUMN_ALARM_CONTENT));
        long lastTimeBucket = ((Number) searchHit.getSource().get(ServiceAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue();
        alarmItem.setStartTime(TimeBucketUtils.INSTANCE.formatMinuteTimeBucket(lastTimeBucket));
        alarmItem.setAlarmType(AlarmType.SERVICE);
        int alarmType = ((Number) searchHit.getSource().get(ServiceAlarmTable.COLUMN_ALARM_TYPE)).intValue();
        if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.SLOW_RTT.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.SLOW_RESPONSE);
        } else if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.ERROR_RATE.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.LOW_SUCCESS_RATE);
        }
        alarm.getItems().add(alarmItem);
    }
    return alarm;
}
Also used : AlarmItem(org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 3 with AlarmItem

use of org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem in project incubator-skywalking by apache.

the class InstanceAlarmEsUIDAO method loadAlarmList.

@Override
public Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceAlarmTable.TABLE);
    searchRequestBuilder.setTypes(InstanceAlarmTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must().add(QueryBuilders.rangeQuery(InstanceAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
    if (StringUtils.isNotEmpty(keyword)) {
        boolQueryBuilder.must().add(QueryBuilders.matchQuery(InstanceAlarmTable.COLUMN_ALARM_CONTENT, keyword));
    }
    searchRequestBuilder.setQuery(boolQueryBuilder);
    searchRequestBuilder.setSize(limit);
    searchRequestBuilder.setFrom(from);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    SearchHit[] searchHits = searchResponse.getHits().getHits();
    Alarm alarm = new Alarm();
    alarm.setTotal((int) searchResponse.getHits().getTotalHits());
    for (SearchHit searchHit : searchHits) {
        AlarmItem alarmItem = new AlarmItem();
        alarmItem.setId(((Number) searchHit.getSource().get(InstanceAlarmTable.COLUMN_INSTANCE_ID)).intValue());
        alarmItem.setTitle((String) searchHit.getSource().get(InstanceAlarmTable.COLUMN_ALARM_CONTENT));
        alarmItem.setContent((String) searchHit.getSource().get(InstanceAlarmTable.COLUMN_ALARM_CONTENT));
        long lastTimeBucket = ((Number) searchHit.getSource().get(InstanceAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue();
        alarmItem.setStartTime(TimeBucketUtils.INSTANCE.formatMinuteTimeBucket(lastTimeBucket));
        alarmItem.setAlarmType(AlarmType.SERVER);
        int alarmType = ((Number) searchHit.getSource().get(InstanceAlarmTable.COLUMN_ALARM_TYPE)).intValue();
        if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.SLOW_RTT.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.SLOW_RESPONSE);
        } else if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.ERROR_RATE.getValue() == alarmType) {
            alarmItem.setCauseType(CauseType.LOW_SUCCESS_RATE);
        }
        alarm.getItems().add(alarmItem);
    }
    return alarm;
}
Also used : AlarmItem(org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

Alarm (org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)3 AlarmItem (org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem)3 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 SearchHit (org.elasticsearch.search.SearchHit)3