arthas监控工具笔记(二)monior等

文章目录

    • monitor/watch/trace 相关
      • monitor
        • monitor例子
          • monitor -c <value>
          • monitor -m <vaule>
          • monitor 条件表达式
          • monitor -b
        • monitor文档(界面描述)
        • monitor文档(help)
      • stack - 输出当前方法被调用的调用路径
      • trace - 方法内部调用路径,并输出方法路径上的每个节点上耗时
      • tt - 方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测
        • tt使用
          • tt 删除
        • tt文档(命令行)
      • watch - 方法执行数据观测
        • watch例子
          • watch target例子
        • watch例子2
        • watch文档(界面)
        • watch文档(命令行)

这是第二章,第一章见博客。

monitor/watch/trace 相关

monitor

monitor是方法监控工具,例如一定时间的次数,成功率,失败率,响应时间等。
还可以根据条件进行过滤。

monitor例子

不加任何参数:
monitor org.apache.commons.lang.StringUtils isBlank

monitor -c

monitor -c 5 org.apache.commons.lang.StringUtils isBlank
-c --cycle 表示统计周期,默认60s。设置为-c 5我们发现命令行每5s打印一次,如果设置为-c 10,每10s打印一次。

monitor -m

monitor -m 1 -c 5 org.apache.commons.lang3.StringUtils isBlank
-m, --maxMatch 表示匹配类的最大限制数,感觉是为了避免相同类内容太多,加上这个参数如果实际类数量>-m的值,会报错。

例如:

[arthas@23052]$ monitor -m 1 -c 5 org.apache.commons.lang3.StringUtils 
isBlank
输出:
Affect(class count: 0 , method count: 0) cost in 9 ms, listenerId: 14
The number of matched classes is 2, greater than the limit value 1. Try to change the limit with option '-m <arg>'.
monitor 条件表达式

monitor -c 5 com.example.controller.api.InvoiceApiContorller invoiceQueryFast “params[0] >1”
“params[0] >1” 在方法执行完之后,根据条件表达式进行过滤。
这里有个疑问啊?
如果是spring的@RequestBody报文,怎么写表达式呢?这个表达式是否只能做一些简单的计算。

monitor -b

monitor -c 5 -b com.example.controller.api.InvoiceApiContorller invoiceQueryFast “params[0] >1”
-b 表示在方法执行完之前,根据条件表达式进行过滤。

monitor文档(界面描述)

参数说明
方法拥有一个命名参数 [c:],意思是统计周期(cycle of output),拥有一个整型的参数值

参数名称 参数说明
class-pattern 类名表达式匹配
method-pattern 方法名表达式匹配
condition-express 条件表达式
[E] 开启正则表达式匹配,默认为通配符匹配
[c:] 统计周期,默认值为 120 秒
[b] 在方法调用之前计算 condition-express
[m ] 指定 Class 最大匹配数量,默认值为 50。长格式为[maxMatch ]。

monitor文档(help)

输入 help monitor,返回的内容就是文档:

help monitor
USAGE:
  monitor [-b] [-c <value>] [--exclude-class-pattern <value>] [-h] [-n <value>] [--listenerId <value>] [-m <value>] [
-E] [-v] class-pattern method-pattern [condition-express]

SUMMARY:
  Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.

Examples:
  monitor org.apache.commons.lang.StringUtils isBlank
  monitor org.apache.commons.lang.StringUtils isBlank -c 5
  monitor org.apache.commons.lang.StringUtils isBlank params[0]!=null
  monitor -b org.apache.commons.lang.StringUtils isBlank params[0]!=null
  monitor -E org\.apache\.commons\.lang\.StringUtils isBlank

WIKI:
  https://arthas.aliyun.com/doc/monitor

OPTIONS:
-b, --before                            Evaluate the condition-express before method invoke
-c, --cycle <value>                     The monitor interval (in seconds), 60 seconds by default
    --exclude-class-pattern <value>     exclude class name pattern, use either '.' or '/' as separator
-h, --help                              this help
-n, --limits <value>                    Threshold of execution times
    --listenerId <value>                The special listenerId
-m, --maxMatch <value>                  The maximum of matched class.
-E, --regex                             Enable regular expression to match (wildcard matching by default)
-v, --verbose                           Enables print verbose information, default value false.
<class-pattern>                         Path and classname of Pattern Matching
<method-pattern>                        Method of Pattern Matching
<condition-express>                     Conditional expression in ognl style, for example:
                                          TRUE  : 1==1
                                          TRUE  : true
                                          FALSE : false
                                          TRUE  : 'params.length>=0'
                                          FALSE : 1==2
                                          '#cost>100'

stack - 输出当前方法被调用的调用路径

trace - 方法内部调用路径,并输出方法路径上的每个节点上耗时

tt - 方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测

tt命令是最有用的命令之一。
如何理解tt呢,相当于将请求快照保存了一份,可以随时调阅。

tt使用

tt -t com.example.controller.RedisController keys
-t, --time-tunnel 时空隧道(相当于快照),这个参数必传

tt -t -n -m com.example.controller.RedisController keys
-n --limits 限制记录条数,如果请求足够多,瞬间可能撑爆内存。
-m --maxMatch 限制匹配类的数量,例如String类,那么匹配的类太多。

-t
tt 命令有很多个主参数,-t 就是其中之一。这个参数的表明希望记录下类 *Test 的 print 方法的每次执行情况。

-n 3
当你执行一个调用量不高的方法时可能你还能有足够的时间用 CTRL+C 中断 tt 命令记录的过程,但如果遇到调用量非常大的方法,瞬间就能将你的 JVM 内存撑爆。

此时你可以通过 -n 参数指定你需要记录的次数,当达到记录次数时 Arthas 会主动中断 tt 命令的记录过程,避免人工操作无法停止的情况。

-m 1
通过 -m 参数指定 Class 匹配的最大数量,防止匹配到的 Class 数量太多导致 JVM 挂起,默认值是 50。

tt 删除

删除单条:

tt -d -i 1001 # 注:删除时-i必填,否则报错(因为不指定索引谁知道该删除哪条呢?)
	-i, --index <value>
tt -d 1001 # 错误的命令

报错:
Error during processing the command:
java.lang.IllegalArgumentException, message:Time fragment index is expected,
please type -i to specify
, please check $HOME/logs/arthas/arthas.log for more details.

这句说的很明显了,需要指定索引。 至于最后一句是通用的语句,让看日志呢。

删除全部:
tt --delete-all # 这个没报错,全都删除了

tt文档(命令行)
[arthas@22560]$ help tt
 USAGE:
   tt [-d] [--delete-all] [--exclude-class-pattern <value>] [-x <value>] [-h] [-i <value>] [-n <value>] [-l] [--listenerId <value>]
  [-m <value>] [-p] [-E] [--replay-interval <value>] [--replay-times <value>] [-s <value>] [-M <value>] [-t] [-v] [-w <value>] [cla
 ss-pattern] [method-pattern] [condition-express]

 SUMMARY:
   Time Tunnel
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 EXAMPLES:
   tt -t *StringUtils isEmpty
   tt -t *StringUtils isEmpty params[0].length==1
   tt -l
   tt -i 1000
   tt -i 1000 -w params[0]
   tt -i 1000 -p
   tt -i 1000 -p --replay-times 3 --replay-interval 3000
   tt -s '{params[0] > 1}' -w '{params}'
   tt --delete-all

 WIKI:
   https://arthas.aliyun.com/doc/tt

 OPTIONS:
 -d, --delete                                Delete time fragment specified by index
     --delete-all                            Delete all the time fragments
     --exclude-class-pattern <value>         exclude class name pattern, use either '.' or '/' as separator
 -x, --expand <value>                        Expand level of object (1 by default)
 -h, --help                                  this help
 -i, --index <value>                         Display the detailed information from specified time fragment
 -n, --limits <value>                        Threshold of execution times, default value 100
 -l, --list                                  List all the time fragments
     --listenerId <value>                    The special listenerId
 -m, --maxMatch <value>                      The maximum of matched class.
 -p, --play                                  Replay the time fragment specified by index
 -E, --regex                                 Enable regular expression to match (wildcard matching by default)
     --replay-interval <value>               replay interval  for  play tt with option r greater than 1
     --replay-times <value>                  execution times when play tt
 -s, --search-express <value>                Search-expression, to search the time fragments by ognl express.
                                             The structure of 'advice' like conditional expression
 -M, --sizeLimit <value>                     Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
 -t, --time-tunnel                           Record the method invocation within time fragments
 -v, --verbose                               Enables print verbose information, default value false.
 -w, --watch-express <value>                 watch the time fragment by ognl express.
                                             Examples:
                                               params
                                               params[0]
                                               'params[0]+params[1]'
                                               '{params[0], target, returnObj}'
                                               returnObj
                                               throwExp
                                               target
                                               clazz
                                               method
 <class-pattern>                             Path and classname of Pattern Matching
 <method-pattern>                            Method of Pattern Matching
 <condition-express>                         Conditional expression in ognl style, for example:
                                               TRUE  : 1==1
                                               TRUE  : true
                                               FALSE : false
                                               TRUE  : 'params.length>=0'
                                               FALSE : 1==2
                                               '#cost>100'

watch - 方法执行数据观测

watch主要用于监控查看方法的参数等。
测试需要这么测。
1、先执行命令监控。
2、再调用该方法,上面的监控就会打印指定的输出。

怎么感觉这个功能日志就可以做到呢?

watch例子

监控所有参数:

watch com.example.controller.RedisController keys "params"
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 85 ms, listenerId: 8

当方法到达后,输出内容:
method=com.example.controller.RedisController.keys location=AtExit
ts=2024-06-27 14:28:39; [cost=34.9303ms] result=@Object[][
    @RedisMapRequest[RedisMapRequest(key=set1, sonKey=null, sonValue=null, map=null)],
]

监控第一个参数:

watch com.example.controller.RedisController keys "params[0]"  # 第一个参数

监控参数的size:
watch com.taobao.container.Test test "params[0].size()"

那么问题来了,如何监控返回结果?
这3个分别表示入参,目标,返回结果。

{params, target, returnObj}

3个参数一起写,只会输出第三个参数,所以就写一个吧:
watch com.example.controller.RedisController keys "params, target, returnObj" # 3个都写

watch com.example.controller.RedisController keys "returnObj" # 只写一个

watch target例子

watch com.example.controller.RedisController keys "target" # target

[arthas@22560]$ watch com.example.controller.RedisController keys "target"
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 88 ms, listenerId: 15

返回结果:
method=com.example.controller.RedisController.keys location=AtExit
ts=2024-06-27 15:04:31; [cost=25.5637ms] result=@RedisController[
    age=@Integer[2],
    logger=@Logger[Logger[com.example.controller.RedisController]],
    redisTemplate=@RedisTemplate[org.springframework.data.redis.core.RedisTemplate@5b4f914],
]

target会返回方法及所属磊信息。

watch例子2
watch文档(界面)

watch 的参数比较多,主要是因为它能在 4 个不同的场景观察对象。

参数名称参数说明
class-pattern类名表达式匹配
method-pattern函数名表达式匹配
express观察表达式,默认值:{params, target, returnObj}
condition-express条件表达式
[b]函数调用之前观察
[e]函数异常之后观察
[s]函数返回之后观察
[f]函数结束之后(正常返回和异常返回)观察
[E]开启正则表达式匹配,默认为通配符匹配
[x:]指定输出结果的属性遍历深度,默认为 1,最大值是 4
[m <arg>]指定 Class 最大匹配数量,默认值为 50。长格式为[maxMatch <arg>]

这里重点要说明的是观察表达式,观察表达式的构成主要由 ognl 表达式组成,所以你可以这样写"{params,returnObj}",只要是一个合法的 ognl 表达式,都能被正常支持。

观察的维度也比较多,主要体现在参数 advice 的数据结构上。Advice 参数最主要是封装了通知节点的所有信息。请参考表达式核心变量中关于该节点的描述。

特殊用法请参考:https://github.com/alibaba/arthas/issues/71
OGNL 表达式官网:https://commons.apache.org/proper/commons-ognl/language-guide.html

watch文档(命令行)

help watch。

[arthas@22560]$ help watch
 USAGE:
   watch [-b] [-e] [--exclude-class-pattern <value>] [-x <value>] [-f] [-h] [-n <value>] [--listenerId <value>] [-m <value>] [-E] [
 -M <value>] [-s] [-v] class-pattern method-pattern [express] [condition-express]

 SUMMARY:
   Display the input/output parameter, return object, and thrown exception of specified method invocation
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 Examples:
   watch org.apache.commons.lang.StringUtils isBlank
   watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj, throwExp}' -x 2
   watch *StringUtils isBlank params[0] params[0].length==1
   watch *StringUtils isBlank params '#cost>100'
   watch -f *StringUtils isBlank params
   watch *StringUtils isBlank params[0]
   watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]
   watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter
   watch OuterClass$InnerClass

 WIKI:
   https://arthas.aliyun.com/doc/watch

 OPTIONS:
 -b, --before                                Watch before invocation
 -e, --exception                             Watch after throw exception
     --exclude-class-pattern <value>         exclude class name pattern, use either '.' or '/' as separator
 -x, --expand <value>                        Expand level of object (1 by default), the max value is 4
 -f, --finish                                Watch after invocation, enable by default
 -h, --help                                  this help
 -n, --limits <value>                        Threshold of execution times
     --listenerId <value>                    The special listenerId
 -m, --maxMatch <value>                      The maximum of matched class.
 -E, --regex                                 Enable regular expression to match (wildcard matching by default)
 -M, --sizeLimit <value>                     Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
 -s, --success                               Watch after successful invocation
 -v, --verbose                               Enables print verbose information, default value false.
 <class-pattern>                             The full qualified class name you want to watch
 <method-pattern>                            The method name you want to watch
 <express>                                   The content you want to watch, written by ognl. Default value is '{params, target, ret
                                             urnObj}'
                                             Examples:
                                               params
                                               params[0]
                                               'params[0]+params[1]'
                                               '{params[0], target, returnObj}'
                                               returnObj
                                               throwExp
                                               target
                                               clazz
                                               method
 <condition-express>                         Conditional expression in ognl style, for example:
                                               TRUE  : 1==1
                                               TRUE  : true
                                               FALSE : false
                                               TRUE  : 'params.length>=0'
                                               FALSE : 1==2
                                               '#cost>100'

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/760541.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

以太网交换机原理

没有配置&#xff0c;比较枯燥&#xff0c;二可以认识线缆&#xff0c; 三比较重要&#xff0c;慢慢理解&#xff0c;事半功倍。 各位老少爷们&#xff0c;在下给大家说段以太网交换机原理&#xff0c;说得不好大家多多包涵&#xff0c;说得好呢&#xff0c;大家叫个好&#x…

Debugging using Visual Studio Code

One of the key features of Visual Studio Code is its great debugging support. VS Code’s built-in debugger helps accelerate your edit, compile, and debug loop. Debugger extensions VS Code 内置了对 Node.js 运行时的调试支持,可以调试 JavaScript、TypeScript…

Web3 前端攻击:原因、影响及经验教训

DeFi的崛起引领了一个创新和金融自由的新时代。然而&#xff0c;这种快速增长也吸引了恶意行为者的注意&#xff0c;他们试图利用漏洞进行攻击。尽管很多焦点都集中在智能合约安全上&#xff0c;但前端攻击也正在成为一个重要的威胁向量。 前端攻击的剖析 理解攻击者利用前端漏…

LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection

LW-DETR: A Transformer Replacement to YOLO for Real-Time Detection 论文链接&#xff1a;http://arxiv.org/abs/2406.03459 代码链接&#xff1a;https://github.com/Atten4Vis/LW-DETR 一、摘要 介绍了一种轻量级检测变换器LWDETR&#xff0c;它在实时物体检测方面超越…

matrixone集群搭建、启停、高可用扩缩容和连接数据库

1. 部署 Kubernetes 集群 由于 MatrixOne 的分布式部署依赖于 Kubernetes 集群&#xff0c;因此我们需要一个 Kubernetes 集群。本篇文章将指导你通过使用 Kuboard-Spray 的方式搭建一个 Kubernetes 集群。 准备集群环境 对于集群环境&#xff0c;需要做如下准备&#xff1a…

数据结构-期末复习题

数据结构-期末复习题 一、选择题 1、在数据结构中&#xff0c;与所使用的计算机无关的是数据的&#xff08; ) 结构。 A. 存储B. 物理C. 逻辑D. 物理和存储 【答案】C 【解析】暂无解析2、算法分析的两个主要方面是 ( )。 A. 正确性和简单性B. 可读性和文档性C. 空间复杂度…

测评推荐:企业管理u盘的软件有哪些?

U盘作为一种便携的存储设备&#xff0c;方便易用&#xff0c;被广泛应用于企业办公、个人学习及日常工作中。然而&#xff0c;U盘的使用也带来了数据泄露、病毒传播等安全隐患。为了解决这些问题&#xff0c;企业管理U盘的软件应运而生。 本文将对市面上流行的几款U盘管理软件…

【SQLmap】常用命令

文章目录 实际使用案例常用命令基本命令数据库指纹识别用户信息用户权限数据库枚举数据导出密码哈希操作系统命令执行文件操作代理和网络参数指定保存恢复自动搜索注入智能模式等级设置自动注入WAF 绕过杂项帮助和支持 SQLmap 是一款开源的自动化 SQL 注入检测和利用工具&#…

Web Based Quiz System v1.0 SQL 注入漏洞(CVE-2022-32991)

前言 CVE-2022-32991 是一个影响 Web Based Quiz System v1.0 的 SQL 注入漏洞。这个漏洞存在于 welcome.php 文件中的 eid 参数处。攻击者可以通过此漏洞在数据库中执行任意 SQL 语句&#xff0c;从而获取、修改或删除数据库中的数据。 具体细节如下&#xff1a; 攻击向量&…

【Spring Boot】Java 持久层 API:JPA

Java 持久层 API&#xff1a;JPA 1.Spring Data1.1 主要模块1.2 社区模块 2.JPA3.使用 JPA3.1 添加 JPA 和 MySQL 数据库的依赖3.2 配置数据库连接信息 4.了解 JPA 注解和属性4.1 常用注解4.2 映射关系的注解4.3 映射关系的属性 5.用 JPA 构建实体数据表 1.Spring Data Spring…

VMware虚拟机迁移:兼用性踩坑和复盘

文章目录 方法失败情况分析&#xff1a;参考文档 方法 虚拟机关机&#xff0c;整个文件夹压缩后拷贝到新机器中&#xff0c;开机启用即可 成功的情况&#xff1a; Mac (intel i5) -> Mac (intel i7)Mac (intel, MacOS - VMware Fusion) -> DELL (intel, Windows - VMw…

flask的基本使用2

上一篇我们介绍了基本使用方法 flask使用 【 1 】基本使用 from flask import Flask# 1 实例化得到对象 app Flask(__name__)# 2 注册路由--》写视图函数 app.route(/) def index():# 3 返回给前端字符串return hello worldif __name__ __main__:# 运行app&#xff0c;默认…

Linux【环境 CenOS7】部分软件安装链接整理

优质博文&#xff1a;IT-BLOG-CN 一、开启网络 【问题】&#xff1a; 刚安装完CentOS&#xff0c;当ping www.baidu.com时&#xff0c;ping不通&#xff1b; 【解决】&#xff1a; 进入cd /etc/sysconfig/network-scripts/我这里修改的是ifcfg-ens33文件&#xff0c;将ONBOOT…

论文阅读_基于嵌入的Facebook搜索

英文名称&#xff1a;Embedding-based Retrieval in Facebook Search 中文名称&#xff1a;基于嵌入式检索的Facebook搜索 时间&#xff1a;Wed, 29 Jul 2020 (v2) 地址&#xff1a;https://arxiv.org/abs/2006.11632 作者&#xff1a;Jui-Ting Huang, Ashish Sharma, Shuying …

【计算机网络仿真】b站湖科大教书匠思科Packet Tracer——实验12 默认路由和特定主机路由

一、实验目的 1.验证默认路由和特定主机路由的作用&#xff1b; 二、实验要求 1.使用Cisco Packet Tracer仿真平台&#xff1b; 2.观看B站湖科大教书匠仿真实验视频&#xff0c;完成对应实验。 三、实验内容 1.构建网络拓扑&#xff1b; 2.验证验证默认路由和特定主机路由…

MySQL高级-索引-使用规则-SQL提示(use、ignore、force)

文章目录 1、查看表 tb_user2、展示索引3、为profession、age、status创建 联合索引4、查询 profession软件工程5、执行计划 profession软件工程6、创建profession单列索引7、再次执行计划 profession软件工程8、SQL提示8.1、use index(idx_user_pro)8.2、ignore index(idx_use…

九浅一深Jemalloc5.3.0 -- ①浅*编译调试

目前市面上有不少分析Jemalloc老版本的博文&#xff0c;但5.3.0却少之又少。而且5.3.0的架构与之前的版本也有较大不同&#xff0c;本着“与时俱进”、“由浅入深”的宗旨&#xff0c;我将逐步分析Jemalloc5.3.0的实现。5.3.0的特性请见Releases jemalloc/jemalloc GitHub 另…

dB分贝入门

主要参考资料&#xff1a; dB&#xff08;分贝&#xff09;定义及其应用: https://blog.csdn.net/u014162133/article/details/110388145 目录 dB的应用一、声音的大小二、信号强度三、增益 dB的应用 一、声音的大小 在日常生活中&#xff0c;住宅小区告知牌上面标示噪音要低…

实战精选 | 在NPU上运行BGE embedding模型,提升RAG整体性能

点击蓝字 关注我们,让开发变得更有趣 作者 | 杨亦诚 排版 | 李擎 介绍 BGE全称是BAAI General Embedding&#xff0c;即北京智源人工智能研究院通用Embedding模型&#xff0c;它可以将任意文本映射到低维的稠密向量&#xff0c;在文本向量化任务中得到了广泛的应用。可以看到在…

180Kg大载重多旋翼无人机技术详解

一、机体结构与材料 180Kg大载重多旋翼无人机在机体结构上采用了高强度轻量化设计。其主体框架采用航空铝合金材料&#xff0c;既保证了机体的结构强度&#xff0c;又减轻了整体重量。同时&#xff0c;关键部位如连接件、旋翼支撑臂等则采用碳纤维复合材料&#xff0c;以进一步…