Rancher CLI进行项目监控(取文件、Log查看、Arthas)

您所在的位置:网站首页 arthas启动 Rancher CLI进行项目监控(取文件、Log查看、Arthas)

Rancher CLI进行项目监控(取文件、Log查看、Arthas)

2024-05-26 22:35| 来源: 网络整理| 查看: 265

在项目在部署平台上运行的时候,作为开发想要监控平台上运行项目的情况,可以使用Rancher管理端平台

但是网页上使用WebSocket去查看运行命令行,我个人感觉是有点卡的、操作效果不太好并且无法进行相关的文件操作

因此想要将这些操作都在windows上终端中显示出来

一、配置好Rancher CLI和kubectl环境

Rancher CLi下载地址 最好参考官方中文文档

Kubectl下载地址

二、Rancher Cli登录和kubectl登录参考

在Rancher UI平台获取API 端点 创建长期的API 密钥

代码语言:shell复制rancher login https:// --token

在Rancher UI平台下载KubeConfig.yaml放入kubectl的文件缓存.kube文件夹下

三、Rancher kubectl命令常用(下载文件)1.查看集群空间代码语言:shell复制rancher namespaces2.查看pod节点代码语言:shell复制rancher kubectl get po -n myproject3.进入指定pod节点容器代码语言:shell复制kubectl exec -it mypod1-7c8848-8z8848 -n myproject /bin/bash4..进入指定pod节点容器新方式代码语言:shell复制kubectl exec -it mypod1-7c8848-8z8848 -n myproject -- /bin/bash5.复制app.jar文件到Windows命令行当前路径(用于取jar包或者项目文件)代码语言:shell复制kubectl cp -n myproject mypod1-7c8848-8z8848:/app.jar ./app.jar四、Rancher kubectl命令常用(窗口查看日志流)1.直接实时流式查看日志的功能代码语言:powershell复制kubectl logs -f -n myproject mypod1-7c8848-8z88482.不加载以前的日志 从前五行开始加载代码语言:powershell复制kubectl logs -f --tail 5 -n myproject mypod1-7c8848-8z88483.保存30分钟以内日志到Windows当前路径代码语言:powershell复制kubectl logs --since=30m -n > logs.txt五、Arthas操作

推荐使用IDEA Arthas插件 参考文档:爱上Java诊断利器Arthas之Arthas idea plugin 的前世今生

1.UTF-8编码启动Arthas

Arthas 向控制台输出内容使用的默认编码,可以通过指定 file.encoding 设置默认编码。

代码语言:shell复制java -Dfile.encoding=UTF-8 -jar arthas-boot.jar

2.sc | arthas 获取classloader的hash 值

Arthas官方文档

如果要使用Ognl表达式来实现相关的操作 就需要获取获取classloader的hash 值

代码语言:shell复制sc -d com.xxx.xxx.xxxServiceImpl

3.查看静态常量

根据唯一类名下的常量名获取

代码语言:shell复制getstatic com.xxx.xxx.xxxServiceImpl xxxTemplatePrefix -x 3

Ognl表达式获取

代码语言:shell复制ognl -x 3 '@com.xxx.xxxServiceImpl@xxxTemplatePrefix ' -c 38848be2

Ognl表达式替换静态常量

代码语言:shell复制ognl -x 3 '#[email protected]@class.getDeclaredField("xxxTemplatePrefix "),#field.setAccessible(true),#field.set(null,"设置的值")'

4.调用spring context invoke

有三种方式

第一种自主配置 (要额外配置代码 算了)

第二种 watch 支持在spring mvc场景 通过watch 间接的获取spring context

第三种 通过tt 获取spring context

5.监听方法

监听方法需要调用经过激活

代码语言:shell复制watch com.xxx.xxxController createXxx '{params,returnObj,throwExp}' -n 5 -x 3

6.获取Spring环境变量

在yaml文件时,这种基本上参照properties的形式 所以在查找yml文件的环境变量的时候 需要转换成一行的形式

举例:查找数据库地址环境变量

代码语言:shell复制vmtool -x 3 --action getInstances --className org.springframework.core.env.ConfigurableEnvironment --express 'instances[0].getProperty("spring.datasource.url") ' -c 38848be2

7.反编译 Decompile Class Jad

获取这个getUsername方法的反编译结果

代码语言:shell复制jad --source-only com.xxx.impl.xxxServiceImpl getUsername


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3