UserStat support agentId (#2501)

This commit is contained in:
codeleep 2023-05-05 16:30:08 +08:00 committed by GitHub
parent 243ffacf88
commit fa1d2bd30a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -456,6 +456,7 @@ public class ArthasBootstrap {
logger().info("arthas stat url: {}", configure.getStatUrl());
}
UserStatUtil.setStatUrl(configure.getStatUrl());
UserStatUtil.setAgentId(configure.getAgentId());
UserStatUtil.arthasStart();
try {

View File

@ -35,6 +35,8 @@ public class UserStatUtil {
private static volatile String statUrl = null;
private static volatile String agentId = null;
public static String getStatUrl() {
return statUrl;
}
@ -43,10 +45,21 @@ public class UserStatUtil {
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 {
@ -60,6 +73,9 @@ public class UserStatUtil {
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));

View File

@ -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<>();