Skip to content

Commit

Permalink
Node Stats: Add largest thread pool count per thread pool stats
Browse files Browse the repository at this point in the history
closes #2382
  • Loading branch information
kimchy committed Nov 6, 2012
1 parent af1e8c0 commit 3390047
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/elasticsearch/threadpool/ThreadPool.java
Expand Up @@ -139,17 +139,19 @@ public ThreadPoolStats stats() {
int queue = -1;
int active = -1;
long rejected = -1;
int largest = -1;
if (holder.executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) holder.executor;
threads = threadPoolExecutor.getPoolSize();
queue = threadPoolExecutor.getQueue().size();
active = threadPoolExecutor.getActiveCount();
largest = threadPoolExecutor.getLargestPoolSize();
RejectedExecutionHandler rejectedExecutionHandler = threadPoolExecutor.getRejectedExecutionHandler();
if (rejectedExecutionHandler instanceof XRejectedExecutionHandler) {
rejected = ((XRejectedExecutionHandler) rejectedExecutionHandler).rejected();
}
}
stats.add(new ThreadPoolStats.Stats(name, threads, queue, active, rejected));
stats.add(new ThreadPoolStats.Stats(name, threads, queue, active, rejected, largest));
}
return new ThreadPoolStats(stats);
}
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java
Expand Up @@ -42,17 +42,19 @@ public static class Stats implements Streamable, ToXContent {
private int queue;
private int active;
private long rejected;
private int largest;

Stats() {

}

public Stats(String name, int threads, int queue, int active, long rejected) {
public Stats(String name, int threads, int queue, int active, long rejected, int largest) {
this.name = name;
this.threads = threads;
this.queue = queue;
this.active = active;
this.rejected = rejected;
this.largest = largest;
}

public String name() {
Expand Down Expand Up @@ -95,22 +97,32 @@ public long getRejected() {
return rejected;
}

public int largest() {
return largest;
}

public int getLargest() {
return largest;
}

@Override
public void readFrom(StreamInput in) throws IOException {
name = in.readUTF();
name = in.readString();
threads = in.readInt();
queue = in.readInt();
active = in.readInt();
rejected = in.readLong();
largest = in.readInt();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(name);
out.writeString(name);
out.writeInt(threads);
out.writeInt(queue);
out.writeInt(active);
out.writeLong(rejected);
out.writeInt(largest);
}

@Override
Expand All @@ -128,6 +140,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (rejected != -1) {
builder.field(Fields.REJECTED, rejected);
}
if (largest != -1) {
builder.field(Fields.LARGEST, rejected);
}
builder.endObject();
return builder;
}
Expand Down Expand Up @@ -179,6 +194,7 @@ static final class Fields {
static final XContentBuilderString QUEUE = new XContentBuilderString("queue");
static final XContentBuilderString ACTIVE = new XContentBuilderString("active");
static final XContentBuilderString REJECTED = new XContentBuilderString("rejected");
static final XContentBuilderString LARGEST = new XContentBuilderString("largest");
}

@Override
Expand Down

0 comments on commit 3390047

Please sign in to comment.