Node Stats API: Change the structure of the response (more structured), closes #746.
This commit is contained in:
parent
682ad7e2fc
commit
f901429aaa
154
modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java
vendored
Normal file
154
modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.cache;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CacheStats implements Streamable, ToXContent {
|
||||
|
||||
long fieldEvictions;
|
||||
long fieldSize = 0;
|
||||
long filterSize = 0;
|
||||
long bloomSize = 0;
|
||||
|
||||
public CacheStats() {
|
||||
}
|
||||
|
||||
public CacheStats(long fieldEvictions, long fieldSize, long filterSize, long bloomSize) {
|
||||
this.fieldEvictions = fieldEvictions;
|
||||
this.fieldSize = fieldSize;
|
||||
this.filterSize = filterSize;
|
||||
this.bloomSize = bloomSize;
|
||||
}
|
||||
|
||||
public void add(CacheStats stats) {
|
||||
this.fieldEvictions += stats.fieldEvictions;
|
||||
this.fieldSize += stats.fieldSize;
|
||||
this.filterSize += stats.filterSize;
|
||||
this.bloomSize += stats.bloomSize;
|
||||
}
|
||||
|
||||
public long fieldEvictions() {
|
||||
return this.fieldEvictions;
|
||||
}
|
||||
|
||||
public long getFieldEvictions() {
|
||||
return this.fieldEvictions();
|
||||
}
|
||||
|
||||
public long fieldSizeInBytes() {
|
||||
return this.fieldSize;
|
||||
}
|
||||
|
||||
public long getFieldSizeInBytes() {
|
||||
return fieldSizeInBytes();
|
||||
}
|
||||
|
||||
public ByteSizeValue fieldSize() {
|
||||
return new ByteSizeValue(fieldSize);
|
||||
}
|
||||
|
||||
public ByteSizeValue getFieldSize() {
|
||||
return this.fieldSize();
|
||||
}
|
||||
|
||||
public long filterSizeInBytes() {
|
||||
return this.filterSize;
|
||||
}
|
||||
|
||||
public long getFilterSizeInBytes() {
|
||||
return this.filterSizeInBytes();
|
||||
}
|
||||
|
||||
public ByteSizeValue filterSize() {
|
||||
return new ByteSizeValue(filterSize);
|
||||
}
|
||||
|
||||
public ByteSizeValue getFilterSize() {
|
||||
return filterSize();
|
||||
}
|
||||
|
||||
public long bloomSizeInBytes() {
|
||||
return this.bloomSize;
|
||||
}
|
||||
|
||||
public long getBloomSizeInBytes() {
|
||||
return this.bloomSize;
|
||||
}
|
||||
|
||||
public ByteSizeValue bloomSize() {
|
||||
return new ByteSizeValue(bloomSize);
|
||||
}
|
||||
|
||||
public ByteSizeValue getBloomSize() {
|
||||
return bloomSize();
|
||||
}
|
||||
|
||||
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(Fields.CACHE);
|
||||
builder.field(Fields.FIELD_EVICTIONS, fieldEvictions);
|
||||
builder.field(Fields.FIELD_SIZE, fieldSize().toString());
|
||||
builder.field(Fields.FIELD_SIZE_IN_BYTES, fieldSize);
|
||||
builder.field(Fields.FILTER_SIZE, filterSize().toString());
|
||||
builder.field(Fields.FILTER_SIZE_IN_BYTES, filterSize);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString CACHE = new XContentBuilderString("cache");
|
||||
static final XContentBuilderString FIELD_SIZE = new XContentBuilderString("field_size");
|
||||
static final XContentBuilderString FIELD_SIZE_IN_BYTES = new XContentBuilderString("field_size_in_bytes");
|
||||
static final XContentBuilderString FIELD_EVICTIONS = new XContentBuilderString("field_evictions");
|
||||
static final XContentBuilderString FILTER_SIZE = new XContentBuilderString("filter_size");
|
||||
static final XContentBuilderString FILTER_SIZE_IN_BYTES = new XContentBuilderString("filter_size_in_bytes");
|
||||
}
|
||||
|
||||
public static CacheStats readCacheStats(StreamInput in) throws IOException {
|
||||
CacheStats stats = new CacheStats();
|
||||
stats.readFrom(in);
|
||||
return stats;
|
||||
}
|
||||
|
||||
@Override public void readFrom(StreamInput in) throws IOException {
|
||||
fieldEvictions = in.readVLong();
|
||||
fieldSize = in.readVLong();
|
||||
filterSize = in.readVLong();
|
||||
bloomSize = in.readVLong();
|
||||
}
|
||||
|
||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeVLong(fieldEvictions);
|
||||
out.writeVLong(fieldSize);
|
||||
out.writeVLong(filterSize);
|
||||
out.writeVLong(bloomSize);
|
||||
}
|
||||
}
|
|
@ -72,6 +72,10 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo
|
|||
}
|
||||
}
|
||||
|
||||
public CacheStats stats() {
|
||||
return new CacheStats(fieldDataCache.evictions(), fieldDataCache.sizeInBytes(), filterCache.sizeInBytes(), bloomCache.sizeInBytes());
|
||||
}
|
||||
|
||||
public FilterCache filter() {
|
||||
return filterCache;
|
||||
}
|
||||
|
|
|
@ -23,13 +23,16 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MergeStats implements Streamable {
|
||||
public class MergeStats implements Streamable, ToXContent {
|
||||
|
||||
private long totalMerges;
|
||||
|
||||
|
@ -93,6 +96,24 @@ public class MergeStats implements Streamable {
|
|||
return stats;
|
||||
}
|
||||
|
||||
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(Fields.MERGES);
|
||||
builder.field(Fields.CURRENT, currentMerges);
|
||||
builder.field(Fields.TOTAL, totalMerges);
|
||||
builder.field(Fields.TOTAL_TIME, totalMergeTime().toString());
|
||||
builder.field(Fields.TOTAL_TIME_IN_MILLIS, totalMergeTime);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
static final XContentBuilderString MERGES = new XContentBuilderString("merges");
|
||||
static final XContentBuilderString CURRENT = new XContentBuilderString("current");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time");
|
||||
static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis");
|
||||
}
|
||||
|
||||
@Override public void readFrom(StreamInput in) throws IOException {
|
||||
totalMerges = in.readVLong();
|
||||
currentMerges = in.readVLong();
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.elasticsearch.gateway.Gateway;
|
|||
import org.elasticsearch.index.*;
|
||||
import org.elasticsearch.index.analysis.AnalysisModule;
|
||||
import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.cache.CacheStats;
|
||||
import org.elasticsearch.index.cache.IndexCache;
|
||||
import org.elasticsearch.index.cache.IndexCacheModule;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
|
@ -163,9 +164,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;
|
||||
CacheStats cacheStats = new CacheStats();
|
||||
MergeStats mergeStats = new MergeStats();
|
||||
for (IndexService indexService : indices.values()) {
|
||||
for (IndexShard indexShard : indexService) {
|
||||
|
@ -185,11 +184,9 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
|
|||
}
|
||||
mergeStats.add(((InternalIndexShard) indexShard).mergeScheduler().stats());
|
||||
}
|
||||
fieldCacheEvictions += indexService.cache().fieldData().evictions();
|
||||
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
|
||||
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
|
||||
cacheStats.add(indexService.cache().stats());
|
||||
}
|
||||
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), numberOfDocs, new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions, mergeStats);
|
||||
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), numberOfDocs, cacheStats, mergeStats);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.index.cache.CacheStats;
|
||||
import org.elasticsearch.index.merge.MergeStats;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,24 +43,17 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
|||
|
||||
private long numDocs;
|
||||
|
||||
private ByteSizeValue fieldCacheSize;
|
||||
|
||||
private ByteSizeValue filterCacheSize;
|
||||
|
||||
private long fieldCacheEvictions;
|
||||
private CacheStats cacheStats;
|
||||
|
||||
private MergeStats mergeStats;
|
||||
|
||||
NodeIndicesStats() {
|
||||
}
|
||||
|
||||
public NodeIndicesStats(ByteSizeValue storeSize, long numDocs, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
|
||||
long fieldCacheEvictions, MergeStats mergeStats) {
|
||||
public NodeIndicesStats(ByteSizeValue storeSize, long numDocs, CacheStats cacheStats, MergeStats mergeStats) {
|
||||
this.storeSize = storeSize;
|
||||
this.numDocs = numDocs;
|
||||
this.fieldCacheSize = fieldCacheSize;
|
||||
this.filterCacheSize = filterCacheSize;
|
||||
this.fieldCacheEvictions = fieldCacheEvictions;
|
||||
this.cacheStats = cacheStats;
|
||||
this.mergeStats = mergeStats;
|
||||
}
|
||||
|
||||
|
@ -91,35 +85,19 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
|
|||
return numDocs();
|
||||
}
|
||||
|
||||
public ByteSizeValue fieldCacheSize() {
|
||||
return this.fieldCacheSize;
|
||||
public CacheStats cache() {
|
||||
return this.cacheStats;
|
||||
}
|
||||
|
||||
public ByteSizeValue getFieldCacheSize() {
|
||||
return this.fieldCacheSize;
|
||||
public CacheStats getCache() {
|
||||
return this.cache();
|
||||
}
|
||||
|
||||
public ByteSizeValue filterCacheSize() {
|
||||
return this.filterCacheSize;
|
||||
}
|
||||
|
||||
public ByteSizeValue getFilterCacheSize() {
|
||||
return this.filterCacheSize;
|
||||
}
|
||||
|
||||
public long fieldCacheEvictions() {
|
||||
return this.fieldCacheEvictions;
|
||||
}
|
||||
|
||||
public long getFieldCacheEvictions() {
|
||||
return fieldCacheEvictions();
|
||||
}
|
||||
|
||||
public MergeStats mergeStats() {
|
||||
public MergeStats merge() {
|
||||
return this.mergeStats;
|
||||
}
|
||||
|
||||
public MergeStats getMergeStats() {
|
||||
public MergeStats getMerge() {
|
||||
return this.mergeStats;
|
||||
}
|
||||
|
||||
|
@ -132,53 +110,46 @@ 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();
|
||||
cacheStats = CacheStats.readCacheStats(in);
|
||||
mergeStats = MergeStats.readMergeStats(in);
|
||||
}
|
||||
|
||||
@Override public void writeTo(StreamOutput out) throws IOException {
|
||||
storeSize.writeTo(out);
|
||||
out.writeVLong(numDocs);
|
||||
fieldCacheSize.writeTo(out);
|
||||
filterCacheSize.writeTo(out);
|
||||
out.writeVLong(fieldCacheEvictions);
|
||||
cacheStats.writeTo(out);
|
||||
mergeStats.writeTo(out);
|
||||
}
|
||||
|
||||
@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());
|
||||
builder.field(Fields.FILTER_CACHE_SIZE, filterCacheSize.toString());
|
||||
builder.field(Fields.FILTER_CACHE_SIZE_IN_BYTES, filterCacheSize.bytes());
|
||||
|
||||
builder.startObject(Fields.MERGES);
|
||||
builder.field(Fields.CURRENT, mergeStats.currentMerges());
|
||||
builder.field(Fields.TOTAL, mergeStats.totalMerges());
|
||||
builder.field(Fields.TOTAL_TIME, mergeStats.totalMergeTime());
|
||||
builder.field(Fields.TOTAL_TIME_IN_MILLIS, mergeStats.totalMergeTimeInMillis());
|
||||
builder.startObject(Fields.STORE);
|
||||
builder.field(Fields.SIZE, storeSize.toString());
|
||||
builder.field(Fields.SIZE_IN_BYTES, storeSize.bytes());
|
||||
builder.endObject();
|
||||
|
||||
builder.startObject(Fields.DOCS);
|
||||
builder.field(Fields.NUM_DOCS, numDocs);
|
||||
builder.endObject();
|
||||
|
||||
cacheStats.toXContent(builder, params);
|
||||
mergeStats.toXContent(builder, params);
|
||||
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
static final class Fields {
|
||||
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 STORE = new XContentBuilderString("store");
|
||||
static final XContentBuilderString SIZE = new XContentBuilderString("store_size");
|
||||
static final XContentBuilderString SIZE_IN_BYTES = new XContentBuilderString("store_size_in_bytes");
|
||||
|
||||
static final XContentBuilderString DOCS = new XContentBuilderString("docs");
|
||||
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");
|
||||
static final XContentBuilderString FILTER_CACHE_SIZE = new XContentBuilderString("filter_cache_size");
|
||||
static final XContentBuilderString FILTER_CACHE_SIZE_IN_BYTES = new XContentBuilderString("filter_cache_size_in_bytes");
|
||||
|
||||
static final XContentBuilderString MERGES = new XContentBuilderString("merges");
|
||||
static final XContentBuilderString CURRENT = new XContentBuilderString("current");
|
||||
static final XContentBuilderString TOTAL = new XContentBuilderString("total");
|
||||
|
|
Loading…
Reference in New Issue