[alibaba/arthas]HTTP API 执行 vmtool 命令,响应没有展开

2025-11-12 195 views
7
环境信息
  • Arthas 版本: 3.6.1
  • 目标进程的JVM版本: 1.8.0_312
重现问题的步骤

使用 HTTP 接口执行 vmtool 指令:

-- request
{
  "action": "exec",
  "command": "vmtool --action getInstances --className org.apache.tomcat.util.threads.ThreadPoolExecutor -x 3",
  "execTimeout": "1000"
}

-- response
{
    "body": {
        "command": "vmtool --action getInstances --className org.apache.tomcat.util.threads.ThreadPoolExecutor -x 3",
        "jobId": 55,
        "jobStatus": "TERMINATED",
        "results": [
            {
                "expand": 3,
                "jobId": 55,
                "type": "vmtool",
                "value": [
                    {
                        "activeCount": 0,
                        "completedTaskCount": 0,
                        "corePoolSize": 10,
                        "largestPoolSize": 10,
                        "maximumPoolSize": 200,
                        "poolSize": 10,
                        "queue": [],
                        "rejectedExecutionHandler": {},
                        "shutdown": false,
                        "submittedCount": 0,
                        "taskCount": 0,
                        "terminated": false,
                        "terminating": false,
                        "threadFactory": {},
                        "threadRenewalDelay": 1000
                    }
                ]
            },
            {
                "jobId": 55,
                "statusCode": 0,
                "type": "status"
            }
        ],
        "timeExpired": false
    },
    "sessionId": "f01c09d0-0af6-4146-86aa-306812b4431e",
    "state": "SUCCEEDED"
}

同样的指令在 web ui 上执行可以得到展开的结果:

回答

7

类似的issue,同样的vmtool语句在命令行和web console可以,到结合系统用http api时,没有返回结果

8

因为http api返回是,直接返回的是 json对象,所以 -x参数无效了。 返回结果只和对象本身的 json

比如执行文档里的 math-gama.jar,在 http://127.0.0.1:8563/ui 里执行vmtool --action getInstances --className demo.MathGame ,返回结果是:

{"expand":1,"jobId":5,"type":"vmtool","value":[{}]}

原因是MathGame这个类本身没有getter/setter 函数,所以它的json输出就是一个{}

如果执行下面的语句,则是有结果的:

vmtool --action getInstances --className demo.MathGame --express '#value1=@System@getProperty("java.home"), #value2=@System@getProperty("java.runtime.name"), {#value1, #value2}'
{"expand":1,"jobId":4,"type":"vmtool","value":["/tmp/java/8.0.332-zulu/zulu-8.jdk/Contents/Home/jre","OpenJDK Runtime Environment"]}