From 4859ce5d79a786b58b1cd2fb131614677efd6b91 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 19 Feb 2015 15:10:17 -0500 Subject: [PATCH] Core: include timestamp and params in hot threads Include the timestamp and params (interval, busiestThreads, ignoreIdleThreads), when hot threads were collected. Closes #9773 --- .../org/elasticsearch/monitor/jvm/HotThreads.java | 15 +++++++++++++++ .../action/admin/HotThreadsTest.java | 13 +++++++++++++ 2 files changed, 28 insertions(+) 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); + } + } }