diff --git a/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java b/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java index f75e6f3ba68..c84fe0c9a35 100644 --- a/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java +++ b/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java @@ -21,6 +21,8 @@ package org.elasticsearch.monitor.jvm; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.ElasticsearchIllegalArgumentException; +import org.elasticsearch.common.joda.FormatDateTimeFormatter; +import org.elasticsearch.common.joda.Joda; import org.elasticsearch.common.unit.TimeValue; import java.lang.management.ManagementFactory; @@ -35,6 +37,8 @@ public class HotThreads { private static final Object mutex = new Object(); + private static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("dateOptionalTime"); + private int busiestThreads = 3; private TimeValue interval = new TimeValue(500, TimeUnit.MILLISECONDS); private TimeValue threadElementsSnapshotDelay = new TimeValue(10); @@ -122,6 +126,17 @@ public class HotThreads { private String innerDetect() throws Exception { StringBuilder sb = new StringBuilder(); + + sb.append("Hot threads at "); + sb.append(DATE_TIME_FORMATTER.printer().print(System.currentTimeMillis())); + sb.append(", interval="); + sb.append(interval); + sb.append(", busiestThreads="); + sb.append(busiestThreads); + sb.append(", ignoreIdleThreads="); + sb.append(ignoreIdleThreads); + sb.append(":\n"); + ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); boolean enabledCpu = false; try { diff --git a/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java b/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java index c90b03824aa..65dbcc852a9 100644 --- a/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java +++ b/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java @@ -163,4 +163,17 @@ public class HotThreadsTest extends ElasticsearchIntegrationTest { // The filtered stacks should be smaller than unfiltered ones: assertThat(totSizeIgnoreIdle, lessThan(totSizeAll)); } + + public void testTimestampAndParams() throws ExecutionException, InterruptedException { + + NodesHotThreadsResponse response = client().admin().cluster().prepareNodesHotThreads().execute().get(); + + for (NodeHotThreads node : response.getNodesMap().values()) { + String result = node.getHotThreads(); + assertTrue(result.indexOf("Hot threads at") != -1); + assertTrue(result.indexOf("interval=500ms") != -1); + assertTrue(result.indexOf("busiestThreads=3") != -1); + assertTrue(result.indexOf("ignoreIdleThreads=true") != -1); + } + } }