Merge pull request #16770 from s1monw/http_on_cat
Expose http address in cat/nodes and cat/nodeattrs APIs We expose a lot of information like IP address and port but never expose the http address/ip:port in the CAT API. It's nice to have it there too since otherwise json parsing is required to get this information
This commit is contained in:
commit
354aae2fec
|
@ -43,6 +43,9 @@ import org.elasticsearch.rest.action.support.RestActionListener;
|
||||||
import org.elasticsearch.rest.action.support.RestResponseListener;
|
import org.elasticsearch.rest.action.support.RestResponseListener;
|
||||||
import org.elasticsearch.rest.action.support.RestTable;
|
import org.elasticsearch.rest.action.support.RestTable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
public class RestNodeAttrsAction extends AbstractCatAction {
|
public class RestNodeAttrsAction extends AbstractCatAction {
|
||||||
|
@ -112,6 +115,19 @@ public class RestNodeAttrsAction extends AbstractCatAction {
|
||||||
for (DiscoveryNode node : nodes) {
|
for (DiscoveryNode node : nodes) {
|
||||||
NodeInfo info = nodesInfo.getNodesMap().get(node.id());
|
NodeInfo info = nodesInfo.getNodesMap().get(node.id());
|
||||||
for(ObjectObjectCursor<String, String> att : node.attributes()) {
|
for(ObjectObjectCursor<String, String> att : node.attributes()) {
|
||||||
|
buildRow(fullId, table, node, info, att.key, att.value);
|
||||||
|
}
|
||||||
|
if (info.getServiceAttributes() != null) {
|
||||||
|
for (Map.Entry<String, String> entry : info.getServiceAttributes().entrySet()) {
|
||||||
|
buildRow(fullId, table, node, info, entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void buildRow(boolean fullId, Table table, DiscoveryNode node, NodeInfo info, String key, String value) {
|
||||||
table.startRow();
|
table.startRow();
|
||||||
table.addCell(node.name());
|
table.addCell(node.name());
|
||||||
table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
|
table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
|
||||||
|
@ -123,12 +139,8 @@ public class RestNodeAttrsAction extends AbstractCatAction {
|
||||||
} else {
|
} else {
|
||||||
table.addCell("-");
|
table.addCell("-");
|
||||||
}
|
}
|
||||||
table.addCell(att.key);
|
table.addCell(key);
|
||||||
table.addCell(att.value);
|
table.addCell(value);
|
||||||
table.endRow();
|
table.endRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ import org.elasticsearch.script.ScriptStats;
|
||||||
import org.elasticsearch.search.suggest.completion.CompletionStats;
|
import org.elasticsearch.search.suggest.completion.CompletionStats;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
|
|
||||||
|
@ -117,6 +118,7 @@ public class RestNodesAction extends AbstractCatAction {
|
||||||
table.addCell("pid", "default:false;alias:p;desc:process id");
|
table.addCell("pid", "default:false;alias:p;desc:process id");
|
||||||
table.addCell("ip", "alias:i;desc:ip address");
|
table.addCell("ip", "alias:i;desc:ip address");
|
||||||
table.addCell("port", "default:false;alias:po;desc:bound transport port");
|
table.addCell("port", "default:false;alias:po;desc:bound transport port");
|
||||||
|
table.addCell("http_address", "default:false;alias:http;desc:bound http adress");
|
||||||
|
|
||||||
table.addCell("version", "default:false;alias:v;desc:es version");
|
table.addCell("version", "default:false;alias:v;desc:es version");
|
||||||
table.addCell("build", "default:false;alias:b;desc:es build hash");
|
table.addCell("build", "default:false;alias:b;desc:es build hash");
|
||||||
|
@ -247,6 +249,12 @@ public class RestNodesAction extends AbstractCatAction {
|
||||||
} else {
|
} else {
|
||||||
table.addCell("-");
|
table.addCell("-");
|
||||||
}
|
}
|
||||||
|
final Map<String, String> serviceAttributes = info.getServiceAttributes();
|
||||||
|
if (serviceAttributes != null) {
|
||||||
|
table.addCell(serviceAttributes.getOrDefault("http_address", "-"));
|
||||||
|
} else {
|
||||||
|
table.addCell("-");
|
||||||
|
}
|
||||||
|
|
||||||
table.addCell(node.getVersion().toString());
|
table.addCell(node.getVersion().toString());
|
||||||
table.addCell(info == null ? null : info.getBuild().shortHash());
|
table.addCell(info == null ? null : info.getBuild().shortHash());
|
||||||
|
|
|
@ -48,3 +48,12 @@
|
||||||
$body: |
|
$body: |
|
||||||
/^ file_desc\.current \s+ file_desc\.percent \s+ file_desc\.max \n
|
/^ file_desc\.current \s+ file_desc\.percent \s+ file_desc\.max \n
|
||||||
(\s+ (-1|\d+) \s+ \d+ \s+ (-1|\d+) \n)+ $/
|
(\s+ (-1|\d+) \s+ \d+ \s+ (-1|\d+) \n)+ $/
|
||||||
|
|
||||||
|
- do:
|
||||||
|
cat.nodes:
|
||||||
|
h: http
|
||||||
|
v: true
|
||||||
|
|
||||||
|
- match:
|
||||||
|
$body: |
|
||||||
|
/^ http \n ((\d{1,3}\.){3}\d{1,3}:\d{1,5}\n)+ $/
|
||||||
|
|
Loading…
Reference in New Issue