Search in sources :

Example 1 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class StorageModuleEsProvider method prepare.

@Override
public void prepare(Properties config) throws ServiceNotProvidedException {
    String clusterName = config.getProperty(CLUSTER_NAME);
    Boolean clusterTransportSniffer = (Boolean) config.get(CLUSTER_TRANSPORT_SNIFFER);
    String clusterNodes = config.getProperty(CLUSTER_NODES);
    elasticSearchClient = new ElasticSearchClient(clusterName, clusterTransportSniffer, clusterNodes);
    this.registerServiceImplementation(IBatchDAO.class, new BatchEsDAO(elasticSearchClient));
    registerCacheDAO();
    registerRegisterDAO();
    registerPersistenceDAO();
    registerUiDAO();
    registerAlarmDAO();
}
Also used : BatchEsDAO(org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Example 2 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class EsDAO method getMaxId.

protected final int getMaxId(String indexName, String columnName) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName);
    searchRequestBuilder.setTypes("type");
    searchRequestBuilder.setSize(0);
    MaxAggregationBuilder aggregation = AggregationBuilders.max("agg").field(columnName);
    searchRequestBuilder.addAggregation(aggregation);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    Max agg = searchResponse.getAggregations().get("agg");
    int id = (int) agg.getValue();
    if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) {
        return 0;
    } else {
        return id;
    }
}
Also used : MaxAggregationBuilder(org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Max(org.elasticsearch.search.aggregations.metrics.max.Max) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 3 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class ElasticSearchStorageInstaller method createTable.

@Override
protected boolean createTable(Client client, TableDefine tableDefine) {
    ElasticSearchClient esClient = (ElasticSearchClient) client;
    ElasticSearchTableDefine esTableDefine = (ElasticSearchTableDefine) tableDefine;
    // mapping
    XContentBuilder mappingBuilder = null;
    Settings settings = createSettingBuilder(esTableDefine);
    try {
        mappingBuilder = createMappingBuilder(esTableDefine);
        logger.info("mapping builder str: {}", mappingBuilder.string());
    } catch (Exception e) {
        logger.error("create {} index mapping builder error", esTableDefine.getName());
    }
    boolean isAcknowledged = esClient.createIndex(esTableDefine.getName(), esTableDefine.type(), settings, mappingBuilder);
    logger.info("create {} index with type of {} finished, isAcknowledged: {}", esTableDefine.getName(), esTableDefine.type(), isAcknowledged);
    return isAcknowledged;
}
Also used : ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Settings(org.elasticsearch.common.settings.Settings) IOException(java.io.IOException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 4 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class InstanceRegisterEsDAO method save.

@Override
public void save(Instance instance) {
    logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
    ElasticSearchClient client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId());
    source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId());
    source.put(InstanceTable.COLUMN_APPLICATION_CODE, instance.getApplicationCode());
    source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID());
    source.put(InstanceTable.COLUMN_REGISTER_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getRegisterTime()));
    source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getHeartBeatTime()));
    source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo());
    source.put(InstanceTable.COLUMN_ADDRESS_ID, instance.getAddressId());
    source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress());
    IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Example 5 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class ServiceNameRegisterEsDAO method save.

@Override
public void save(ServiceName serviceName) {
    logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
    ElasticSearchClient client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
    source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
    source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
    source.put(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, serviceName.getServiceName());
    source.put(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, serviceName.getSrcSpanType());
    IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    logger.debug("save service name register info, application getApplicationId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Aggregations

ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)7 HashMap (java.util.HashMap)5 SearchHit (org.elasticsearch.search.SearchHit)5 IndexResponse (org.elasticsearch.action.index.IndexResponse)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)4 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 IOException (java.io.IOException)1 BatchEsDAO (org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 Max (org.elasticsearch.search.aggregations.metrics.max.Max)1 MaxAggregationBuilder (org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder)1 Min (org.elasticsearch.search.aggregations.metrics.min.Min)1 MinAggregationBuilder (org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder)1