01. CAT环境的搭建&效果

由于工作的需要接触到美团的CAT监控中间件。有幸CAT的发展历程。

进入正题,细说本章内容

1. CAT 背景

历史

CAT 是在大众点评被美团收购&兼并之前的中间件中最出彩产品,作为大众点评的公司内部项目与公司的基础框架融合非常好,这样也就出现要适当的学习大众点评的其他基础框架。

为了解决什么问题

CAT主要为了解决微服务环境中,系统的调用关系链错综复杂,线上问题排查难的问题。

能力规划

实时处理:信息的价值会随时间锐减,尤其是事故处理过程中
全量数据:全量采集指标数据,便于深度分析故障案例
高可用:故障的还原与问题定位,需要高可用监控来支撑
故障容忍:故障不影响业务正常运转、对业务透明
高吞吐:海量监控数据的收集,需要高吞吐能力做保证
可扩展:支持分布式、跨 IDC 部署,横向扩展的监控系统

这写能力,引用官方的说法

2. CAT 本地环境搭建

作为研究CAT源码同学,迫不及待的想看一下 CAT的是如何实现。是如何如何实现它所说的这些能力。

2.1 maven 环境准备

源代码构建需要下载大众点评的nexus下jar。需要在maven中进行配置。所谓,磨刀不误砍柴工。

maven的环境
个人电脑是MAC。配置如下

# JDK
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
#JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
#JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH

# Maven
MAVEN_HOME=/Users/{mac账户用户名}/Works/soft/maven
export MAVEN_HOME
export PATH=$MAVEN_HOME/bin:$PATH

maven的setting.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<!--localRepository必须是个绝对路径,否则项目构建时会在项目根目录下出现 ~ 文件夹形式 -->
<localRepository>/Users/{mac账户用户名}/.m2/repository</localRepository>
  <servers>

  <server>
      <id>nexus-releases</id>
      <username>{nexus账户名}</username>
      <password>{nexus账户密码}</password>
    </server>
    <server>
      <id>nexus-snapshot</id>
      <username>{nexus账户名}</username>
      <password>{nexus账户密码}</password>
    </server>
  </servers>

  <mirrors>
        <!--配置udial的nexus的镜像-->
          <mirror>
         <id>unidal</id>
         <mirrorOf>unidal</mirrorOf>
         <name>nexus repository for all Mirror.</name>
         <url>http://unidal.org/nexus/content/repositories/releases/</url>
     </mirror>
      <mirror>
        <id>company</id>
        <mirrorOf>*,!unidal</mirrorOf>
        <name>nexus repository for all Mirror.</name>
        <url>http://{公司的nexus地址}/nexus/content/groups/public</url>
      </mirror>
  </mirrors>


  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

    <!-- 大众点评 -->
    <profile>
        <id>unidal</id>
        <repositories>
            <repository>
                <id>unidal</id>
                <url>http://unidal.org/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>
    </profile>
    <profile>
      <id>jdk-1.8</id>
      <activation>
          <activeByDefault>true</activeByDefault>
          <jdk>1.8</jdk>
      </activation>
      <properties>
          <maven.compiler.source>1.8</maven.compiler.source>
          <maven.compiler.target>1.8</maven.compiler.target>
          <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
  </profiles>


  <activeProfiles>
    <activeProfile>nexus</activeProfile>
    <activeProfile>unidal</activeProfile>
  </activeProfiles>
</settings>

关注

  • mirrorsunidalcompany 的配置;可以搜索一下maven如何配置多个镜像

2.2 db环境准备

CAT的运行环境的DB是MySQL,5.7版本即可。
使用客户端连接上服务器
    先创建一个数据库实例
    执行源码中的SQL脚本即可,SQL脚本的位置在 `cat/script/Cat.sql`

2.3 源代码下载

源代码github地址是 https://github.com/dianping/cat.git
本人研读的代码版本是 ==2.0.0== 

2.4 配置

涉及到配有有,存放路径 /data/appdatas/cat/*.xml

  • client.xml
  • server.xml
  • datasource.xml
<?xml version="1.0" encoding="utf-8"?>

<!-- Configuration for development environment-->
<config local-mode="true" hdfs-machine="false" job-machine="false" alert-machine="false">

    <storage  local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7">

    </storage>

    <console default-domain="Cat" show-cat-domain="true">
        <remote-servers>192.168.1.1:8080</remote-servers>
    </console>
    <!--
    <ldap ldapUrl="ldap://192.168.50.11:389/DC=dianpingoa,DC=com"/>
  -->
</config>

<!-- Configuration for production environment -->
<!-- Note: -->
<!-- 1. Set local-mode false to activate remote mode. -->
<!-- 2. If machine is job-machine, set job-machine true, you just need config only one machine. Job is offline for report aggreation, statistics report.-->
<!-- 3. If machine is alert-machine, set alert-machine true, you just need config only one machine. -->
<!-- 4. Cat can run without hdfs, you just config hdfs-machine false. If you have hdfs, you can config hdfs info for saving the logview info.  -->
<!-- 5. If you don't need hdfs, the logview will be stored in local disk. You can config max local-logivew-storage-time for cleaning up old logview, the unit is day. -->
<!-- 6. Please set hadoop environment accordingly. -->
<!-- 7. Please set ldap info for login the system. -->
<!-- 8. Please config remote-server if you have many cat servers. -->
<!--
<config local-mode="false" hdfs-machine="false" job-machine="false" alert-machine="false">
    <storage  local-base-dir="/data/appdatas/cat/bucket/" max-hdfs-storage-time="15" local-report-storage-time="7" local-logivew-storage-time="7">
        <hdfs id="logview" max-size="128M" server-uri="hdfs://10.1.77.86/user/cat" base-dir="logview"/>
        <hdfs id="dump" max-size="128M" server-uri="hdfs://10.1.77.86/user/cat" base-dir="dump"/>
        <hdfs id="remote" max-size="128M" server-uri="hdfs://10.1.77.86/user/cat" base-dir="remote"/>
    </storage>

    <console default-domain="Cat" show-cat-domain="true">
        <remote-servers>192.168.0.1:2281,192.168.0.2:2281</remote-servers>
    </console>

    <ldap ldapUrl="ldap://192.168.50.11:389/DC=dianpingoa,DC=com"/>
</config>

<?xml version="1.0" encoding="utf-8"?>

<data-sources>
    <data-source id="cat">
        <maximum-pool-size>3</maximum-pool-size>
        <connection-timeout>1s</connection-timeout>
        <idle-timeout>10m</idle-timeout>
        <statement-cache-size>1000</statement-cache-size>
        <properties>
            <driver>com.mysql.jdbc.Driver</driver>
            <url><![CDATA[jdbc:mysql://10.104.122.1:3306/cat_local]]></url>
            <user>root</user>
            <password>123456</password>
            <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&socketTimeout=120000]]></connectionProperties>
        </properties>
    </data-source>
    <data-source id="app">
        <maximum-pool-size>3</maximum-pool-size>
        <connection-timeout>1s</connection-timeout>
        <idle-timeout>10m</idle-timeout>
        <statement-cache-size>1000</statement-cache-size>
        <properties>
            <driver>com.mysql.jdbc.Driver</driver>
            <url><![CDATA[jdbc:mysql://10.104.122.1:3306/cat_local]]></url>
            <user>root</user>
            <password>123456</password>
            <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&socketTimeout=120000]]></connectionProperties>
        </properties>
    </data-source>
</data-sources>
<?xml version="1.0" encoding="utf-8"?>

<config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
    <servers>
        <!-- Local mode for development -->
        <server ip="127.0.0.1" port="2280" http-port="8080" />
        <!-- If under production environment, put actual server address as list. -->
        <!--
            <server ip="192.168.7.71" port="2280" />
            <server ip="192.168.7.72" port="2280" />
        -->
    </servers>
</config>

2.5 mac环境特殊说明

mac特说的原因是 MAC os引入了系统完整性保护(SIP)机制,无法在/、/usr 目录下新建文件

处理方案是

2.5 环境运行效果

项目启动 com.dianping.cat.TestServer.startWebApp

2.5.1 界面展示

2.5.2 日志目录说明

data
├── appdatas
│   └── cat
│       ├── bucket
│       │   ├── dump
│       │   │   ├── 20210207
│       │   │   └── 20210209
│       │   └── report
│       │       ├── 20210127
│       │       ├── 20210201
│       │       ├── 20210202
│       │       ├── 20210207
│       │       └── 20210209
│       ├── cat-UNKNOWN.mark
│       ├── cat-cat.mark
│       ├── client.xml
│       ├── datasources.xml
│       └── server.xml
└── applogs

2.6 小结

posted @ 2021-02-09 11:02  可可逗豆  阅读(483)  评论(0)    收藏  举报