Node Stats API: Change the structure of the response (more structured), closes #746.

This commit is contained in:
kimchy 2011-03-04 00:20:05 +02:00
parent 682ad7e2fc
commit f901429aaa
5 changed files with 213 additions and 66 deletions

View 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);
}
}

View File

@ -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() { public FilterCache filter() {
return filterCache; return filterCache;
} }

View File

@ -23,13 +23,16 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.unit.TimeValue; 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; import java.io.IOException;
/** /**
* *
*/ */
public class MergeStats implements Streamable { public class MergeStats implements Streamable, ToXContent {
private long totalMerges; private long totalMerges;
@ -93,6 +96,24 @@ public class MergeStats implements Streamable {
return stats; 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 { @Override public void readFrom(StreamInput in) throws IOException {
totalMerges = in.readVLong(); totalMerges = in.readVLong();
currentMerges = in.readVLong(); currentMerges = in.readVLong();

View File

@ -41,6 +41,7 @@ import org.elasticsearch.gateway.Gateway;
import org.elasticsearch.index.*; import org.elasticsearch.index.*;
import org.elasticsearch.index.analysis.AnalysisModule; import org.elasticsearch.index.analysis.AnalysisModule;
import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.cache.CacheStats;
import org.elasticsearch.index.cache.IndexCache; import org.elasticsearch.index.cache.IndexCache;
import org.elasticsearch.index.cache.IndexCacheModule; import org.elasticsearch.index.cache.IndexCacheModule;
import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.engine.Engine;
@ -163,9 +164,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
@Override public NodeIndicesStats stats() { @Override public NodeIndicesStats stats() {
long storeTotalSize = 0; long storeTotalSize = 0;
long numberOfDocs = 0; long numberOfDocs = 0;
long fieldCacheEvictions = 0; CacheStats cacheStats = new CacheStats();
long fieldCacheTotalSize = 0;
long filterCacheTotalSize = 0;
MergeStats mergeStats = new MergeStats(); MergeStats mergeStats = new MergeStats();
for (IndexService indexService : indices.values()) { for (IndexService indexService : indices.values()) {
for (IndexShard indexShard : indexService) { for (IndexShard indexShard : indexService) {
@ -185,11 +184,9 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
} }
mergeStats.add(((InternalIndexShard) indexShard).mergeScheduler().stats()); mergeStats.add(((InternalIndexShard) indexShard).mergeScheduler().stats());
} }
fieldCacheEvictions += indexService.cache().fieldData().evictions(); cacheStats.add(indexService.cache().stats());
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
} }
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), numberOfDocs, new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions, mergeStats); return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), numberOfDocs, cacheStats, mergeStats);
} }
/** /**

View File

@ -26,6 +26,7 @@ import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.index.cache.CacheStats;
import org.elasticsearch.index.merge.MergeStats; import org.elasticsearch.index.merge.MergeStats;
import java.io.IOException; import java.io.IOException;
@ -42,24 +43,17 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
private long numDocs; private long numDocs;
private ByteSizeValue fieldCacheSize; private CacheStats cacheStats;
private ByteSizeValue filterCacheSize;
private long fieldCacheEvictions;
private MergeStats mergeStats; private MergeStats mergeStats;
NodeIndicesStats() { NodeIndicesStats() {
} }
public NodeIndicesStats(ByteSizeValue storeSize, long numDocs, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize, public NodeIndicesStats(ByteSizeValue storeSize, long numDocs, CacheStats cacheStats, MergeStats mergeStats) {
long fieldCacheEvictions, MergeStats mergeStats) {
this.storeSize = storeSize; this.storeSize = storeSize;
this.numDocs = numDocs; this.numDocs = numDocs;
this.fieldCacheSize = fieldCacheSize; this.cacheStats = cacheStats;
this.filterCacheSize = filterCacheSize;
this.fieldCacheEvictions = fieldCacheEvictions;
this.mergeStats = mergeStats; this.mergeStats = mergeStats;
} }
@ -91,35 +85,19 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
return numDocs(); return numDocs();
} }
public ByteSizeValue fieldCacheSize() { public CacheStats cache() {
return this.fieldCacheSize; return this.cacheStats;
} }
public ByteSizeValue getFieldCacheSize() { public CacheStats getCache() {
return this.fieldCacheSize; return this.cache();
} }
public ByteSizeValue filterCacheSize() { public MergeStats merge() {
return this.filterCacheSize;
}
public ByteSizeValue getFilterCacheSize() {
return this.filterCacheSize;
}
public long fieldCacheEvictions() {
return this.fieldCacheEvictions;
}
public long getFieldCacheEvictions() {
return fieldCacheEvictions();
}
public MergeStats mergeStats() {
return this.mergeStats; return this.mergeStats;
} }
public MergeStats getMergeStats() { public MergeStats getMerge() {
return this.mergeStats; return this.mergeStats;
} }
@ -132,53 +110,46 @@ public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
@Override public void readFrom(StreamInput in) throws IOException { @Override public void readFrom(StreamInput in) throws IOException {
storeSize = ByteSizeValue.readBytesSizeValue(in); storeSize = ByteSizeValue.readBytesSizeValue(in);
numDocs = in.readVLong(); numDocs = in.readVLong();
fieldCacheSize = ByteSizeValue.readBytesSizeValue(in); cacheStats = CacheStats.readCacheStats(in);
filterCacheSize = ByteSizeValue.readBytesSizeValue(in);
fieldCacheEvictions = in.readVLong();
mergeStats = MergeStats.readMergeStats(in); mergeStats = MergeStats.readMergeStats(in);
} }
@Override public void writeTo(StreamOutput out) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException {
storeSize.writeTo(out); storeSize.writeTo(out);
out.writeVLong(numDocs); out.writeVLong(numDocs);
fieldCacheSize.writeTo(out); cacheStats.writeTo(out);
filterCacheSize.writeTo(out);
out.writeVLong(fieldCacheEvictions);
mergeStats.writeTo(out); mergeStats.writeTo(out);
} }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.INDICES); 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.startObject(Fields.STORE);
builder.field(Fields.CURRENT, mergeStats.currentMerges()); builder.field(Fields.SIZE, storeSize.toString());
builder.field(Fields.TOTAL, mergeStats.totalMerges()); builder.field(Fields.SIZE_IN_BYTES, storeSize.bytes());
builder.field(Fields.TOTAL_TIME, mergeStats.totalMergeTime());
builder.field(Fields.TOTAL_TIME_IN_MILLIS, mergeStats.totalMergeTimeInMillis());
builder.endObject(); builder.endObject();
builder.startObject(Fields.DOCS);
builder.field(Fields.NUM_DOCS, numDocs);
builder.endObject();
cacheStats.toXContent(builder, params);
mergeStats.toXContent(builder, params);
builder.endObject(); builder.endObject();
return builder; return builder;
} }
static final class Fields { static final class Fields {
static final XContentBuilderString INDICES = new XContentBuilderString("indices"); 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 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 MERGES = new XContentBuilderString("merges");
static final XContentBuilderString CURRENT = new XContentBuilderString("current"); static final XContentBuilderString CURRENT = new XContentBuilderString("current");
static final XContentBuilderString TOTAL = new XContentBuilderString("total"); static final XContentBuilderString TOTAL = new XContentBuilderString("total");