mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-28 10:58:30 +00:00
Node Stats: Add number of docs per node, closes #713.
This commit is contained in:
parent
45ec2c6e21
commit
c6f58321e4
modules/elasticsearch/src/main/java/org/elasticsearch/indices
@ -43,6 +43,7 @@ import org.elasticsearch.index.analysis.AnalysisModule;
|
||||
import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.cache.IndexCache;
|
||||
import org.elasticsearch.index.cache.IndexCacheModule;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.index.engine.IndexEngine;
|
||||
import org.elasticsearch.index.engine.IndexEngineModule;
|
||||
import org.elasticsearch.index.gateway.IndexGateway;
|
||||
@ -54,6 +55,7 @@ import org.elasticsearch.index.query.IndexQueryParserModule;
|
||||
import org.elasticsearch.index.service.IndexService;
|
||||
import org.elasticsearch.index.service.InternalIndexService;
|
||||
import org.elasticsearch.index.settings.IndexSettingsModule;
|
||||
import org.elasticsearch.index.shard.IndexShardState;
|
||||
import org.elasticsearch.index.shard.service.IndexShard;
|
||||
import org.elasticsearch.index.shard.service.InternalIndexShard;
|
||||
import org.elasticsearch.index.similarity.SimilarityModule;
|
||||
@ -159,6 +161,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
|
||||
|
||||
@Override public NodeIndicesStats stats() {
|
||||
long storeTotalSize = 0;
|
||||
long numberOfDocs = 0;
|
||||
long fieldCacheEvictions = 0;
|
||||
long fieldCacheTotalSize = 0;
|
||||
long filterCacheTotalSize = 0;
|
||||
@ -169,12 +172,21 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
if (indexShard.state() == IndexShardState.STARTED) {
|
||||
Engine.Searcher searcher = indexShard.searcher();
|
||||
try {
|
||||
numberOfDocs += searcher.reader().numDocs();
|
||||
} finally {
|
||||
searcher.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldCacheEvictions += indexService.cache().fieldData().evictions();
|
||||
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
|
||||
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
|
||||
}
|
||||
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
|
||||
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), numberOfDocs, new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,8 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
||||
|
||||
private ByteSizeValue storeSize;
|
||||
|
||||
private long numDocs;
|
||||
|
||||
private ByteSizeValue fieldCacheSize;
|
||||
|
||||
private ByteSizeValue filterCacheSize;
|
||||
@ -48,9 +50,10 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
||||
NodeIndicesStats() {
|
||||
}
|
||||
|
||||
public NodeIndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
|
||||
public NodeIndicesStats(ByteSizeValue storeSize, long numDocs, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
|
||||
long fieldCacheEvictions) {
|
||||
this.storeSize = storeSize;
|
||||
this.numDocs = numDocs;
|
||||
this.fieldCacheSize = fieldCacheSize;
|
||||
this.filterCacheSize = filterCacheSize;
|
||||
this.fieldCacheEvictions = fieldCacheEvictions;
|
||||
@ -70,6 +73,20 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
||||
return storeSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of docs on the node (an aggregation of the number of docs of all the shards allocated on the node).
|
||||
*/
|
||||
public long numDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of docs on the node (an aggregation of the number of docs of all the shards allocated on the node).
|
||||
*/
|
||||
public long getNumDocs() {
|
||||
return numDocs();
|
||||
}
|
||||
|
||||
public ByteSizeValue fieldCacheSize() {
|
||||
return this.fieldCacheSize;
|
||||
}
|
||||
@ -102,20 +119,25 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
||||
|
||||
@Override public void readFrom(StreamInput in) throws IOException {
|
||||
storeSize = ByteSizeValue.readBytesSizeValue(in);
|
||||
numDocs = in.readVLong();
|
||||
fieldCacheSize = ByteSizeValue.readBytesSizeValue(in);
|
||||
filterCacheSize = ByteSizeValue.readBytesSizeValue(in);
|
||||
fieldCacheEvictions = in.readVLong();
|
||||
}
|
||||
|
||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||
storeSize.writeTo(out);
|
||||
out.writeVLong(numDocs);
|
||||
fieldCacheSize.writeTo(out);
|
||||
filterCacheSize.writeTo(out);
|
||||
out.writeVLong(fieldCacheEvictions);
|
||||
}
|
||||
|
||||
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(Fields.INDICES);
|
||||
builder.field(Fields.STORE_SIZE, storeSize.toString());
|
||||
builder.field(Fields.STORE_SIZE_IN_BYTES, storeSize.bytes());
|
||||
builder.field(Fields.NUM_DOCS, numDocs);
|
||||
builder.field(Fields.FIELD_CACHE_EVICTIONS, fieldCacheEvictions);
|
||||
builder.field(Fields.FIELD_CACHE_SIZE, fieldCacheSize.toString());
|
||||
builder.field(Fields.FIELD_CACHE_SIZE_IN_BYTES, fieldCacheSize.bytes());
|
||||
@ -129,6 +151,7 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
||||
static final XContentBuilderString INDICES = new XContentBuilderString("indices");
|
||||
static final XContentBuilderString STORE_SIZE = new XContentBuilderString("store_size");
|
||||
static final XContentBuilderString STORE_SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes");
|
||||
static final XContentBuilderString NUM_DOCS = new XContentBuilderString("num_docs");
|
||||
static final XContentBuilderString FIELD_CACHE_SIZE = new XContentBuilderString("field_cache_size");
|
||||
static final XContentBuilderString FIELD_CACHE_SIZE_IN_BYTES = new XContentBuilderString("field_cache_size_in_bytes");
|
||||
static final XContentBuilderString FIELD_CACHE_EVICTIONS = new XContentBuilderString("field_cache_evictions");
|
||||
|
Loading…
x
Reference in New Issue
Block a user