> For the complete documentation index, see [llms.txt](https://yangsx95.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yangsx95.gitbook.io/notes/architect/apm/arthas.md).

# Arthas

Arthas 是一款Java应用诊断利器，官方地址为：<https://arthas.gitee.io/>

启动：

```console
# 指定端口启动
./as.sh --telnet-port 9998
```

监测方法的耗时：

```console
# 监测单个方法执行时间
trace com.rhdk.contractservice.contract.service.AbstractContractService doHibernateValidate -n 10

# 监测多个方法执行时间
trace -n 10 -E com.rhdk.contractservice.contract.service.AbstractContractService|com.rhdk.contractservice.contract.service.impl.PurchaseBusinessService update
trace -n 10 -E com.rhdk.contractservice.contract.service.AbstractContractService|com.rhdk.contractservice.contract.service.impl.PurchaseBusinessService|com.rhdk.contractservice.feign.RemoteUserFeignResolver doUpdateContract|getOrgName 

# 监测不跳过jdk的方法
trace --skipJDKMethod false demo.MathGame run

# 监测大于10ms的方法
trace demo.MathGame run '#cost > 10'

# 监测排除指定的类
trace javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter
```

jprofiler 火焰图生成：

```console
profiler start
profiler status
profiler stop --format html
```

配置nginx访问火焰图：

```conf
location /arthas {
    #arthas 生成资源路径
    proxy_pass http://127.0.0.1:3658/arthas-output;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
```

使用watch命令监控方法出入参：

```console
# 监控DemoService的getUser方法 的 入参与出参
# -x 3 表示输出对象遍历深度为3，用于输出对象中含有对象的属性
watch com.demo.service.DemoService getUser '{params,returnObj}' -x 3
```

监控有参数的methodName方法的入参、返回值、异常信息：

```console
watch packagename.ClassName methodName '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0'
```

```console
watch packagename.ClassName methodName '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0 && params[0] instanceof java.lang.Integer'
```

watch com.spicrhdk.jupiter.auth.biz.service.impl.serviceutil.AppOrgTypeService checkOrgTypeIsInner '{params,returnObj,throwExp}' -n 5 -x 3 'params.length >0 && params\[0] instanceof java.lang.Integer && params\[1] instanceof java.lang.String'


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yangsx95.gitbook.io/notes/architect/apm/arthas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
