diff --git a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index 447e260615d31..82d1aea50a986 100644 --- a/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -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() { @@ -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; } @@ -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); } @@ -112,10 +133,12 @@ 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 @@ -123,10 +146,12 @@ 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 @@ -134,10 +159,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws 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; } @@ -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 { @@ -253,3 +282,4 @@ public void writeTo(StreamOutput out) throws IOException { } } } + diff --git a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java index 45cb268537845..15ae7eb343daa 100644 --- a/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java +++ b/src/main/java/org/elasticsearch/index/indexing/ShardIndexingService.java @@ -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) { @@ -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) { @@ -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 { @@ -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() { @@ -302,3 +313,4 @@ public void clear() { } } } +