Add OS name to _nodes and _cluster/nodes

we currently don't expose this.

This adds the following to the OS section of `_nodes`:

```
"os": {
     "name": "Mac OS X",
     ...
 }
 ```

 and the following to the OS section of `_cluster/stats`:

 ```
      "os": {
         ...
          "names": [
             {
                "name": "Mac OS X",
                "count": 1
             }
          ],
          ...
       },
 ```

Closes #11807
This commit is contained in:
Boaz Leskes 2015-06-22 16:36:00 +02:00
parent 2e07d0ba26
commit 1df2d3015e
4 changed files with 47 additions and 4 deletions

View File

@ -303,10 +303,12 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
int availableProcessors; int availableProcessors;
long availableMemory; long availableMemory;
ObjectIntHashMap<OsInfo.Cpu> cpus; final ObjectIntHashMap<String> names;
final ObjectIntHashMap<OsInfo.Cpu> cpus;
public OsStats() { public OsStats() {
cpus = new ObjectIntHashMap<>(); cpus = new ObjectIntHashMap<>();
names = new ObjectIntHashMap<>();
} }
public void addNodeInfo(NodeInfo nodeInfo) { public void addNodeInfo(NodeInfo nodeInfo) {
@ -314,6 +316,9 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
if (nodeInfo.getOs() == null) { if (nodeInfo.getOs() == null) {
return; return;
} }
if (nodeInfo.getOs().getName() != null) {
names.addTo(nodeInfo.getOs().getName(), 1);
}
if (nodeInfo.getOs().cpu() != null) { if (nodeInfo.getOs().cpu() != null) {
cpus.addTo(nodeInfo.getOs().cpu(), 1); cpus.addTo(nodeInfo.getOs().cpu(), 1);
} }
@ -339,8 +344,13 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
availableProcessors = in.readVInt(); availableProcessors = in.readVInt();
availableMemory = in.readLong(); availableMemory = in.readLong();
int size = in.readVInt(); int size = in.readVInt();
cpus = new ObjectIntHashMap<>(size); names.clear();
for (; size > 0; size--) { for (int i = 0; i < size; i++) {
names.addTo(in.readString(), in.readVInt());
}
size = in.readVInt();
cpus.clear();
for (int i = 0; i < size; i++) {
cpus.addTo(OsInfo.Cpu.readCpu(in), in.readVInt()); cpus.addTo(OsInfo.Cpu.readCpu(in), in.readVInt());
} }
} }
@ -349,12 +359,16 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(availableProcessors); out.writeVInt(availableProcessors);
out.writeLong(availableMemory); out.writeLong(availableMemory);
out.writeVInt(names.size());
for (ObjectIntCursor<String> name : names) {
out.writeString(name.key);
out.writeVInt(name.value);
}
out.writeVInt(cpus.size()); out.writeVInt(cpus.size());
for (ObjectIntCursor<OsInfo.Cpu> c : cpus) { for (ObjectIntCursor<OsInfo.Cpu> c : cpus) {
c.key.writeTo(out); c.key.writeTo(out);
out.writeVInt(c.value); out.writeVInt(c.value);
} }
} }
public static OsStats readOsStats(StreamInput in) throws IOException { public static OsStats readOsStats(StreamInput in) throws IOException {
@ -365,6 +379,8 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
static final class Fields { static final class Fields {
static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors"); static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors");
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString NAMES = new XContentBuilderString("names");
static final XContentBuilderString MEM = new XContentBuilderString("mem"); static final XContentBuilderString MEM = new XContentBuilderString("mem");
static final XContentBuilderString TOTAL = new XContentBuilderString("total"); static final XContentBuilderString TOTAL = new XContentBuilderString("total");
static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes"); static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes");
@ -379,6 +395,15 @@ public class ClusterStatsNodes implements ToXContent, Streamable {
builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, availableMemory); builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, availableMemory);
builder.endObject(); builder.endObject();
builder.startArray(Fields.NAMES);
for (ObjectIntCursor<String> name : names) {
builder.startObject();
builder.field(Fields.NAME, name.key);
builder.field(Fields.COUNT, name.value);
builder.endObject();
}
builder.endArray();
builder.startArray(Fields.CPU); builder.startArray(Fields.CPU);
for (ObjectIntCursor<OsInfo.Cpu> cpu : cpus) { for (ObjectIntCursor<OsInfo.Cpu> cpu : cpus) {
builder.startObject(); builder.startObject();

View File

@ -39,6 +39,8 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
int availableProcessors; int availableProcessors;
String name = null;
Cpu cpu = null; Cpu cpu = null;
Mem mem = null; Mem mem = null;
@ -88,8 +90,13 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
return swap(); return swap();
} }
public String getName() {
return name;
}
static final class Fields { static final class Fields {
static final XContentBuilderString OS = new XContentBuilderString("os"); static final XContentBuilderString OS = new XContentBuilderString("os");
static final XContentBuilderString NAME = new XContentBuilderString("name");
static final XContentBuilderString REFRESH_INTERVAL = new XContentBuilderString("refresh_interval"); static final XContentBuilderString REFRESH_INTERVAL = new XContentBuilderString("refresh_interval");
static final XContentBuilderString REFRESH_INTERVAL_IN_MILLIS = new XContentBuilderString("refresh_interval_in_millis"); static final XContentBuilderString REFRESH_INTERVAL_IN_MILLIS = new XContentBuilderString("refresh_interval_in_millis");
static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors"); static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors");
@ -112,6 +119,9 @@ public class OsInfo implements Streamable, Serializable, ToXContent {
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.OS); builder.startObject(Fields.OS);
if (name != null) {
builder.field(Fields.NAME, name);
}
builder.timeValueField(Fields.REFRESH_INTERVAL_IN_MILLIS, Fields.REFRESH_INTERVAL, refreshInterval); builder.timeValueField(Fields.REFRESH_INTERVAL_IN_MILLIS, Fields.REFRESH_INTERVAL, refreshInterval);
builder.field(Fields.AVAILABLE_PROCESSORS, availableProcessors); builder.field(Fields.AVAILABLE_PROCESSORS, availableProcessors);
if (cpu != null) { if (cpu != null) {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.monitor.os; package org.elasticsearch.monitor.os;
import org.apache.lucene.util.Constants;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -46,6 +47,7 @@ public class OsService extends AbstractComponent {
this.info = probe.osInfo(); this.info = probe.osInfo();
this.info.refreshInterval = refreshInterval.millis(); this.info.refreshInterval = refreshInterval.millis();
this.info.availableProcessors = Runtime.getRuntime().availableProcessors(); this.info.availableProcessors = Runtime.getRuntime().availableProcessors();
this.info.name = Constants.OS_NAME;
osStatsCache = new OsStatsCache(refreshInterval, probe.osStats()); osStatsCache = new OsStatsCache(refreshInterval, probe.osStats());
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval); logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);
} }

View File

@ -86,6 +86,12 @@ Will return, for example:
"total": "8gb", "total": "8gb",
"total_in_bytes": 8589934592 "total_in_bytes": 8589934592
}, },
"names": [
{
"name": "Mac OS X",
"count": 1
}
],
"cpu": [ "cpu": [
{ {
"vendor": "Intel", "vendor": "Intel",