Add info to _cat/nodes, add _cat/indices.

This commit is contained in:
Andrew Raines 2013-07-15 15:28:38 -05:00
parent c3038889f9
commit 092fd6fc7a
5 changed files with 190 additions and 8 deletions

2
.gitignore vendored
View File

@ -22,3 +22,5 @@ target/
## netbeans ignores ## netbeans ignores
nb-configuration.xml nb-configuration.xml
nbactions.xml nbactions.xml
/dependency-reduced-pom.xml

View File

@ -67,6 +67,7 @@ import org.elasticsearch.rest.action.admin.indices.warmer.delete.RestDeleteWarme
import org.elasticsearch.rest.action.admin.indices.warmer.get.RestGetWarmerAction; import org.elasticsearch.rest.action.admin.indices.warmer.get.RestGetWarmerAction;
import org.elasticsearch.rest.action.admin.indices.warmer.put.RestPutWarmerAction; import org.elasticsearch.rest.action.admin.indices.warmer.put.RestPutWarmerAction;
import org.elasticsearch.rest.action.bulk.RestBulkAction; import org.elasticsearch.rest.action.bulk.RestBulkAction;
import org.elasticsearch.rest.action.cat.RestIndicesAction;
import org.elasticsearch.rest.action.cat.RestMasterAction; import org.elasticsearch.rest.action.cat.RestMasterAction;
import org.elasticsearch.rest.action.cat.RestNodesAction; import org.elasticsearch.rest.action.cat.RestNodesAction;
import org.elasticsearch.rest.action.cat.RestShardsAction; import org.elasticsearch.rest.action.cat.RestShardsAction;
@ -187,5 +188,6 @@ public class RestActionModule extends AbstractModule {
bind(RestShardsAction.class).asEagerSingleton(); bind(RestShardsAction.class).asEagerSingleton();
bind(RestMasterAction.class).asEagerSingleton(); bind(RestMasterAction.class).asEagerSingleton();
bind(RestNodesAction.class).asEagerSingleton(); bind(RestNodesAction.class).asEagerSingleton();
bind(RestIndicesAction.class).asEagerSingleton();
} }
} }

View File

@ -0,0 +1,151 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.rest.action.cat;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterIndexHealth;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.action.support.RestActions.splitIndices;
public class RestIndicesAction extends BaseRestHandler {
@Inject
public RestIndicesAction(Settings settings, Client client, RestController controller) {
super(settings, client);
controller.registerHandler(GET, "/_cat/indices", this);
controller.registerHandler(GET, "/_cat/indices/{index}", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel) {
final String[] indices = splitIndices(request.param("index"));
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.filterMetaData(true).filteredIndices(indices);
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
client.admin().cluster().state(clusterStateRequest, new ActionListener<ClusterStateResponse>() {
@Override
public void onResponse(final ClusterStateResponse clusterStateResponse) {
ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices);
clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
clusterHealthRequest.indices(indices);
client.admin().cluster().health(clusterHealthRequest, new ActionListener<ClusterHealthResponse>() {
@Override
public void onResponse(final ClusterHealthResponse clusterHealthResponse) {
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.clear().store(true).docs(true);
client.admin().indices().stats(indicesStatsRequest, new ActionListener<IndicesStatsResponse>() {
@Override
public void onResponse(IndicesStatsResponse indicesStatsResponse) {
try {
channel.sendResponse(RestTable.buildResponse(buildTable(clusterStateResponse, clusterHealthResponse, indicesStatsResponse), request, channel));
} catch (Throwable e) {
onFailure(e);
}
}
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
}
});
}
private Table buildTable(ClusterStateResponse state, ClusterHealthResponse health, IndicesStatsResponse stats) {
Table table = new Table();
table.startHeaders();
table.addCell("health");
table.addCell("index");
table.addCell("pri", "text-align:right;");
table.addCell("rep", "text-align:right;");
table.addCell("docs", "text-align:right;");
table.addCell("docs/del", "text-align:right;");
table.addCell("size/pri", "text-align:right;");
table.addCell("size/total", "text-align:right;");
table.endHeaders();
for (Map.Entry entry : state.getState().routingTable().indicesRouting().entrySet()) {
String index = (String) entry.getKey();
ClusterIndexHealth indexHealth = health.getIndices().get(index);
IndexStats indexStats = stats.getIndices().get(index);
table.startRow();
table.addCell(indexHealth == null ? "red*" : indexHealth.getStatus().toString().toLowerCase(Locale.getDefault()));
table.addCell(index);
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfShards());
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfReplicas());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getDeleted());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getStore().size());
table.addCell(indexStats == null ? null : indexStats.getTotal().getStore().size());
table.endRow();
}
return table;
}
}

View File

@ -34,10 +34,13 @@ import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.monitor.fs.FsStats;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestTable; import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.GET;
@ -60,12 +63,12 @@ public class RestNodesAction extends BaseRestHandler {
@Override @Override
public void onResponse(final ClusterStateResponse clusterStateResponse) { public void onResponse(final ClusterStateResponse clusterStateResponse) {
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
nodesInfoRequest.clear().jvm(true).os(true); nodesInfoRequest.clear().jvm(true).os(true).process(true);
client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() { client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
@Override @Override
public void onResponse(final NodesInfoResponse nodesInfoResponse) { public void onResponse(final NodesInfoResponse nodesInfoResponse) {
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(); NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
nodesStatsRequest.clear().jvm(true); nodesStatsRequest.clear().jvm(true).fs(true);
client.admin().cluster().nodesStats(nodesStatsRequest, new ActionListener<NodesStatsResponse>() { client.admin().cluster().nodesStats(nodesStatsRequest, new ActionListener<NodesStatsResponse>() {
@Override @Override
public void onResponse(NodesStatsResponse nodesStatsResponse) { public void onResponse(NodesStatsResponse nodesStatsResponse) {
@ -109,14 +112,17 @@ public class RestNodesAction extends BaseRestHandler {
} }
private Table buildTable(ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) { private Table buildTable(ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
String masterId = state.getState().nodes().masterNodeId();
Table table = new Table(); Table table = new Table();
table.startHeaders(); table.startHeaders();
table.addCell("id"); table.addCell("id");
table.addCell("pid");
table.addCell("ip"); table.addCell("ip");
table.addCell("port"); table.addCell("port");
// Considering supporting params like jvm, os, http to turn various columns on/off
table.addCell("jdk"); table.addCell("jdk");
table.addCell("diskfree", "text-align:right;");
table.addCell("heapmax", "text-align:right;"); table.addCell("heapmax", "text-align:right;");
table.addCell("memmax", "text-align:right;"); table.addCell("memmax", "text-align:right;");
@ -127,16 +133,26 @@ public class RestNodesAction extends BaseRestHandler {
table.endHeaders(); table.endHeaders();
for (DiscoveryNode node : state.getState().nodes()) { for (DiscoveryNode node : state.getState().nodes()) {
String masterId = state.getState().nodes().masterNodeId();
NodeInfo info = nodesInfo.getNodesMap().get(node.id()); NodeInfo info = nodesInfo.getNodesMap().get(node.id());
NodeStats stats = nodesStats.getNodesMap().get(node.id()); NodeStats stats = nodesStats.getNodesMap().get(node.id());
long availableDisk = -1;
if (!(stats.getFs() == null)) {
availableDisk = 0;
Iterator<FsStats.Info> it = stats.getFs().iterator();
while (it.hasNext()) {
availableDisk += it.next().getAvailable().bytes();
}
}
table.startRow(); table.startRow();
table.addCell(node.id()); table.addCell(node.id());
table.addCell(info.getProcess().id());
table.addCell(((InetSocketTransportAddress) node.address()).address().getAddress().getHostAddress()); table.addCell(((InetSocketTransportAddress) node.address()).address().getAddress().getHostAddress());
table.addCell(((InetSocketTransportAddress) node.address()).address().getPort()); table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
table.addCell(info.getJvm().version()); table.addCell(info.getJvm().version());
table.addCell(availableDisk < 0 ? null : ByteSizeValue.parseBytesSizeValue(new Long(availableDisk).toString()));
table.addCell(info.getJvm().mem().heapMax()); table.addCell(info.getJvm().mem().heapMax());
table.addCell(info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ table.addCell(info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ
table.addCell(stats.getJvm().uptime()); table.addCell(stats.getJvm().uptime());

View File

@ -97,8 +97,8 @@ public class RestShardsAction extends BaseRestHandler {
.addCell("shard", "default:true;") .addCell("shard", "default:true;")
.addCell("p/r", "default:true;") .addCell("p/r", "default:true;")
.addCell("state", "default:true;") .addCell("state", "default:true;")
.addCell("docs", "default:true;") .addCell("docs", "text-align:right;")
.addCell("store", "default:true;") .addCell("store", "text-align:right;")
.addCell("ip", "default:true;") .addCell("ip", "default:true;")
.addCell("node", "default:true;") .addCell("node", "default:true;")
.endHeaders(); .endHeaders();
@ -115,8 +115,19 @@ public class RestShardsAction extends BaseRestHandler {
table.addCell(shardStats == null ? null : shardStats.getDocs().getCount()); table.addCell(shardStats == null ? null : shardStats.getDocs().getCount());
table.addCell(shardStats == null ? null : shardStats.getStore().getSize()); table.addCell(shardStats == null ? null : shardStats.getStore().getSize());
if (shard.assignedToNode()) { if (shard.assignedToNode()) {
table.addCell(((InetSocketTransportAddress) state.getState().nodes().get(shard.currentNodeId()).address()).address().getAddress().getHostAddress()); String ip = ((InetSocketTransportAddress) state.getState().nodes().get(shard.currentNodeId()).address()).address().getAddress().getHostAddress();
table.addCell(state.getState().nodes().get(shard.currentNodeId()).name()); StringBuilder name = new StringBuilder();
name.append(state.getState().nodes().get(shard.currentNodeId()).name());
if (shard.relocating()) {
String reloIp = ((InetSocketTransportAddress) state.getState().nodes().get(shard.relocatingNodeId()).address()).address().getAddress().getHostAddress();
String reloNme = state.getState().nodes().get(shard.relocatingNodeId()).name();
name.append(" -> ");
name.append(reloIp);
name.append(" ");
name.append(reloNme);
}
table.addCell(ip);
table.addCell(name);
} else { } else {
table.addCell(null); table.addCell(null);
table.addCell(null); table.addCell(null);