Provide the getAlarmTrend query.
This commit is contained in:
parent
47e1db5011
commit
23975678a9
|
|
@ -105,6 +105,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay
|
|||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
|
|
@ -264,6 +265,7 @@ public class StorageModule extends Module {
|
|||
classes.add(IApplicationAlarmUIDAO.class);
|
||||
classes.add(IInstanceAlarmUIDAO.class);
|
||||
classes.add(IServiceAlarmUIDAO.class);
|
||||
classes.add(IApplicationAlarmListUIDAO.class);
|
||||
}
|
||||
|
||||
private void addAlarmDAO(List<Class> classes) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.storage.dao.ui;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IApplicationAlarmListUIDAO extends DAO {
|
||||
|
||||
List<Integer> getAlarmedApplicationNum(Step step, long start, long end);
|
||||
}
|
||||
|
|
@ -18,11 +18,25 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.ui.overview;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class AlarmTrend {
|
||||
public List<Integer> numOfAlarmRate;
|
||||
|
||||
private List<Integer> numOfAlarmRate;
|
||||
|
||||
public AlarmTrend() {
|
||||
this.numOfAlarmRate = new LinkedList<>();
|
||||
}
|
||||
|
||||
public List<Integer> getNumOfAlarmRate() {
|
||||
return numOfAlarmRate;
|
||||
}
|
||||
|
||||
public void setNumOfAlarmRate(List<Integer> numOfAlarmRate) {
|
||||
this.numOfAlarmRate = numOfAlarmRate;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay
|
|||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
|
|
@ -220,6 +221,7 @@ import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceH
|
|||
import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceMinuteMetricEsPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceMonthMetricEsPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationAlarmEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationAlarmListEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationComponentEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationMappingEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationMetricEsUIDAO;
|
||||
|
|
@ -430,6 +432,8 @@ public class StorageModuleEsProvider extends ModuleProvider {
|
|||
this.registerServiceImplementation(IApplicationAlarmUIDAO.class, new ApplicationAlarmEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(IInstanceAlarmUIDAO.class, new InstanceAlarmEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(IServiceAlarmUIDAO.class, new ServiceAlarmEsUIDAO(elasticSearchClient));
|
||||
|
||||
this.registerServiceImplementation(IApplicationAlarmListUIDAO.class, new ApplicationAlarmListEsUIDAO(elasticSearchClient));
|
||||
}
|
||||
|
||||
private void registerAlarmDAO() throws ServiceNotProvidedException {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ApplicationAlarmListEsUIDAO extends EsDAO implements IApplicationAlarmListUIDAO {
|
||||
|
||||
public ApplicationAlarmListEsUIDAO(ElasticSearchClient client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Integer> getAlarmedApplicationNum(Step step, long start, long end) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationAlarmListTable.TABLE);
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ApplicationAlarmListTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationAlarmListTable.COLUMN_TIME_BUCKET).gte(start).lte(end));
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
searchRequestBuilder.addAggregation(AggregationBuilders.terms(ApplicationAlarmListTable.COLUMN_TIME_BUCKET).field(ApplicationAlarmListTable.COLUMN_TIME_BUCKET).size(100)
|
||||
.subAggregation(AggregationBuilders.terms(ApplicationAlarmListTable.COLUMN_APPLICATION_ID).field(ApplicationAlarmListTable.COLUMN_APPLICATION_ID).size(100)));
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
Terms timeBucketTerms = searchResponse.getAggregations().get(ApplicationAlarmListTable.COLUMN_TIME_BUCKET);
|
||||
|
||||
List<Integer> alarmApplicationNum = new LinkedList<>();
|
||||
for (Terms.Bucket timeBucketBucket : timeBucketTerms.getBuckets()) {
|
||||
Terms applicationBucketTerms = timeBucketBucket.getAggregations().get(ApplicationAlarmListTable.COLUMN_APPLICATION_ID);
|
||||
int num = applicationBucketTerms.getBuckets().size();
|
||||
alarmApplicationNum.add(num);
|
||||
}
|
||||
|
||||
return alarmApplicationNum;
|
||||
}
|
||||
}
|
||||
|
|
@ -110,6 +110,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay
|
|||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
|
||||
|
|
@ -216,6 +217,7 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceH
|
|||
import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceMinuteMetricH2PersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceMonthMetricH2PersistenceDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationAlarmH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationAlarmListH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationComponentH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationMappingH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationMetricH2UIDAO;
|
||||
|
|
@ -406,6 +408,8 @@ public class StorageModuleH2Provider extends ModuleProvider {
|
|||
this.registerServiceImplementation(IApplicationAlarmUIDAO.class, new ApplicationAlarmH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(IInstanceAlarmUIDAO.class, new InstanceAlarmH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(IServiceAlarmUIDAO.class, new ServiceAlarmH2UIDAO(h2Client));
|
||||
|
||||
this.registerServiceImplementation(IApplicationAlarmListUIDAO.class, new ApplicationAlarmListH2UIDAO(h2Client));
|
||||
}
|
||||
|
||||
private void registerAlarmDAO() throws ServiceNotProvidedException {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ApplicationAlarmListH2UIDAO extends H2DAO implements IApplicationAlarmListUIDAO {
|
||||
|
||||
public ApplicationAlarmListH2UIDAO(H2Client client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Integer> getAlarmedApplicationNum(Step step, long start, long end) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -109,10 +109,13 @@ public class OverViewLayerQuery implements Query {
|
|||
}
|
||||
|
||||
public AlarmTrend getAlarmTrend(Duration duration) throws ParseException {
|
||||
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
|
||||
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
|
||||
|
||||
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
|
||||
|
||||
return getAlarmService().getApplicationAlarmTrend(duration.getStep(), start, end);
|
||||
return getAlarmService().getApplicationAlarmTrend(duration.getStep(), startTimeBucket, endTimeBucket, start, end);
|
||||
}
|
||||
|
||||
public ConjecturalAppBrief getConjecturalApps(Duration duration) throws ParseException {
|
||||
|
|
|
|||
|
|
@ -22,14 +22,15 @@ import java.text.ParseException;
|
|||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmListUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceAlarmUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.application.Application;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -40,14 +41,18 @@ public class AlarmService {
|
|||
|
||||
private final Logger logger = LoggerFactory.getLogger(AlarmService.class);
|
||||
|
||||
private final IInstanceUIDAO instanceDAO;
|
||||
private final IApplicationAlarmUIDAO applicationAlarmUIDAO;
|
||||
private final IInstanceAlarmUIDAO instanceAlarmUIDAO;
|
||||
private final IServiceAlarmUIDAO serviceAlarmUIDAO;
|
||||
private final IApplicationAlarmListUIDAO applicationAlarmListUIDAO;
|
||||
|
||||
public AlarmService(ModuleManager moduleManager) {
|
||||
this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
|
||||
this.applicationAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationAlarmUIDAO.class);
|
||||
this.instanceAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceAlarmUIDAO.class);
|
||||
this.serviceAlarmUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceAlarmUIDAO.class);
|
||||
this.applicationAlarmListUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationAlarmListUIDAO.class);
|
||||
}
|
||||
|
||||
public Alarm loadApplicationAlarmList(String keyword, long start, long end,
|
||||
|
|
@ -68,10 +73,15 @@ public class AlarmService {
|
|||
return serviceAlarmUIDAO.loadAlarmList(keyword, start, end, limit, from);
|
||||
}
|
||||
|
||||
public AlarmTrend getApplicationAlarmTrend(Step step, long start, long end) throws ParseException {
|
||||
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end);
|
||||
public AlarmTrend getApplicationAlarmTrend(Step step, long startTimeBucket, long endTimeBucket, long start,
|
||||
long end) throws ParseException {
|
||||
List<Application> applications = instanceDAO.getApplications(start, end);
|
||||
|
||||
List<Integer> applicationNum = applicationAlarmListUIDAO.getAlarmedApplicationNum(step, startTimeBucket, endTimeBucket);
|
||||
AlarmTrend alarmTrend = new AlarmTrend();
|
||||
applicationNum.forEach(num -> {
|
||||
alarmTrend.getNumOfAlarmRate().add((num * 10000) / (applications.size()));
|
||||
});
|
||||
return alarmTrend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue