Search in sources :

Example 1 with Application

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;
}
Also used : ValueCount(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Application(org.apache.skywalking.apm.collector.storage.ui.application.Application) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 2 with Application

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) Application(org.apache.skywalking.apm.collector.storage.ui.application.Application) LinkedList(java.util.LinkedList)

Example 3 with Application

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;
}
Also used : Application(org.apache.skywalking.apm.collector.storage.ui.application.Application)

Example 4 with Application

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;
}
Also used : HashMap(java.util.HashMap) DurationPoint(org.apache.skywalking.apm.collector.storage.utils.DurationPoint) Application(org.apache.skywalking.apm.collector.storage.ui.application.Application) AlarmTrend(org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend)

Aggregations

Application (org.apache.skywalking.apm.collector.storage.ui.application.Application)4 LinkedList (java.util.LinkedList)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 AlarmTrend (org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend)1 DurationPoint (org.apache.skywalking.apm.collector.storage.utils.DurationPoint)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)1 ValueCount (org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount)1