From f901429aaa1030fe1b51d5fd8b1786bf1e6398eb Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 4 Mar 2011 00:20:05 +0200 Subject: [PATCH] Node Stats API: Change the structure of the response (more structured), closes #746. --- .../elasticsearch/index/cache/CacheStats.java | 154 ++++++++++++++++++ .../elasticsearch/index/cache/IndexCache.java | 4 + .../elasticsearch/index/merge/MergeStats.java | 23 ++- .../indices/InternalIndicesService.java | 11 +- .../indices/NodeIndicesStats.java | 87 ++++------ 5 files changed, 213 insertions(+), 66 deletions(-) create mode 100644 modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java new file mode 100644 index 00000000000..85f5daedc69 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/CacheStats.java @@ -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); + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java index e57db9846d8..3eec0c02988 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -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; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/merge/MergeStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/merge/MergeStats.java index 6c20ca794d8..7b57e86299a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/merge/MergeStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/merge/MergeStats.java @@ -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(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java index f5823a21c4a..08b27a2c582 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesService.java @@ -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