Skip to content
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

[Feature][REST-API] Add threaddump rest api #7615

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class RestConstant {
public static final String JOB_INFO_URL = "/hazelcast/rest/maps/job-info";
public static final String FINISHED_JOBS_INFO = "/hazelcast/rest/maps/finished-jobs";
public static final String ENCRYPT_CONFIG = "/hazelcast/rest/maps/encrypt-config";
public static final String THREAD_DUMP = "/hazelcast/rest/maps/thread-dump";

// only for test use
public static final String RUNNING_THREADS = "/hazelcast/rest/maps/running-threads";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@

import java.io.IOException;
import java.io.StringWriter;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -93,6 +96,7 @@
import static org.apache.seatunnel.engine.server.rest.RestConstant.SYSTEM_MONITORING_INFORMATION;
import static org.apache.seatunnel.engine.server.rest.RestConstant.TELEMETRY_METRICS_URL;
import static org.apache.seatunnel.engine.server.rest.RestConstant.TELEMETRY_OPEN_METRICS_URL;
import static org.apache.seatunnel.engine.server.rest.RestConstant.THREAD_DUMP;

public class RestHttpGetCommandProcessor extends HttpCommandProcessor<HttpGetCommand> {

Expand Down Expand Up @@ -144,6 +148,8 @@ public void handle(HttpGetCommand httpGetCommand) {
handleMetrics(httpGetCommand, TextFormat.CONTENT_TYPE_004);
} else if (uri.equals(TELEMETRY_OPEN_METRICS_URL)) {
handleMetrics(httpGetCommand, TextFormat.CONTENT_TYPE_OPENMETRICS_100);
} else if (uri.startsWith(THREAD_DUMP)) {
getThreadDump(httpGetCommand);
} else {
original.handle(httpGetCommand);
}
Expand Down Expand Up @@ -203,6 +209,28 @@ public void overView(HttpGetCommand command, String uri) {
JsonUtil.toJsonObject(JsonUtils.toMap(JsonUtils.toJsonString(overviewInfo))));
}

public void getThreadDump(HttpGetCommand command) {
final StringBuilder dump = new StringBuilder();
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
final ThreadInfo[] threadInfos =
threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
for (ThreadInfo threadInfo : threadInfos) {
dump.append('"');
dump.append(threadInfo.getThreadName());
dump.append("\" ");
final Thread.State state = threadInfo.getThreadState();
dump.append("\n java.lang.Thread.State: ");
dump.append(state);
final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
for (final StackTraceElement stackTraceElement : stackTraceElements) {
dump.append("\n at ");
dump.append(stackTraceElement);
}
dump.append("\n\n");
}
this.prepareResponse(command, dump.toString());
liugddx marked this conversation as resolved.
Show resolved Hide resolved
}

private void getSystemMonitoringInformation(HttpGetCommand command) {
Cluster cluster = textCommandService.getNode().hazelcastInstance.getCluster();
nodeEngine = textCommandService.getNode().hazelcastInstance.node.nodeEngine;
Expand Down
Loading