org.elasticsearch.action.admin.indices.stats.CommonStatsFlags Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.stats.CommonStatsFlags. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportIndexShardStatsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected ShardStats shardOperation(IndexShardStatsRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.shardSafe(shardRouting.shardId().id());
    // if we don't have the routing entry yet, we need it stats wise, we treat it as if the shard is not ready yet
    if (indexShard.routingEntry() == null) {
        throw new ShardNotFoundException(indexShard.shardId());
    }

    if (!indexShard.state().equals(IndexShardState.STARTED)) {
        throw new ElasticsearchException(indexShard.shardId().toString() + " state is " + indexShard.state() + ", not started");
    }
    
    CommonStatsFlags flags = new CommonStatsFlags().clear();

    if (request.dl()) {
        flags.set(CommonStatsFlags.Flag.DL);
    }

    return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats());
}
 
Example #2
Source File: NodeService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public NodeStats stats(CommonStatsFlags indices, boolean os, boolean process, boolean jvm, boolean threadPool,
                       boolean fs, boolean transport, boolean http, boolean circuitBreaker,
                       boolean script) {
    // for indices stats we want to include previous allocated shards stats as well (it will
    // only be applied to the sensible ones to use, like refresh/merge/flush/indexing stats)
    return new NodeStats(discovery.localNode(), System.currentTimeMillis(),
            indices.anySet() ? indicesService.stats(true, indices) : null,
            os ? monitorService.osService().stats() : null,
            process ? monitorService.processService().stats() : null,
            jvm ? monitorService.jvmService().stats() : null,
            threadPool ? this.threadPool.stats() : null,
            fs ? monitorService.fsService().stats() : null,
            transport ? transportService.stats() : null,
            http ? (httpServer == null ? null : httpServer.stats()) : null,
            circuitBreaker ? circuitBreakerService.stats() : null,
            script ? scriptService.stats() : null
    );
}
 
Example #3
Source File: TransportClusterStatsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
    NodeInfo nodeInfo = nodeService.info(false, true, false, true, false, true, false, true);
    NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false);
    List<ShardStats> shardsStats = new ArrayList<>();
    for (IndexService indexService : indicesService) {
        for (IndexShard indexShard : indexService) {
            if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
                // only report on fully started shards
                shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, SHARD_STATS_FLAGS), indexShard.commitStats()));
            }
        }
    }

    ClusterHealthStatus clusterStatus = null;
    if (clusterService.state().nodes().localNodeMaster()) {
        clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
    }

    return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));

}
 
Example #4
Source File: IndexShardStatsRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    flags = CommonStatsFlags.readCommonStatsFlags(in);
    indexName = in.readString();
    shardId = in.readInt();
}
 
Example #5
Source File: NodesStatsRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    indices = CommonStatsFlags.readCommonStatsFlags(in);
    os = in.readBoolean();
    process = in.readBoolean();
    jvm = in.readBoolean();
    threadPool = in.readBoolean();
    fs = in.readBoolean();
    transport = in.readBoolean();
    http = in.readBoolean();
    breaker = in.readBoolean();
    script = in.readBoolean();
}
 
Example #6
Source File: GraphiteService.java    From elasticsearch-graphite-plugin with Do What The F*ck You Want To Public License 5 votes vote down vote up
public void run() {
    while (!closed) {
        DiscoveryNode node = clusterService.localNode();
        boolean isClusterStarted = clusterService.lifecycleState().equals(Lifecycle.State.STARTED);

        if (isClusterStarted && node != null && node.isMasterNode()) {
            NodeIndicesStats nodeIndicesStats = indicesService.stats(false);
            CommonStatsFlags commonStatsFlags = new CommonStatsFlags().clear();
            NodeStats nodeStats = nodeService.stats(commonStatsFlags, true, true, true, true, true, true, true, true, true);
            List<IndexShard> indexShards = getIndexShards(indicesService);

            GraphiteReporter graphiteReporter = new GraphiteReporter(graphiteHost, graphitePort, graphitePrefix,
                    nodeIndicesStats, indexShards, nodeStats, graphiteInclusionRegex, graphiteExclusionRegex);
            graphiteReporter.run();
        } else {
            if (node != null) {
                logger.debug("[{}]/[{}] is not master node, not triggering update", node.getId(), node.getName());
            }
        }

        try {
            Thread.sleep(graphiteRefreshInternal.millis());
        } catch (InterruptedException e1) {
            continue;
        }
    }
}
 
Example #7
Source File: IndicesService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) {
    CommonStats oldStats = new CommonStats(flags);

    if (includePrevious) {
        Flag[] setFlags = flags.getFlags();
        for (Flag flag : setFlags) {
            switch (flag) {
                case Get:
                    oldStats.get.add(oldShardsStats.getStats);
                    break;
                case Indexing:
                    oldStats.indexing.add(oldShardsStats.indexingStats);
                    break;
                case Search:
                    oldStats.search.add(oldShardsStats.searchStats);
                    break;
                case Merge:
                    oldStats.merge.add(oldShardsStats.mergeStats);
                    break;
                case Refresh:
                    oldStats.refresh.add(oldShardsStats.refreshStats);
                    break;
                case Recovery:
                    oldStats.recoveryStats.add(oldShardsStats.recoveryStats);
                    break;
                case Flush:
                    oldStats.flush.add(oldShardsStats.flushStats);
                    break;
            }
        }
    }

    Map<Index, List<IndexShardStats>> statsByShard = Maps.newHashMap();
    for (IndexServiceInjectorPair value : indices.values()) {
        IndexService indexService = value.getIndexService();
        for (IndexShard indexShard : indexService) {
            try {
                if (indexShard.routingEntry() == null) {
                    continue;
                }
                IndexShardStats indexShardStats = new IndexShardStats(indexShard.shardId(), new ShardStats[] { new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indexShard, flags), indexShard.commitStats()) });
                if (!statsByShard.containsKey(indexService.index())) {
                    statsByShard.put(indexService.index(), arrayAsArrayList(indexShardStats));
                } else {
                    statsByShard.get(indexService.index()).add(indexShardStats);
                }
            } catch (IllegalIndexShardStateException e) {
                // we can safely ignore illegal state on ones that are closing for example
                logger.trace("{} ignoring shard stats", e, indexShard.shardId());
            }
        }
    }
    return new NodeIndicesStats(oldStats, statsByShard);
}
 
Example #8
Source File: RestNodesStatsAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
    Set<String> metrics = Strings.splitStringByCommaToSet(request.param("metric", "_all"));

    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(nodesIds);
    nodesStatsRequest.timeout(request.param("timeout"));

    if (metrics.size() == 1 && metrics.contains("_all")) {
        nodesStatsRequest.all();
        nodesStatsRequest.indices(CommonStatsFlags.ALL);
    } else {
        nodesStatsRequest.clear();
        nodesStatsRequest.os(metrics.contains("os"));
        nodesStatsRequest.jvm(metrics.contains("jvm"));
        nodesStatsRequest.threadPool(metrics.contains("thread_pool"));
        nodesStatsRequest.fs(metrics.contains("fs"));
        nodesStatsRequest.transport(metrics.contains("transport"));
        nodesStatsRequest.http(metrics.contains("http"));
        nodesStatsRequest.indices(metrics.contains("indices"));
        nodesStatsRequest.process(metrics.contains("process"));
        nodesStatsRequest.breaker(metrics.contains("breaker"));
        nodesStatsRequest.script(metrics.contains("script"));

        // check for index specific metrics
        if (metrics.contains("indices")) {
            Set<String> indexMetrics = Strings.splitStringByCommaToSet(request.param("indexMetric", "_all"));
            if (indexMetrics.size() == 1 && indexMetrics.contains("_all")) {
                nodesStatsRequest.indices(CommonStatsFlags.ALL);
            } else {
                CommonStatsFlags flags = new CommonStatsFlags();
                for (Flag flag : CommonStatsFlags.Flag.values()) {
                    flags.set(flag, indexMetrics.contains(flag.getRestName()));
                }
                nodesStatsRequest.indices(flags);
            }
        }
    }

    if (nodesStatsRequest.indices().isSet(Flag.FieldData) && (request.hasParam("fields") || request.hasParam("fielddata_fields"))) {
        nodesStatsRequest.indices().fieldDataFields(request.paramAsStringArray("fielddata_fields", request.paramAsStringArray("fields", null)));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Completion) && (request.hasParam("fields") || request.hasParam("completion_fields"))) {
        nodesStatsRequest.indices().completionDataFields(request.paramAsStringArray("completion_fields", request.paramAsStringArray("fields", null)));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Search) && (request.hasParam("groups"))) {
        nodesStatsRequest.indices().groups(request.paramAsStringArray("groups", null));
    }
    if (nodesStatsRequest.indices().isSet(Flag.Indexing) && (request.hasParam("types"))) {
        nodesStatsRequest.indices().types(request.paramAsStringArray("types", null));
    }

    client.admin().cluster().nodesStats(nodesStatsRequest, new RestToXContentListener<NodesStatsResponse>(channel));
}
 
Example #9
Source File: NodesStatsRequestBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Should the node indices stats be returned.
 */
public NodesStatsRequestBuilder setIndices(CommonStatsFlags indices) {
    request.indices(indices);
    return this;
}
 
Example #10
Source File: NodesStatsRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public CommonStatsFlags indices() {
    return indices;
}
 
Example #11
Source File: NodesStatsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public NodesStatsRequestBuilder indices(CommonStatsFlags commonStatsFlags) {
    request.indices(commonStatsFlags);
    return this;
}
 
Example #12
Source File: IndicesService.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the node stats indices stats. The <tt>includePrevious</tt> flag controls
 * if old shards stats will be aggregated as well (only for relevant stats, such as
 * refresh and indexing, not for docs/store).
 */
public NodeIndicesStats stats(boolean includePrevious) {
    return stats(includePrevious, new CommonStatsFlags().all());
}