Skip to content

Node Stats : last index and last delete timestamps added #3933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
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
36 changes: 33 additions & 3 deletions src/main/java/org/elasticsearch/index/indexing/IndexingStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,38 @@ public static class Stats implements Streamable, ToXContent {

private long indexCount;
private long indexTimeInMillis;
private long indexLastTimestamp;
private long indexCurrent;

private long deleteCount;
private long deleteTimeInMillis;
private long deleteLastTimestamp;
private long deleteCurrent;

Stats() {

}

public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long deleteCount, long deleteTimeInMillis, long deleteCurrent) {
public Stats(long indexCount, long indexTimeInMillis, long indexCurrent, long indexLastTime, long deleteCount, long deleteTimeInMillis, long deleteCurrent, long deleteLastTime) {
this.indexCount = indexCount;
this.indexTimeInMillis = indexTimeInMillis;
this.indexCurrent = indexCurrent;
this.indexLastTimestamp = indexLastTime;
this.deleteCount = deleteCount;
this.deleteTimeInMillis = deleteTimeInMillis;
this.deleteCurrent = deleteCurrent;
this.deleteLastTimestamp = deleteLastTime;
}

public void add(Stats stats) {
indexCount += stats.indexCount;
indexTimeInMillis += stats.indexTimeInMillis;
indexCurrent += stats.indexCurrent;

indexLastTimestamp = Math.max(indexLastTimestamp, stats.indexLastTimestamp);
deleteCount += stats.deleteCount;
deleteTimeInMillis += stats.deleteTimeInMillis;
deleteCurrent += stats.deleteCurrent;
deleteLastTimestamp = Math.max(deleteLastTimestamp, stats.deleteLastTimestamp);
}

public long getIndexCount() {
Expand All @@ -81,6 +86,14 @@ public long getIndexTimeInMillis() {
return indexTimeInMillis;
}

public TimeValue getLastIndexTime() {
return new TimeValue(indexLastTimestamp);
}

public long getIndexLastTimestamp() {
return indexLastTimestamp;
}

public long getIndexCurrent() {
return indexCurrent;
}
Expand All @@ -89,6 +102,14 @@ public long getDeleteCount() {
return deleteCount;
}

public TimeValue getDeleteLastTime() {
return new TimeValue(deleteLastTimestamp);
}

public long getLastDeleteTimestamp() {
return deleteLastTimestamp;
}

public TimeValue getDeleteTime() {
return new TimeValue(deleteTimeInMillis);
}
Expand All @@ -112,32 +133,38 @@ public void readFrom(StreamInput in) throws IOException {
indexCount = in.readVLong();
indexTimeInMillis = in.readVLong();
indexCurrent = in.readVLong();

indexLastTimestamp = in.readVLong();

deleteCount = in.readVLong();
deleteTimeInMillis = in.readVLong();
deleteCurrent = in.readVLong();
deleteLastTimestamp = in.readVLong();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVLong(indexCount);
out.writeVLong(indexTimeInMillis);
out.writeVLong(indexCurrent);
out.writeVLong(indexLastTimestamp);

out.writeVLong(deleteCount);
out.writeVLong(deleteTimeInMillis);
out.writeVLong(deleteCurrent);
out.writeVLong(deleteLastTimestamp);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(Fields.INDEX_TOTAL, indexCount);
builder.timeValueField(Fields.INDEX_TIME_IN_MILLIS, Fields.INDEX_TIME, indexTimeInMillis);
builder.field(Fields.INDEX_CURRENT, indexCurrent);
builder.field(Fields.INDEX_LAST_TIME_IN_MILLIS, indexLastTimestamp);

builder.field(Fields.DELETE_TOTAL, deleteCount);
builder.timeValueField(Fields.DELETE_TIME_IN_MILLIS, Fields.DELETE_TIME, deleteTimeInMillis);
builder.field(Fields.DELETE_CURRENT, deleteCurrent);
builder.field(Fields.DELETE_LAST_TIME_IN_MILLIS, deleteLastTimestamp);

return builder;
}
Expand Down Expand Up @@ -213,11 +240,13 @@ static final class Fields {
static final XContentBuilderString INDEX_TOTAL = new XContentBuilderString("index_total");
static final XContentBuilderString INDEX_TIME = new XContentBuilderString("index_time");
static final XContentBuilderString INDEX_TIME_IN_MILLIS = new XContentBuilderString("index_time_in_millis");
static final XContentBuilderString INDEX_LAST_TIME_IN_MILLIS = new XContentBuilderString("last_index_timestamp");
static final XContentBuilderString INDEX_CURRENT = new XContentBuilderString("index_current");
static final XContentBuilderString DELETE_TOTAL = new XContentBuilderString("delete_total");
static final XContentBuilderString DELETE_TIME = new XContentBuilderString("delete_time");
static final XContentBuilderString DELETE_TIME_IN_MILLIS = new XContentBuilderString("delete_time_in_millis");
static final XContentBuilderString DELETE_CURRENT = new XContentBuilderString("delete_current");
static final XContentBuilderString DELETE_LAST_TIME_IN_MILLIS = new XContentBuilderString("last_delete_timestamp");
}

public static IndexingStats readIndexingStats(StreamInput in) throws IOException {
Expand Down Expand Up @@ -253,3 +282,4 @@ public void writeTo(StreamOutput out) throws IOException {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ public void postCreateUnderLock(Engine.Create create) {

public void postCreate(Engine.Create create) {
long took = create.endTime() - create.startTime();
long now = System.currentTimeMillis();
totalStats.indexMetric.inc(took);
totalStats.indexCurrent.dec();
totalStats.indexLastTimestamp = now;
StatsHolder typeStats = typeStats(create.type());
typeStats.indexMetric.inc(took);
typeStats.indexCurrent.dec();
typeStats.indexLastTimestamp = now;
slowLog.postCreate(create, took);
if (listeners != null) {
for (IndexingOperationListener listener : listeners) {
Expand Down Expand Up @@ -165,11 +168,14 @@ public void postIndexUnderLock(Engine.Index index) {

public void postIndex(Engine.Index index) {
long took = index.endTime() - index.startTime();
long now = System.currentTimeMillis();
totalStats.indexMetric.inc(took);
totalStats.indexCurrent.dec();
totalStats.indexLastTimestamp = now;
StatsHolder typeStats = typeStats(index.type());
typeStats.indexMetric.inc(took);
typeStats.indexCurrent.dec();
typeStats.indexLastTimestamp = now;
slowLog.postIndex(index, took);
if (listeners != null) {
for (IndexingOperationListener listener : listeners) {
Expand Down Expand Up @@ -212,11 +218,14 @@ public void postDeleteUnderLock(Engine.Delete delete) {

public void postDelete(Engine.Delete delete) {
long took = delete.endTime() - delete.startTime();
long now = System.currentTimeMillis();
totalStats.deleteMetric.inc(took);
totalStats.deleteCurrent.dec();
totalStats.deleteLastTimestamp = now;
StatsHolder typeStats = typeStats(delete.type());
typeStats.deleteMetric.inc(took);
typeStats.deleteCurrent.dec();
typeStats.deleteLastTimestamp = now;
if (listeners != null) {
for (IndexingOperationListener listener : listeners) {
try {
Expand Down Expand Up @@ -285,11 +294,13 @@ static class StatsHolder {
public final MeanMetric deleteMetric = new MeanMetric();
public final CounterMetric indexCurrent = new CounterMetric();
public final CounterMetric deleteCurrent = new CounterMetric();
public long indexLastTimestamp = 0;
public long deleteLastTimestamp = 0;

public IndexingStats.Stats stats() {
return new IndexingStats.Stats(
indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(),
deleteMetric.count(), TimeUnit.NANOSECONDS.toMillis(deleteMetric.sum()), deleteCurrent.count());
indexMetric.count(), TimeUnit.NANOSECONDS.toMillis(indexMetric.sum()), indexCurrent.count(), indexLastTimestamp,
deleteMetric.count(), TimeUnit.NANOSECONDS.toMillis(deleteMetric.sum()), deleteCurrent.count(), deleteLastTimestamp);
}

public long totalCurrent() {
Expand All @@ -302,3 +313,4 @@ public void clear() {
}
}
}