Index Status: Add primary store size to include only primary shards store sizes, also move index store and translog into their own elements, closes #666.

This commit is contained in:
kimchy 2011-02-03 00:50:24 +02:00
parent 13869239b0
commit 5fe2615ba7
7 changed files with 92 additions and 18 deletions

View File

@ -23,7 +23,7 @@ import org.elasticsearch.action.support.nodes.NodeOperationResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.indices.IndicesStats;
import org.elasticsearch.indices.NodeIndicesStats;
import org.elasticsearch.monitor.jvm.JvmStats;
import org.elasticsearch.monitor.network.NetworkStats;
import org.elasticsearch.monitor.os.OsStats;
@ -40,7 +40,7 @@ import java.io.IOException;
*/
public class NodeStats extends NodeOperationResponse {
private IndicesStats indices;
private NodeIndicesStats indices;
private OsStats os;
@ -57,7 +57,7 @@ public class NodeStats extends NodeOperationResponse {
NodeStats() {
}
public NodeStats(DiscoveryNode node, IndicesStats indices,
public NodeStats(DiscoveryNode node, NodeIndicesStats indices,
OsStats os, ProcessStats process, JvmStats jvm, NetworkStats network,
ThreadPoolStats threadPool, TransportStats transport) {
super(node);
@ -73,14 +73,14 @@ public class NodeStats extends NodeOperationResponse {
/**
* Indices level stats.
*/
public IndicesStats indices() {
public NodeIndicesStats indices() {
return this.indices;
}
/**
* Indices level stats.
*/
public IndicesStats getIndices() {
public NodeIndicesStats getIndices() {
return indices();
}
@ -171,7 +171,7 @@ public class NodeStats extends NodeOperationResponse {
@Override public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
indices = IndicesStats.readIndicesStats(in);
indices = NodeIndicesStats.readIndicesStats(in);
}
if (in.readBoolean()) {
os = OsStats.readOsStats(in);

View File

@ -59,6 +59,39 @@ public class IndexShardStatus implements Iterable<ShardStatus> {
return shards[position];
}
/**
* Returns only the primary shards store size in bytes.
*/
public ByteSizeValue primaryStoreSize() {
long bytes = -1;
for (ShardStatus shard : shards()) {
if (!shard.shardRouting().primary()) {
// only sum docs for the primaries
continue;
}
if (shard.storeSize() != null) {
if (bytes == -1) {
bytes = 0;
}
bytes += shard.storeSize().bytes();
}
}
if (bytes == -1) {
return null;
}
return new ByteSizeValue(bytes);
}
/**
* Returns only the primary shards store size in bytes.
*/
public ByteSizeValue getPrimaryStoreSize() {
return primaryStoreSize();
}
/**
* Returns the full store size in bytes, of both primaries and replicas.
*/
public ByteSizeValue storeSize() {
long bytes = -1;
for (ShardStatus shard : shards()) {
@ -75,6 +108,9 @@ public class IndexShardStatus implements Iterable<ShardStatus> {
return new ByteSizeValue(bytes);
}
/**
* Returns the full store size in bytes, of both primaries and replicas.
*/
public ByteSizeValue getStoreSize() {
return storeSize();
}

View File

@ -87,6 +87,35 @@ public class IndexStatus implements Iterable<IndexShardStatus> {
return settings();
}
/**
* Returns only the primary shards store size in bytes.
*/
public ByteSizeValue primaryStoreSize() {
long bytes = -1;
for (IndexShardStatus shard : this) {
if (shard.primaryStoreSize() != null) {
if (bytes == -1) {
bytes = 0;
}
bytes += shard.primaryStoreSize().bytes();
}
}
if (bytes == -1) {
return null;
}
return new ByteSizeValue(bytes);
}
/**
* Returns only the primary shards store size in bytes.
*/
public ByteSizeValue getPrimaryStoreSize() {
return primaryStoreSize();
}
/**
* Returns the full store size in bytes, of both primaries and replicas.
*/
public ByteSizeValue storeSize() {
long bytes = -1;
for (IndexShardStatus shard : this) {
@ -103,6 +132,9 @@ public class IndexStatus implements Iterable<IndexShardStatus> {
return new ByteSizeValue(bytes);
}
/**
* Returns the full store size in bytes, of both primaries and replicas.
*/
public ByteSizeValue getStoreSize() {
return storeSize();
}

View File

@ -38,7 +38,7 @@ public interface IndicesService extends Iterable<IndexService>, LifecycleCompone
*/
public boolean changesAllowed();
IndicesStats stats();
NodeIndicesStats stats();
boolean hasIndex(String index);

View File

@ -157,7 +157,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
return this.indicesLifecycle;
}
@Override public IndicesStats stats() {
@Override public NodeIndicesStats stats() {
long storeTotalSize = 0;
long fieldCacheEvictions = 0;
long fieldCacheTotalSize = 0;
@ -174,7 +174,7 @@ public class InternalIndicesService extends AbstractLifecycleComponent<IndicesSe
fieldCacheTotalSize += indexService.cache().fieldData().sizeInBytes();
filterCacheTotalSize += indexService.cache().filter().sizeInBytes();
}
return new IndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
return new NodeIndicesStats(new ByteSizeValue(storeTotalSize), new ByteSizeValue(fieldCacheTotalSize), new ByteSizeValue(filterCacheTotalSize), fieldCacheEvictions);
}
/**

View File

@ -35,7 +35,7 @@ import java.io.Serializable;
*
* @author kimchy (shay.banon)
*/
public class IndicesStats implements Streamable, Serializable, ToXContent {
public class NodeIndicesStats implements Streamable, Serializable, ToXContent {
private ByteSizeValue storeSize;
@ -45,11 +45,11 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
private long fieldCacheEvictions;
IndicesStats() {
NodeIndicesStats() {
}
public IndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
long fieldCacheEvictions) {
public NodeIndicesStats(ByteSizeValue storeSize, ByteSizeValue fieldCacheSize, ByteSizeValue filterCacheSize,
long fieldCacheEvictions) {
this.storeSize = storeSize;
this.fieldCacheSize = fieldCacheSize;
this.filterCacheSize = filterCacheSize;
@ -94,8 +94,8 @@ public class IndicesStats implements Streamable, Serializable, ToXContent {
return fieldCacheEvictions();
}
public static IndicesStats readIndicesStats(StreamInput in) throws IOException {
IndicesStats stats = new IndicesStats();
public static NodeIndicesStats readIndicesStats(StreamInput in) throws IOException {
NodeIndicesStats stats = new NodeIndicesStats();
stats.readFrom(in);
return stats;
}

View File

@ -85,12 +85,18 @@ public class RestIndicesStatusAction extends BaseRestHandler {
}
builder.endObject();
builder.startObject("index");
if (indexStatus.storeSize() != null) {
builder.field("store_size", indexStatus.storeSize().toString());
builder.field("store_size_in_bytes", indexStatus.storeSize().bytes());
builder.field("primary_size", indexStatus.primaryStoreSize().toString());
builder.field("primary_size_in_bytes", indexStatus.primaryStoreSize().bytes());
builder.field("size", indexStatus.storeSize().toString());
builder.field("size_in_bytes", indexStatus.storeSize().bytes());
}
builder.endObject();
if (indexStatus.translogOperations() != -1) {
builder.field("translog_operations", indexStatus.translogOperations());
builder.startObject("translog");
builder.field("operations", indexStatus.translogOperations());
builder.endObject();
}
if (indexStatus.docs() != null) {