Skip to content

Commit

Permalink
Expose min/max open file descriptors in Cluster Stats API
Browse files Browse the repository at this point in the history
Also changes the response format of that section to:

```
 "open_file_descriptors": {
      "min": 200,
      "max": 346,
       "avg": 273
 }
```

Closes elastic#4681
  • Loading branch information
bleskes committed Jan 10, 2014
1 parent 62ff3bb commit e979f9c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
6 changes: 5 additions & 1 deletion docs/reference/cluster/stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ Will return, for example:
"cpu": {
"percent": 3
},
"avg_open_file_descriptors": 218
"open_file_descriptors": {
"min": 200,
"max": 346,
"avg": 273
}
},
"jvm": {
"max_uptime": "24s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ public static class ProcessStats implements ToXContent, Streamable {
int count;
int cpuPercent;
long totalOpenFileDescriptors;
long minOpenFileDescriptors = Integer.MAX_VALUE;
long maxOpenFileDescriptors = Integer.MIN_VALUE;

public void addNodeStats(NodeStats nodeStats) {
if (nodeStats.getProcess() == null) {
Expand All @@ -407,7 +409,10 @@ public void addNodeStats(NodeStats nodeStats) {
// with no sigar, this may not be available
cpuPercent += nodeStats.getProcess().cpu().getPercent();
}
totalOpenFileDescriptors += nodeStats.getProcess().openFileDescriptors();
long fd = nodeStats.getProcess().openFileDescriptors();
totalOpenFileDescriptors += fd;
minOpenFileDescriptors = Math.min(minOpenFileDescriptors, fd);
maxOpenFileDescriptors = Math.max(maxOpenFileDescriptors, fd);
}

/**
Expand All @@ -424,6 +429,20 @@ public long getAvgOpenFileDescriptors() {
return totalOpenFileDescriptors / count;
}

public long getMaxOpenFileDescriptors() {
if (count == 0) {
return -1;
}
return maxOpenFileDescriptors;
}

public long getMinOpenFileDescriptors() {
if (count == 0) {
return -1;
}
return minOpenFileDescriptors;
}

@Override
public void readFrom(StreamInput in) throws IOException {
count = in.readVInt();
Expand All @@ -447,13 +466,22 @@ public static ProcessStats readStats(StreamInput in) throws IOException {
static final class Fields {
static final XContentBuilderString CPU = new XContentBuilderString("cpu");
static final XContentBuilderString PERCENT = new XContentBuilderString("percent");
static final XContentBuilderString AVG_OPEN_FD = new XContentBuilderString("avg_open_file_descriptors");
static final XContentBuilderString OPEN_FILE_DESCRIPTORS = new XContentBuilderString("open_file_descriptors");
static final XContentBuilderString MIN = new XContentBuilderString("min");
static final XContentBuilderString MAX = new XContentBuilderString("max");
static final XContentBuilderString AVG = new XContentBuilderString("avg");
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.CPU).field(Fields.PERCENT, cpuPercent).endObject();
builder.field(Fields.AVG_OPEN_FD, getAvgOpenFileDescriptors());
if (count > 0) {
builder.startObject(Fields.OPEN_FILE_DESCRIPTORS);
builder.field(Fields.MIN, getMinOpenFileDescriptors());
builder.field(Fields.MAX, getMaxOpenFileDescriptors());
builder.field(Fields.AVG, getAvgOpenFileDescriptors());
builder.endObject();
}
return builder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,9 @@ public void testValuesSmokeScreen() {
assertThat(response.nodesStats.getVersions().contains(Version.CURRENT), Matchers.equalTo(true));
assertThat(response.nodesStats.getPlugins().size(), Matchers.greaterThanOrEqualTo(0));

assertThat(response.nodesStats.getProcess().getAvgOpenFileDescriptors(), Matchers.greaterThan(0L));
assertThat(response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThan(0L));
assertThat(response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThan(0L));

}
}

0 comments on commit e979f9c

Please sign in to comment.