use of org.apache.skywalking.apm.collector.storage.ui.application.Application in project incubator-skywalking by apache.
the class InstanceEsUIDAO method getApplications.
@Override
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
logger.debug("application list get, start time: {}, end time: {}", startSecondTimeBucket, endSecondTimeBucket);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder boolQuery1 = QueryBuilders.boolQuery();
boolQuery1.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(endSecondTimeBucket));
boolQuery1.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).lte(endSecondTimeBucket));
BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery();
boolQuery2.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).lte(endSecondTimeBucket));
boolQuery2.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startSecondTimeBucket));
BoolQueryBuilder timeBoolQuery = QueryBuilders.boolQuery();
timeBoolQuery.should().add(boolQuery1);
timeBoolQuery.should().add(boolQuery2);
boolQueryBuilder.must().add(timeBoolQuery);
boolQueryBuilder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
if (applicationIds.length > 0) {
boolQueryBuilder.must().add(QueryBuilders.termsQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationIds));
}
searchRequestBuilder.setQuery(boolQueryBuilder);
searchRequestBuilder.setSize(0);
searchRequestBuilder.addAggregation(AggregationBuilders.terms(InstanceTable.COLUMN_APPLICATION_ID).field(InstanceTable.COLUMN_APPLICATION_ID).size(100).subAggregation(AggregationBuilders.count(InstanceTable.COLUMN_INSTANCE_ID).field(InstanceTable.COLUMN_INSTANCE_ID)));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
Terms genders = searchResponse.getAggregations().get(InstanceTable.COLUMN_APPLICATION_ID);
List<Application> applications = new LinkedList<>();
for (Terms.Bucket applicationsBucket : genders.getBuckets()) {
Integer applicationId = applicationsBucket.getKeyAsNumber().intValue();
logger.debug("applicationId: {}", applicationId);
ValueCount instanceCount = applicationsBucket.getAggregations().get(InstanceTable.COLUMN_INSTANCE_ID);
Application application = new Application();
application.setId(applicationId);
application.setNumOfServer((int) instanceCount.getValue());
applications.add(application);
}
return applications;
}
use of org.apache.skywalking.apm.collector.storage.ui.application.Application in project incubator-skywalking by apache.
the class InstanceH2UIDAO method getApplications.
@Override
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
H2Client client = getClient();
List<Application> applications = new LinkedList<>();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] { startSecondTimeBucket };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
logger.debug("applicationId: {}", applicationId);
Application application = new Application();
application.setId(applicationId);
application.setNumOfServer(rs.getInt("cnt"));
applications.add(application);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return applications;
}
use of org.apache.skywalking.apm.collector.storage.ui.application.Application in project incubator-skywalking by apache.
the class ApplicationService method getApplications.
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
List<Application> applications = instanceDAO.getApplications(startSecondTimeBucket, endSecondTimeBucket, applicationIds);
for (int i = applications.size() - 1; i >= 0; i--) {
Application application = applications.get(i);
if (application.getId() == Const.NONE_APPLICATION_ID) {
applications.remove(i);
}
}
applications.forEach(application -> {
String applicationCode = applicationCacheService.getApplicationById(application.getId()).getApplicationCode();
application.setName(applicationCode);
});
return applications;
}
use of org.apache.skywalking.apm.collector.storage.ui.application.Application in project incubator-skywalking by apache.
the class AlarmService method getApplicationAlarmTrend.
public AlarmTrend getApplicationAlarmTrend(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) throws ParseException {
List<Application> applications = instanceDAO.getApplications(startSecondTimeBucket, endSecondTimeBucket);
List<DurationPoint> durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, startTimeBucket, endTimeBucket);
List<IApplicationAlarmListUIDAO.AlarmTrend> alarmTrends = applicationAlarmListUIDAO.getAlarmedApplicationNum(step, startTimeBucket, endTimeBucket);
Map<Long, Integer> trendsMap = new HashMap<>();
alarmTrends.forEach(alarmTrend -> trendsMap.put(alarmTrend.getTimeBucket(), alarmTrend.getNumberOfApplication()));
AlarmTrend alarmTrend = new AlarmTrend();
durationPoints.forEach(durationPoint -> {
if (applications.size() == 0) {
alarmTrend.getNumOfAlarmRate().add(0);
} else {
alarmTrend.getNumOfAlarmRate().add((trendsMap.getOrDefault(durationPoint.getPoint(), 0) * 10000) / (applications.size()));
}
});
return alarmTrend;
}
Aggregations