cat本地打包安装
因为org.unidal包,plexus包在maven仓库公有仓库拉取不到,导致本地编码打包失败。
通过下载相关jar,在本地手动安装到仓库。
mvn install:install-file -DgroupId=org.unidal.framework -DartifactId=test-framework -Dversion=2.4.0 -Dpackaging=jar -Dfile=/Users/lichangwu/Desktop/xy-wms-service/test-framework-2.4.0.jar
cat-client安装到本地
mvn install:install-file “-DgroupId=com.dianping.cat“ “-DartifactId=cat-client“ “-Dversion=3.0.0“ “-Dpackaging=jar“ “-Dfile=/Users/lichangwu/workspace-xy/cat-3.0.0/lib/java/jar/cat-client-3.0.0.jar”
最新版本客户端已经不需要依赖org.unidal.*,只要配置好maven或者私服,便可以拉取依赖文件。
修改CAT_HOME启动
当修改了cat默认的配置文件路径时,需要指定CAT_HOME
CAT_HOME=/Users/lichangwu/workspace-soft/cat/data/appdatas/cat/
一定要以/结尾,否则cat找不到配置文件
私服配置cat依赖
mac部署
因为mac对/data目录只读权限的原因,我们可以修改CAT_HOME
设置CAT_HOME环境变量
在tomcat的bin目录下创建setenv.sh脚本
export CAT_HOME=/Users/lichangwu/workspace-soft/cat/data/appdatas/cat/
CATALINA_OPTS="$CATALINA_OPTS -server -DCAT_HOME=$CAT_HOME -Djava.awt.headless=true -Xms2G -Xmx2G -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewSize=1024m -XX:MaxNewSize=2014m -XX:SurvivorRatio=10 -XX:+UseParNewGC -XX:ParallelGCThreads=4"
数据连接工具
数据库版本不同,对datasources.xml中的驱动,可能需要自己手动添加到tomcat的lib目录中,比如mysql-connect.jar
单机部署参看
可以参考
https://m.imooc.com/article/323393
设置dashboard自动刷新
以chrome为例,在应用商店搜索并安装Auto Refreash Page 插件功能
点击右上角扩展程序图标
将自动刷新插件设置固定
浏览器右上角出现自动刷新图标
点击,设置刷新时间间隔
启动即可
报表单位修正
cat默认的报表配置是供服务端采样使用
对于集成cat-client.3.0.0的客户端,需要少做调整,在原来的配置下,追加以下配置:
在调整心跳报表的过程中,
<!-- 添加如下cat-client 3.0.0相关指标展示 -->
<group id="cat.status" order="13">
<metric id="cat.status.send.sample.ratio" unit="1" delta="false" order="1" title="Cat采样比例" lable="百分比" alert="false"/>
<metric id="cat.status.send.queue.size" unit="1" delta="false" order="2" title="Cat普通消息队列size" lable="个数" alert="false"/>
<metric id="cat.status.send.atomic.queue.size" unit="1" delta="false" order="3" title="Cat Atomic消息队列size" lable="个数" alert="false"/>
<metric id="cat.status.message.bytes" unit="M" delta="false" order="4" title="Cat上报消息容量" lable="MB" alert="false"/>
<metric id="cat.status.message.produced" unit="1" delta="false" order="5" title="Cat上报消息数量" lable="个数" alert="false"/>
<metric id="cat.status.message.overflowed" unit="1" delta="false" order="6" title="Cat丢弃消息数量" lable="个数" alert="false"/>
</group>
<group id="jvm.memory" order="14">
<metric id="jvm.memory.used" unit="M" delta="false" order="1" title="Jvm内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.used.percent" unit="1" delta="false" order="2" title="JVM内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.nonheap.used" unit="M" delta="false" order="3" title="Noheap内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.nonheap.used.percent" unit="1" delta="false" order="4" title="Noheap内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.eden.used" unit="M" delta="false" order="5" title="Eden内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.eden.used.percent" unit="1" delta="false" order="6" title="Eden内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.survivor.used" unit="M" delta="false" order="7" title="Survivor内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.survivor.used.percent" unit="1" delta="false" order="8" title="Survivor内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.oldgen.used" unit="M" delta="false" order="9" title="Oldgen内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.oldgen.used.percent" unit="1" delta="false" order="10" title="Oldgen内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.oldgen.used.percent.after.fullgc" unit="1" delta="false" order="11" title="Oldgen内存使用率(After Fullgc)" lable="百分比" alert="true"/>
<metric id="jvm.memory.perm.used" unit="M" delta="false" order="12" title="Perm内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.perm.used.percent" unit="1" delta="false" order="13" title="Perm内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.metaspace.used" unit="M" delta="false" order="14" title="MetaSpace内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.metaspace.used.percent" unit="1" delta="false" order="15" title="MetaSpace内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.memory.codecache.used" unit="M" delta="false" order="16" title="CodeCache内存使用量" lable="MB" alert="true"/>
<metric id="jvm.memory.codecache.used.percent" unit="1" delta="false" order="17" title="CodeCache内存使用率" lable="百分比" alert="true"/>
<metric id="jvm.nio.directbuffer.used" unit="M" delta="false" order="18" title="BufferPool direct对象使用内存" lable="MB" alert="true"/>
<metric id="jvm.nio.mapped.used" unit="M" delta="false" order="19" title="BufferPool mapped对象使用内存" lable="MB" alert="true"/>
</group>
<group id="jvm.gc" order="15">
<metric id="jvm.gc.count" unit="1" delta="false" order="1" title="Gc次数" lable="次数" alert="true"/>
<metric id="jvm.gc.time" unit="1" delta="false" order="2" title="Gc持续时长总和" lable="毫秒" alert="true"/>
<metric id="jvm.younggc.count" unit="1" delta="false" order="3" title="YoungGc次数" lable="次数" alert="true"/>
<metric id="jvm.younggc.time" unit="1" delta="false" order="4" title="YoungGc持续时长总和" lable="毫秒" alert="true"/>
<metric id="jvm.younggc.meantime" unit="1" delta="false" order="5" title="YoungGc平均时长" lable="毫秒" alert="true"/>
<metric id="jvm.fullgc.count" unit="1" delta="false" order="6" title="FullGc次数" lable="次数" alert="true"/>
<metric id="jvm.fullgc.time" unit="1" delta="false" order="7" title="FullGc持续时长总和" lable="毫秒" alert="true"/>
</group>
<group id="jvm.thread" order="16">
<metric id="jvm.thread.count" unit="1" delta="false" order="1" title="活动线程总数" lable="个数" alert="true"/>
<metric id="jvm.thread.daemon.count" unit="1" delta="false" order="2" title="活动daemon线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.totalstarted.count" unit="1" delta="false" order="3" title="累计创建线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.new.count" unit="1" delta="false" order="4" title="new状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.runnable.count" unit="1" delta="false" order="5" title="runnable状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.blocked.count" unit="1" delta="false" order="6" title="blocked状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.waiting.count" unit="1" delta="false" order="7" title="waiting状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.time_waiting.count" unit="1" delta="false" order="8" title="time_waiting状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.deadlock.count" unit="1" delta="false" order="9" title="deadlock状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.terminated.count" unit="1" delta="false" order="10" title="terminated状态的线程数" lable="个数" alert="true"/>
<metric id="jvm.thread.http.count" unit="1" delta="false" order="11" title="http线程数(http, catalina, @qtc)" lable="个数" alert="true"/>
<metric id="jvm.thread.cat.count" unit="1" delta="false" order="12" title="cat线程数(Cat, cat)" lable="个数" alert="true"/>
<metric id="jvm.thread.pigeon.count" unit="1" delta="false" order="13" title="pigeon线程数" lable="个数" alert="true"/>
</group>
<group id="http.status" order="17">
<metric id="http.count" unit="1" delta="false" order="1" title="http请求数量" lable="次数" alert="true"/>
<metric id="http.meantime" unit="1" delta="false" order="2" title="http请求平均耗时" lable="毫秒" alert="true"/>
<metric id="http.status400.count" unit="1" delta="false" order="3" title="4xx的http请求数量" lable="次数" alert="true"/>
<metric id="http.status500.count" unit="1" delta="false" order="4" title="5xx的http请求数量" lable="次数" alert="true"/>
</group>
<group id="jvm.classingloading" order="18">
<metric id="jvm.classloading.loaded.count" unit="1" delta="false" order="2" title="当前加载的类数量" lable="个数" alert="true"/>
<metric id="jvm.classloading.totalloaded.count" unit="1" delta="false" order="3" title="累计加载的类数量" lable="个数" alert="true"/>
<metric id="jvm.classloading.unloaded.count" unit="1" delta="false" order="4" title="累计卸载的类数量" lable="个数" alert="true"/>
</group>
<group id="system.process" order="19">
<metric id="system.load.average" unit="1" delta="false" order="1" title="系统负载" lable="个数" alert="true"/>
<metric id="cpu.system.load.percent" unit="1" delta="false" order="2" title="cpu使用率" lable="百分比" alert="true"/>
<metric id="cpu.jvm.load.percent" unit="1" delta="false" order="3" title="Jvm进程cpu使用率" lable="百分比" alert="true"/>
<metric id="system.process.used.phyical.memory" unit="M" delta="false" order="1" title="内存用量" lable="MB" alert="true"/>
<metric id="system.process.used.swap.size" unit="M" delta="false" order="1" title="交换空间用量" lable="MB" alert="true"/>
</group>
- 发现metric.title中包含字符中横线-,点号 .,心跳直方图中的数字tooltip提示会消失;
- 配置metric.alert=true即可在心跳报警配置中对指定的心跳指标进行监控
如何使用
告警设置
cat自身不提供告警功能,需要自行定义
1.配置默认告警人
2.配置告警url
<?xml version="1.0" encoding="utf-8"?>
<sender-config>
<sender id="mail" url="https://sba.trendsi.co/cat/alarm/lark" type="post" successCode="200" batchSend="true">
<par id="type=1500"/>
<par id="key=title,body"/>
<par id="re=jack"/>
<par id="to=${receiver}"/>
<par id="value=${title},${content}"/>
</sender>
</sender-config>
3.定义告警方法
@Slf4j
@RestController
@RequestMapping("/cat/alarm")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CatAlarmController {
private final MessageComponent messageComponent;
@RequestMapping(value = "/lark")
public String larkAlarm(@RequestParam String to, @RequestParam String value) {
log.info("--->>>>>>>>>>>>>to:{},value:{}", to, value);
String replace = value.replace("cat-web-server", "10.90.10.9:8080");
if (replace.contains("<br/><br/>")) {
String[] split = replace.split("<br/><br/>");
messageComponent.send(MessageType.Alarm_Message, split[0]);
} else {
messageComponent.send(MessageType.Alarm_Message, replace);
}
return "200";
}
}