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 isBlankmonitor org.apache.commons.lang.StringUtils isBlank -c 5monitor org.apache.commons.lang.StringUtils isBlank params[0]!=nullmonitor -b org.apache.commons.lang.StringUtils isBlank params[0]!=nullmonitor -E org\.apache\.commons\.lang\.StringUtils isBlankWIKI:https://arthas.aliyun.com/doc/monitorOPTIONS:
-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==1TRUE : trueFALSE : falseTRUE : '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 ttUSAGE: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>] [class-pattern] [method-pattern] [condition-express]SUMMARY:Time TunnelThe express may be one of the following expression (evaluated dynamically):target : the objectclazz : the object's classmethod : the constructor or methodparams : the parameters array of methodparams[0..n] : the element of parameters arrayreturnObj : the returned object of methodthrowExp : the throw exception of methodisReturn : the method ended by returnisThrow : the method ended by throwing exception#cost : the execution time in ms of method invocationEXAMPLES:tt -t *StringUtils isEmptytt -t *StringUtils isEmpty params[0].length==1tt -ltt -i 1000tt -i 1000 -w params[0]tt -i 1000 -ptt -i 1000 -p --replay-times 3 --replay-interval 3000tt -s '{params[0] > 1}' -w '{params}'tt --delete-allWIKI:https://arthas.aliyun.com/doc/ttOPTIONS:-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:paramsparams[0]'params[0]+params[1]''{params[0], target, returnObj}'returnObjthrowExptargetclazzmethod<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==1TRUE : trueFALSE : falseTRUE : '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 watchUSAGE: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 invocationThe express may be one of the following expression (evaluated dynamically):target : the objectclazz : the object's classmethod : the constructor or methodparams : the parameters array of methodparams[0..n] : the element of parameters arrayreturnObj : the returned object of methodthrowExp : the throw exception of methodisReturn : the method ended by returnisThrow : the method ended by throwing exception#cost : the execution time in ms of method invocationExamples:watch org.apache.commons.lang.StringUtils isBlankwatch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj, throwExp}' -x 2watch *StringUtils isBlank params[0] params[0].length==1watch *StringUtils isBlank params '#cost>100'watch -f *StringUtils isBlank paramswatch *StringUtils isBlank params[0]watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilterwatch OuterClass$InnerClassWIKI:https://arthas.aliyun.com/doc/watchOPTIONS:-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, returnObj}'Examples:paramsparams[0]'params[0]+params[1]''{params[0], target, returnObj}'returnObjthrowExptargetclazzmethod<condition-express> Conditional expression in ognl style, for example:TRUE : 1==1TRUE : trueFALSE : falseTRUE : 'params.length>=0'FALSE : 1==2'#cost>100'
相关文章:

arthas监控工具笔记(二)monior等
文章目录 monitor/watch/trace 相关monitormonitor例子monitor -c <value>monitor -m <vaule>monitor 条件表达式monitor -b monitor文档(界面描述)monitor文档(help) stack - 输出当前方法被调用的调用路径trace - 方法内部调用路径,并输出方法路径上的…...

【mybatis】mybatis-plus中主键生成策略
1、简介 MyBatis-Plus 中的主键生成策略是一个关键特性,它决定了如何为新插入的行生成唯一标识符(即主键)。MyBatis-Plus 提供了多种主键生成策略,以满足不同场景下的需求。 2、常见主键生成策略 1. AUTO(数据库ID自…...

模型情景制作-如何制作棕榈树
夏天,沙滩,海景,棕榈树,外加美女,想象下热带海滨的样子吧 可是口年的上班族没有多少机会去到海滩,肿么办?我们自己DIY一个海滨情景摆在办公桌上吧~~~ 什么什么?棕榈树不会做…...

# mysql 中文乱码问题分析
mysql 中文乱码问题分析 一、问题分析: MySQL 中文乱码通常是因为字符集设置不正确导致的。MySQL 有多种字符集,如 latin1、utf8、utf8mb4 等,如果在创建数据库、数据表或者字段时没有指定正确的字符集,或者在插入数据时使用了与…...

[小试牛刀-习题练]《计算机组成原理》之指令系统
一、选择题 0.【指令-课本习题】某计算机按字节编址,指令字长固定且只有两种指令格式,其中三地址指令29条,二地址指令107条,每个地址字段为6位,则指令字长至少应该是(A) A.24位 B. 26位 C. 28位…...

JAVA 实现拍卖框架及拍卖详情流程介绍(包含代码示咧)
本人详解 作者:王文峰,参加过 CSDN 2020年度博客之星,《Java王大师王天师》 公众号:JAVA开发王大师,专注于天道酬勤的 Java 开发问题中国国学、传统文化和代码爱好者的程序人生,期待你的关注和支持!本人外号:神秘小峯 山峯 转载说明:务必注明来源(注明:作者:王文峰…...

力扣1177.构建回文串检测
力扣1177.构建回文串检测 因为子串可以重新排序 因此考虑一下什么情况需要替换字母1.当前有一个字母的数量为奇数 需要替换的次数为0 2.当前有二个字母的数量为奇数 需要替换的次数为1 (奇数个a 奇数个b 需要将b -> a) 3.当前有三个字母的数量为奇数 需要替换的次数为1 4.当…...

Vue跨域获取ip和ip位置城市等归属地信息
由于端口设置与查询服务器不一致,所以不能直接从ip138网上抓取,只能跨域查询。实现跨域查询,简单的方法是使用jsonp方式,只支持get请求,同时也需要查询的服务器支持jsonp。这时找到了腾讯位置服务。参考文章࿰…...

缺失的第一个正数
给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。 请你实现时间复杂度为 O(n) 并且只使用常数级别额外空间的解决方案。 示例 1: 输入:nums [1,2,0] 输出:3 解释:范围 [1,2] 中的数字都在数组…...

mac 上 Docker Desktop的免费开源的替代工具Colima
当谈到在macOS上运行容器时,Docker长期以来一直是首选。但是,必须解决使用适用于macOS的Docker Desktop时出现的一些限制,特别是对于大中型公司,最大的问题是需要购买许可证。另外,macOS 版Docker Desktop的性能问题也…...

C语言 -- 函数
C语言 -- 函数 1. 函数的概念2. 库函数2.1 标准库和头文件2.2 库函数的使用方法2.2.1 功能2.2.2 头文件包含2.2.3 实践2.2.4 库函数文档的一般格式 3. 自定义函数3.1 函数的语法形式3.2 函数的举例 4. 形参和实参4.1 实参4.2 形参4.3 实参和形参的关系 5. return 语句6. 数组做…...

Cesium 立式雷达扫描
Cesium 立式雷达扫描 自定义 Primitive 实现支持水平和垂直交替扫描...

Oracle HTTP Server(OHS)与Oracle数据库的紧密绑定
Oracle HTTP Server(OHS)与Oracle数据库的紧密绑定通常是通过一系列的配置和集成步骤来实现的。以下是这些步骤的详细归纳,包括必要的分点表示和参考信息: 一、安装和配置Oracle HTTP Server 安装OHS: 在安装Oracle…...

mmcv安装失败及解决方案
假如想安装的版本是mmcv1.4.0, 但是pip install mmcv1.4.0总是失败,若是直接pip install mmcv会安装成功,但是安装的就是最新版本,后面代码跑起来还会报错,怎么办呢? 接下来分享一个mmcv指定版本安装的方式。 网页&a…...

国产强大免费WAF, 社区版雷池动态防护介绍
雷池WAF,基于智能语义分析的下一代 Web 应用防火墙 使用情况 我司于2023年4月23日对雷池进行测试,测试一个月后,于2023年5月24日对雷池进行正式切换,此时版本为1.5.1。 里程碑纪念 后续一直跟随雷池进行版本升级,当前…...

【Django】网上蛋糕项目商城-首页
概念 本文在上一文章搭建完数据库,以及创建好项目之后,以及前端静态文件后,对项目的首页功能开发。 后端代码编写 在views.py文件中创建方法,连接数据库,并获取首页需要的数据 def getGoodsList(type):# 获取所有横…...

Vue 父子页面使用指南
Vue3父子页面使用指南 Vue3作为一种现代化的前端框架,提供了强大的组件化功能,使得页面开发更加模块化和可维护。本文将深入探讨Vue3中父子页面的使用方法,包括如何传递参数、父组件如何调用子组件的方法,以及父子页面的加载原理…...

TVBox自定义配置+软件密码版本
apk地址 : https://gitee.com/wheat-wheat/kekeda-duck-apk 1、安装安卓SDK Android SDK Windows 安装及环境配置教程_sdk manager windows-CSDN博客 修改点: 基础配置: java版本:...

Java单体架构项目_云霄外卖-特殊点
项目介绍: 定位: 专门为餐饮企业(餐厅、饭店)定制的一款软件商品 分为: 管理端:外卖商家使用 用户端(微信小程序):点餐用户使用。 功能架构: (…...

一文搞懂 java 线程池:ScheduledThreadPool 和 WorkStealingPool 原理
你好,我是 shengjk1,多年大厂经验,努力构建 通俗易懂的、好玩的编程语言教程。 欢迎关注!你会有如下收益: 了解大厂经验拥有和大厂相匹配的技术等 希望看什么,评论或者私信告诉我! 文章目录 一…...

轮换IP是什么?——深入了解轮换IP的特点
大家在日常上网时,可能听说过“轮换IP”这个词。那么,轮换IP到底是什么?它有哪些特点?今天,我们就来揭开轮换IP的神秘面纱。 什么是轮换IP? 简单来说,轮换IP是指定期更换上网时使用的IP地址。…...

中英双语介绍美国的州:华盛顿州(Washington)
中文版 华盛顿州简介 华盛顿州(Washington)位于美国太平洋西北地区,以其壮丽的自然景观和蓬勃发展的经济闻名。以下是对华盛顿州的详细介绍,包括其地理位置、人口、经济、教育、文化和主要城市。 地理位置 华盛顿州北接加拿大…...

美工画师必看!AI绘画Stable Diffusion 一键生成 B 端图标教程,轻松制作商业可用的设计图标,从此告别加班!(附安装包)
大家好,我是画画的小强 在日常工作中,设计师在应对运营和UI设计的B端图标时,常常面临大量的构思、制作和渲染等工作,耗时耗力。我们可以利用Stable Diffusion(以下简称SD)结合AI的方式,帮助设计师优化图标的设计流程&…...

使用表单系统快速搭建邀请和签到系统
在组织活动时,邀请和签到环节往往是活动成败的关键之一。传统的纸质邀请和签到方式不仅费时费力,还容易出现各种问题,例如名单遗漏、签到混乱等。而使用TDuckX“搭建邀请和签到系统”将彻底改变这一现状,为活动组织者提供了一种高…...

Vue 3 入门与精通:为初学者打造的全面学习指南
引言: Vue.js,这款由尤雨溪创建的轻量级前端框架,以其简洁的API、双向数据绑定和组件化的开发模式,深受广大开发者喜爱。Vue 3 的发布,带来了更多的性能优化和功能增强,为开发者提供了更广阔的空间。本文旨…...

React+TS前台项目实战(二十四)-- 全局常用绘制组件Qrcode封装
文章目录 前言Qrcode组件1. 功能分析2. 代码详细注释3. 使用方式4. 效果展示(pc端 / 移动端) 总结 前言 今天要封装的Qrcode 组件,是通过传入的信息,绘制在二维码上,可用于很多场景,如区块链项目中的区块显示交易地址时就可以用到…...

寄5公斤哪个快递便宜?寄10多斤的物品怎么寄最划算?
作为一个频繁需要寄东西的大学生,每次选择快递公司都是一件头疼的事。尤其是寄5公斤左右的包裹,既要考虑价格,又要看服务质量。今天,我就来分享一些寄5公斤包裹省钱的干货,希望能帮到大家。云木寄快递首先要推荐的就是…...

【postgresql】索引
见的索引类型: B-tree 索引:这是最常用的索引类型,适用于大多数查询。B-tree索引可以高效地处理范围查询。 Hash 索引:适用于等值查询,但不支持范围查询。 GiST 索引:通用搜索树(GiST…...

2D Game Kit在unity的使用
本文参考: 如何制作游戏?【不需要编程 __】新手30分钟 学会制作2D游戏!_ 如何制作游戏 _ unity教学 _ 制作游戏 _ 2d游戏_哔哩哔哩_bilibili 1、下载2d game kit 新建一个unity工程,进入该工程后,在Window -> Ass…...

使用中国大陆镜像源安装最新版的 docker Deamon
在一个智算项目交付过程中,出现了新建集群中的全部 docker server V19 进程消失、仅剩 docker server 的 unix-socket 存活的现象。 为了验证是否是BD产品研发提供的产品deploy语句缺陷,需要在本地环境上部署一个简单的 docker Deamon 环境。尴尬的是&a…...