Search in sources :

Example 6 with Alarm

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

the class AlarmService method loadApplicationAlarmList.

public Alarm loadApplicationAlarmList(String keyword, Step step, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
    logger.debug("keyword: {}, startTimeBucket: {}, endTimeBucket: {}, limit: {}, from: {}", keyword, startTimeBucket, endTimeBucket, limit, from);
    Alarm alarm = applicationAlarmUIDAO.loadAlarmList(keyword, startTimeBucket, endTimeBucket, limit, from);
    List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
    Map<Integer, Integer> mappings = new HashMap<>();
    applicationMappings.forEach(applicationMapping -> mappings.put(applicationMapping.getMappingApplicationId(), applicationMapping.getApplicationId()));
    alarm.getItems().forEach(item -> {
        String applicationCode = applicationCacheService.getApplicationById(mappings.getOrDefault(item.getId(), item.getId())).getApplicationCode();
        switch(item.getCauseType()) {
            case SLOW_RESPONSE:
                item.setTitle("Application " + applicationCode + RESPONSE_TIME_ALARM);
                break;
            case LOW_SUCCESS_RATE:
                item.setTitle("Application " + applicationCode + SUCCESS_RATE_ALARM);
                break;
        }
    });
    return alarm;
}
Also used : HashMap(java.util.HashMap) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)

Example 7 with Alarm

use of org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm 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)7 HashMap (java.util.HashMap)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 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1 ApplicationNode (org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode)1 ConjecturalNode (org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode)1 Call (org.apache.skywalking.apm.collector.storage.ui.common.Call)1 Node (org.apache.skywalking.apm.collector.storage.ui.common.Node)1 Topology (org.apache.skywalking.apm.collector.storage.ui.common.Topology)1 VisualUserNode (org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode)1