add get java app classpath case of http api (#1426)

This commit is contained in:
gongdewei
2020-08-13 17:00:59 +08:00
committed by GitHub
parent 0366205bda
commit e652137af2
2 changed files with 92 additions and 9 deletions
+45 -4
View File
@@ -26,9 +26,9 @@ http api.
```json
{
"action": "exec",
"requestId": "req112"
"sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb"
"consumerId": "955dbd1325334a84972b0f3ac19de4f7_2"
"requestId": "req112",
"sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb",
"consumerId": "955dbd1325334a84972b0f3ac19de4f7_2",
"command": "version",
"execTimeout": "10000"
}
@@ -614,7 +614,48 @@ receive this `enhancer` result. It may happen that the result of
`enhancer` is successful, but there is no hit method. The client can
prompt the user according to the result of `enhancer`.
### Others
### Cases
#### Get classpath of Java application
Get system properties of the Java application through Http api and
extract the value of `java.class.path`.
```bash
json_data=$(curl -Ss -XPOST http://localhost:8563/api -d '
{
"action":"exec",
"command":"sysprop"
}')
```
* Extract value with `sed`:
```bash
class_path=$(echo $json_data | tr -d '\n' | sed 's/.*"java.class.path":"\([^"]*\).*/\1/')
echo "classpath: $class_path"
```
* Extract value with `json_pp/awk`:
```bash
class_path=$(echo $json_data | tr -d '\n' | json_pp | grep java.class.path | awk -F'"' '{ print $4 }')
echo "classpath: $class_path"
```
Output:
```
classpath: demo-arthas-spring-boot.jar
```
NOTE:
* `echo $json_data | tr -d '\n'` : Delete line breaks (the value of
`line.separator`) to avoid affecting the processing of `sed`/`json_pp`
commands.
* `awk -F'"' '{ print $4 }'` : Use double quote as delimiter
<a id="change_watch_value_to_map"></a>
#### Make watch command output a map object
+47 -5
View File
@@ -20,9 +20,9 @@ Http API接口地址为:`http://ip:port/api`,必须使用POST方式提交请
```json
{
"action": "exec",
"requestId": "req112"
"sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb"
"consumerId": "955dbd1325334a84972b0f3ac19de4f7_2"
"requestId": "req112",
"sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb",
"consumerId": "955dbd1325334a84972b0f3ac19de4f7_2",
"command": "version",
"execTimeout": "10000"
}
@@ -537,7 +537,47 @@ curl -Ss -XPOST http://localhost:8563/api -d '''
`trace/watch/jad/tt`等命令需要对类进行增强,会接收到这个`enhancer`结果。可能出现`enhancer`结果成功,但没有命中方法的情况,客户端可以根据`enhancer`结果提示用户。
### 其它
### 案例
#### 获取Java应用的Classpath
通过Http api查询Java应用的System properties,提取`java.class.path`的值。
```bash
json_data=$(curl -Ss -XPOST http://localhost:8563/api -d '
{
"action":"exec",
"command":"sysprop"
}')
```
* 使用`sed`提取值:
```bash
class_path=$(echo $json_data | tr -d '\n' | sed 's/.*"java.class.path":"\([^"]*\).*/\1/')
echo "classpath: $class_path"
```
* 使用`json_pp/awk`提取值
```bash
class_path=$(echo $json_data | tr -d '\n' | json_pp | grep java.class.path | awk -F'"' '{ print $4 }')
echo "classpath: $class_path"
```
输出内容:
```
classpath: demo-arthas-spring-boot.jar
```
注意:
* `echo $json_data | tr -d '\n'` : 删除换行符(`line.separator`的值),避免影响`sed`/`json_pp`命令处理。
* `awk -F'"' '{ print $4 }'` : 使用双引号作为分隔符号
<a id="change_watch_value_to_map"></a>
#### watch命令输出map对象
@@ -629,4 +669,6 @@ Http api 执行结果:
}
```
可以看到watch结果的value变成map对象,程序可以通过key读取结果。
可以看到watch结果的value变成map对象,程序可以通过key读取结果。