Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,22 @@ public static class OsStats implements ToXContent, Streamable {

int availableProcessors;
long availableMemory;
ObjectIntHashMap<OsInfo.Cpu> cpus;
final ObjectIntHashMap<String> names;
final ObjectIntHashMap<OsInfo.Cpu> cpus;

public OsStats() {
cpus = new ObjectIntHashMap<>();
names = new ObjectIntHashMap<>();
}

public void addNodeInfo(NodeInfo nodeInfo) {
availableProcessors += nodeInfo.getOs().availableProcessors();
if (nodeInfo.getOs() == null) {
return;
}
if (nodeInfo.getOs().getName() != null) {
names.addTo(nodeInfo.getOs().getName(), 1);
}
if (nodeInfo.getOs().cpu() != null) {
cpus.addTo(nodeInfo.getOs().cpu(), 1);
}
Expand All @@ -339,8 +344,13 @@ public void readFrom(StreamInput in) throws IOException {
availableProcessors = in.readVInt();
availableMemory = in.readLong();
int size = in.readVInt();
cpus = new ObjectIntHashMap<>(size);
for (; size > 0; size--) {
names.clear();
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());
}
}
Expand All @@ -349,12 +359,16 @@ public void readFrom(StreamInput in) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(availableProcessors);
out.writeLong(availableMemory);
out.writeVInt(names.size());
for (ObjectIntCursor<String> name : names) {
out.writeString(name.key);
out.writeVInt(name.value);
}
out.writeVInt(cpus.size());
for (ObjectIntCursor<OsInfo.Cpu> c : cpus) {
c.key.writeTo(out);
out.writeVInt(c.value);
}

}

public static OsStats readOsStats(StreamInput in) throws IOException {
Expand All @@ -365,6 +379,8 @@ public static OsStats readOsStats(StreamInput in) throws IOException {

static final class Fields {
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 TOTAL = new XContentBuilderString("total");
static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes");
Expand All @@ -379,6 +395,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.byteSizeField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, availableMemory);
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);
for (ObjectIntCursor<OsInfo.Cpu> cpu : cpus) {
builder.startObject();
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class OsInfo implements Streamable, Serializable, ToXContent {

int availableProcessors;

String name = null;

Cpu cpu = null;

Mem mem = null;
Expand Down Expand Up @@ -88,8 +90,13 @@ public Swap getSwap() {
return swap();
}

public String getName() {
return name;
}

static final class Fields {
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_IN_MILLIS = new XContentBuilderString("refresh_interval_in_millis");
static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors");
Expand All @@ -112,6 +119,9 @@ static final class Fields {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.OS);
if (name != null) {
builder.field(Fields.NAME, name);
}
builder.timeValueField(Fields.REFRESH_INTERVAL_IN_MILLIS, Fields.REFRESH_INTERVAL, refreshInterval);
builder.field(Fields.AVAILABLE_PROCESSORS, availableProcessors);
if (cpu != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.monitor.os;

import org.apache.lucene.util.Constants;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -46,6 +47,7 @@ public OsService(Settings settings, OsProbe probe) {
this.info = probe.osInfo();
this.info.refreshInterval = refreshInterval.millis();
this.info.availableProcessors = Runtime.getRuntime().availableProcessors();
this.info.name = Constants.OS_NAME;
osStatsCache = new OsStatsCache(refreshInterval, probe.osStats());
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);
}
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/cluster/stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Will return, for example:
"total": "8gb",
"total_in_bytes": 8589934592
},
"names": [
{
"name": "Mac OS X",
"count": 1
}
],
"cpu": [
{
"vendor": "Intel",
Expand Down