Skip to content

Commit

Permalink
UserStat support agentId (#2501)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeleep authored May 5, 2023
1 parent 243ffac commit fa1d2bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ private void bind(Configure configure) throws Throwable {
logger().info("arthas stat url: {}", configure.getStatUrl());
}
UserStatUtil.setStatUrl(configure.getStatUrl());
UserStatUtil.setAgentId(configure.getAgentId());
UserStatUtil.arthasStart();

try {
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/com/taobao/arthas/core/util/UserStatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public Thread newThread(Runnable r) {

private static volatile String statUrl = null;

private static volatile String agentId = null;

public static String getStatUrl() {
return statUrl;
}
Expand All @@ -43,10 +45,21 @@ public static void setStatUrl(String url) {
statUrl = url;
}

public static String getAgentId() {
return agentId;
}

public static void setAgentId(String id) {
agentId = id;
}

public static void arthasStart() {
RemoteJob job = new RemoteJob();
job.appendQueryData("ip", ip);
job.appendQueryData("version", version);
if (agentId != null) {
job.appendQueryData("agentId", agentId);
}
job.appendQueryData("command", "start");

try {
Expand All @@ -60,6 +73,9 @@ public static void arthasUsage(String cmd, String detail) {
RemoteJob job = new RemoteJob();
job.appendQueryData("ip", ip);
job.appendQueryData("version", version);
if (agentId != null) {
job.appendQueryData("agentId", agentId);
}
job.appendQueryData("command", URLEncoder.encode(cmd));
if (detail != null) {
job.appendQueryData("arguments", URLEncoder.encode(detail));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class StatController {
@ResponseBody
public Map<String, Object> execute(@RequestParam(value = "ip", required = true) String ip,
@RequestParam(value = "version", required = true) String version,
@RequestParam(value = "agentId", required = false) String agentId,
@RequestParam(value = "command", required = true) String command,
@RequestParam(value = "arguments", required = false, defaultValue = "") String arguments) {

logger.info("arthas stat, ip: {}, version: {}, command: {}, arguments: {}", ip, version, command, arguments);
logger.info("arthas stat, ip: {}, version: {}, agentId: {}, command: {}, arguments: {}", ip, version, agentId, command, arguments);

Map<String, Object> result = new HashMap<>();

Expand Down

0 comments on commit fa1d2bd

Please sign in to comment.