cat本地打包安装

因为org.unidal包,plexus包在maven仓库公有仓库拉取不到,导致本地编码打包失败。

通过下载相关jar,在本地手动安装到仓库。

  1. 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安装到本地

  1. 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

  1. CAT_HOME=/Users/lichangwu/workspace-soft/cat/data/appdatas/cat/

一定要以/结尾,否则cat找不到配置文件

点评cat - 图1

私服配置cat依赖

点评cat - 图2

点评cat - 图3

点评cat - 图4

点评cat - 图5

mac部署

因为mac对/data目录只读权限的原因,我们可以修改CAT_HOME

设置CAT_HOME环境变量

在tomcat的bin目录下创建setenv.sh脚本

  1. export CAT_HOME=/Users/lichangwu/workspace-soft/cat/data/appdatas/cat/
  2. 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 - 图6

点击右上角扩展程序图标

点评cat - 图7

将自动刷新插件设置固定

点评cat - 图8

浏览器右上角出现自动刷新图标

点评cat - 图9

点击,设置刷新时间间隔

点评cat - 图10

启动即可

报表单位修正

cat默认的报表配置是供服务端采样使用

点评cat - 图11

对于集成cat-client.3.0.0的客户端,需要少做调整,在原来的配置下,追加以下配置:

  1. <!-- 添加如下cat-client 3.0.0相关指标展示 -->
  2. <group id="cat.status" order="13">
  3. <metric id="cat.status.send.sample.ratio" unit="1" delta="false" order="1" title="Cat采样比例" lable="百分比" alert="false"/>
  4. <metric id="cat.status.send.queue.size" unit="1" delta="false" order="2" title="Cat普通消息队列size" lable="个数" alert="false"/>
  5. <metric id="cat.status.send.atomic.queue.size" unit="1" delta="false" order="3" title="Cat Atomic消息队列size" lable="个数" alert="false"/>
  6. <metric id="cat.status.message.bytes" unit="M" delta="false" order="4" title="Cat上报消息容量" lable="MB" alert="false"/>
  7. <metric id="cat.status.message.produced" unit="1" delta="false" order="5" title="Cat上报消息数量" lable="个数" alert="false"/>
  8. <metric id="cat.status.message.overflowed" unit="1" delta="false" order="6" title="Cat丢弃消息数量" lable="个数" alert="false"/>
  9. </group>
  10. <group id="jvm.memory" order="14">
  11. <metric id="jvm.memory.used" unit="M" delta="false" order="1" title="Jvm内存使用量" lable="MB" alert="true"/>
  12. <metric id="jvm.memory.used.percent" unit="1" delta="false" order="2" title="JVM内存使用率" lable="百分比" alert="true"/>
  13. <metric id="jvm.memory.nonheap.used" unit="M" delta="false" order="3" title="Noheap内存使用量" lable="MB" alert="true"/>
  14. <metric id="jvm.memory.nonheap.used.percent" unit="1" delta="false" order="4" title="Noheap内存使用率" lable="百分比" alert="true"/>
  15. <metric id="jvm.memory.eden.used" unit="M" delta="false" order="5" title="Eden内存使用量" lable="MB" alert="true"/>
  16. <metric id="jvm.memory.eden.used.percent" unit="1" delta="false" order="6" title="Eden内存使用率" lable="百分比" alert="true"/>
  17. <metric id="jvm.memory.survivor.used" unit="M" delta="false" order="7" title="Survivor内存使用量" lable="MB" alert="true"/>
  18. <metric id="jvm.memory.survivor.used.percent" unit="1" delta="false" order="8" title="Survivor内存使用率" lable="百分比" alert="true"/>
  19. <metric id="jvm.memory.oldgen.used" unit="M" delta="false" order="9" title="Oldgen内存使用量" lable="MB" alert="true"/>
  20. <metric id="jvm.memory.oldgen.used.percent" unit="1" delta="false" order="10" title="Oldgen内存使用率" lable="百分比" alert="true"/>
  21. <metric id="jvm.memory.oldgen.used.percent.after.fullgc" unit="1" delta="false" order="11" title="Oldgen内存使用率(After Fullgc)" lable="百分比" alert="true"/>
  22. <metric id="jvm.memory.perm.used" unit="M" delta="false" order="12" title="Perm内存使用量" lable="MB" alert="true"/>
  23. <metric id="jvm.memory.perm.used.percent" unit="1" delta="false" order="13" title="Perm内存使用率" lable="百分比" alert="true"/>
  24. <metric id="jvm.memory.metaspace.used" unit="M" delta="false" order="14" title="MetaSpace内存使用量" lable="MB" alert="true"/>
  25. <metric id="jvm.memory.metaspace.used.percent" unit="1" delta="false" order="15" title="MetaSpace内存使用率" lable="百分比" alert="true"/>
  26. <metric id="jvm.memory.codecache.used" unit="M" delta="false" order="16" title="CodeCache内存使用量" lable="MB" alert="true"/>
  27. <metric id="jvm.memory.codecache.used.percent" unit="1" delta="false" order="17" title="CodeCache内存使用率" lable="百分比" alert="true"/>
  28. <metric id="jvm.nio.directbuffer.used" unit="M" delta="false" order="18" title="BufferPool direct对象使用内存" lable="MB" alert="true"/>
  29. <metric id="jvm.nio.mapped.used" unit="M" delta="false" order="19" title="BufferPool mapped对象使用内存" lable="MB" alert="true"/>
  30. </group>
  31. <group id="jvm.gc" order="15">
  32. <metric id="jvm.gc.count" unit="1" delta="false" order="1" title="Gc次数" lable="次数" alert="true"/>
  33. <metric id="jvm.gc.time" unit="1" delta="false" order="2" title="Gc持续时长总和" lable="毫秒" alert="true"/>
  34. <metric id="jvm.younggc.count" unit="1" delta="false" order="3" title="YoungGc次数" lable="次数" alert="true"/>
  35. <metric id="jvm.younggc.time" unit="1" delta="false" order="4" title="YoungGc持续时长总和" lable="毫秒" alert="true"/>
  36. <metric id="jvm.younggc.meantime" unit="1" delta="false" order="5" title="YoungGc平均时长" lable="毫秒" alert="true"/>
  37. <metric id="jvm.fullgc.count" unit="1" delta="false" order="6" title="FullGc次数" lable="次数" alert="true"/>
  38. <metric id="jvm.fullgc.time" unit="1" delta="false" order="7" title="FullGc持续时长总和" lable="毫秒" alert="true"/>
  39. </group>
  40. <group id="jvm.thread" order="16">
  41. <metric id="jvm.thread.count" unit="1" delta="false" order="1" title="活动线程总数" lable="个数" alert="true"/>
  42. <metric id="jvm.thread.daemon.count" unit="1" delta="false" order="2" title="活动daemon线程数" lable="个数" alert="true"/>
  43. <metric id="jvm.thread.totalstarted.count" unit="1" delta="false" order="3" title="累计创建线程数" lable="个数" alert="true"/>
  44. <metric id="jvm.thread.new.count" unit="1" delta="false" order="4" title="new状态的线程数" lable="个数" alert="true"/>
  45. <metric id="jvm.thread.runnable.count" unit="1" delta="false" order="5" title="runnable状态的线程数" lable="个数" alert="true"/>
  46. <metric id="jvm.thread.blocked.count" unit="1" delta="false" order="6" title="blocked状态的线程数" lable="个数" alert="true"/>
  47. <metric id="jvm.thread.waiting.count" unit="1" delta="false" order="7" title="waiting状态的线程数" lable="个数" alert="true"/>
  48. <metric id="jvm.thread.time_waiting.count" unit="1" delta="false" order="8" title="time_waiting状态的线程数" lable="个数" alert="true"/>
  49. <metric id="jvm.thread.deadlock.count" unit="1" delta="false" order="9" title="deadlock状态的线程数" lable="个数" alert="true"/>
  50. <metric id="jvm.thread.terminated.count" unit="1" delta="false" order="10" title="terminated状态的线程数" lable="个数" alert="true"/>
  51. <metric id="jvm.thread.http.count" unit="1" delta="false" order="11" title="http线程数(http, catalina, @qtc)" lable="个数" alert="true"/>
  52. <metric id="jvm.thread.cat.count" unit="1" delta="false" order="12" title="cat线程数(Cat, cat)" lable="个数" alert="true"/>
  53. <metric id="jvm.thread.pigeon.count" unit="1" delta="false" order="13" title="pigeon线程数" lable="个数" alert="true"/>
  54. </group>
  55. <group id="http.status" order="17">
  56. <metric id="http.count" unit="1" delta="false" order="1" title="http请求数量" lable="次数" alert="true"/>
  57. <metric id="http.meantime" unit="1" delta="false" order="2" title="http请求平均耗时" lable="毫秒" alert="true"/>
  58. <metric id="http.status400.count" unit="1" delta="false" order="3" title="4xx的http请求数量" lable="次数" alert="true"/>
  59. <metric id="http.status500.count" unit="1" delta="false" order="4" title="5xx的http请求数量" lable="次数" alert="true"/>
  60. </group>
  61. <group id="jvm.classingloading" order="18">
  62. <metric id="jvm.classloading.loaded.count" unit="1" delta="false" order="2" title="当前加载的类数量" lable="个数" alert="true"/>
  63. <metric id="jvm.classloading.totalloaded.count" unit="1" delta="false" order="3" title="累计加载的类数量" lable="个数" alert="true"/>
  64. <metric id="jvm.classloading.unloaded.count" unit="1" delta="false" order="4" title="累计卸载的类数量" lable="个数" alert="true"/>
  65. </group>
  66. <group id="system.process" order="19">
  67. <metric id="system.load.average" unit="1" delta="false" order="1" title="系统负载" lable="个数" alert="true"/>
  68. <metric id="cpu.system.load.percent" unit="1" delta="false" order="2" title="cpu使用率" lable="百分比" alert="true"/>
  69. <metric id="cpu.jvm.load.percent" unit="1" delta="false" order="3" title="Jvm进程cpu使用率" lable="百分比" alert="true"/>
  70. <metric id="system.process.used.phyical.memory" unit="M" delta="false" order="1" title="内存用量" lable="MB" alert="true"/>
  71. <metric id="system.process.used.swap.size" unit="M" delta="false" order="1" title="交换空间用量" lable="MB" alert="true"/>
  72. </group>
在调整心跳报表的过程中,
  • 发现metric.title中包含字符中横线-,点号 .,心跳直方图中的数字tooltip提示会消失;
  • 配置metric.alert=true即可在心跳报警配置中对指定的心跳指标进行监控

如何使用

点评cat - 图12

点评cat - 图13

点评cat - 图14

点评cat - 图15

点评cat - 图16

点评cat - 图17

点评cat - 图18

点评cat - 图19

点评cat - 图20

告警设置

cat自身不提供告警功能,需要自行定义

1.配置默认告警人

点评cat - 图21

2.配置告警url

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <sender-config>
  3. <sender id="mail" url="https://sba.trendsi.co/cat/alarm/lark" type="post" successCode="200" batchSend="true">
  4. <par id="type=1500"/>
  5. <par id="key=title,body"/>
  6. <par id="re=jack"/>
  7. <par id="to=${receiver}"/>
  8. <par id="value=${title},${content}"/>
  9. </sender>
  10. </sender-config>

点评cat - 图22

3.定义告警方法

  1. @Slf4j
  2. @RestController
  3. @RequestMapping("/cat/alarm")
  4. @RequiredArgsConstructor(onConstructor = @__(@Autowired))
  5. public class CatAlarmController {
  6. private final MessageComponent messageComponent;
  7. @RequestMapping(value = "/lark")
  8. public String larkAlarm(@RequestParam String to, @RequestParam String value) {
  9. log.info("--->>>>>>>>>>>>>to:{},value:{}", to, value);
  10. String replace = value.replace("cat-web-server", "10.90.10.9:8080");
  11. if (replace.contains("<br/><br/>")) {
  12. String[] split = replace.split("<br/><br/>");
  13. messageComponent.send(MessageType.Alarm_Message, split[0]);
  14. } else {
  15. messageComponent.send(MessageType.Alarm_Message, replace);
  16. }
  17. return "200";
  18. }
  19. }

常见异常

异常1

点评cat - 图23

异常2

点评cat - 图24