提交 f10f2eba 编写于 作者: A ainilife

update README.md and more unit tests

上级 5ffa8491
CAT
CAT [![Build Status](https://travis-ci.org/dianping/cat.png?branch=biz)](https://travis-ci.org/dianping/cat)
===
<hr>
Central Application Tracking [![Build Status](https://travis-ci.org/dianping/cat.png?branch=biz)](https://travis-ci.org/dianping/cat)
CAT的全称是Central Application Tracking,是基于Java开发的实时应用监控平台,包括实时系统监控、应用监控以及业务监控。
CAT主要通过以下几种埋点类型收集信息:
* Event 用来记录次数,表名单位时间内消息发生次数,比如记录系统异常,它和transaction相比缺少了时间的统计,开销比transaction要小。
* Transaction 适合记录跨越系统边界的程序访问行为,,比如远程调用,数据库调用,也适合执行时间较长的业务逻辑监控。
* Heartbeat Heartbeta表示程序内定期产生的统计信息, 如CHPU%, MEM%, 连接池状态, 系统负载等。
* Metric 用于业务监控埋点的API。
Requirements
---------------------
* Java 6
* Maven
* MySQL
Quick Started
---------------------
#####1、安装Java 6+,Maven以及MySQL
#####2、cd到CAT目录下,用maven构建项目
mvn eclipse:clean eclipse:eclipse
#####3、安装CAT的maven plugin,使用它配置CAT的环境
cd cat-maven-plugin;mvn cat:install
确保系统的临时目录程序拥有读写权限,Linux为/tmp/目录
#####5、如果你安装了hadoop集群,请到/data/appdatas/cat/server.xml中配置对应hadoop信息,并将localmode设置为false。默认情况下,CAT在localmode=true的开发模式下工作。
#####1、cd到CAT目录下,用maven构建项目
mvn install
#####2、安装CAT的maven plugin,使用它配置CAT的环境
mkdir -p /data/appdata/cat; chmod 777 /data/appdata/cat
mkdir -p /data/applogs/cat; chmod 777 /data/applogs/cat
mvn cat:install
#####3、如果安装了hadoop集群,需到/data/appdatas/cat/server.xml中配置对应hadoop信息。将localmode设置为false,默认情况下,CAT在开发模式(localmode=true)下工作。
#####4、运行CAT
开发模式下有两种方式启动:
方式一:
cd cat-home;mvn jetty:run
然后浏览http://localhost:2281
方式二:
将项目导入到eclipse中,运行cat-home项目里得‘com.dianping.cat.TestServer’来启动CAT。
cd cat-home;mvn jetty:run
然后打开浏览器,输入http://localhost:2281。
或者在cat目录下输入
mvn eclipse:clean eclipse:eclipse
然后将项目导入到eclipse中,运行cat-home项目里得‘com.dianping.cat.TestServer’来启动CAT。
Copyright and license
---------------------
......
......@@ -42,4 +42,13 @@ public class TrafficDistributionGroupStrategy implements ABTestGroupStrategy {
m_percentA = 50;
}
}
public void init(int... percents) {
if (percents.length == 2) {
if (percents[0] + percents[1] == 100) {
m_percentControl = percents[0];
m_percentA = percents[1];
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="config" type="ConfigType"/>
<xs:complexType name="ConfigType">
<xs:sequence>
......
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="status" type="StatusType"/>
<xs:complexType name="StatusType">
<xs:sequence>
......
......@@ -4,6 +4,9 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.dianping.cat.abtest.spi.internal.ABTestCodecTest;
import com.dianping.cat.abtest.spi.internal.ABTestEntityManagerTest;
import com.dianping.cat.abtest.spi.internal.groupstrategy.TrafficDistributionGroupStrategyTest;
import com.dianping.cat.configuration.ConfigTest;
import com.dianping.cat.log4j.CatAppenderTest;
import com.dianping.cat.message.EventTest;
......@@ -26,6 +29,12 @@ CatAppenderTest.class,
/* .message */
MessageTest.class,
TrafficDistributionGroupStrategyTest.class,
ABTestCodecTest.class,
ABTestEntityManagerTest.class,
EventTest.class,
HeartbeatTest.class,
......
......@@ -9,7 +9,7 @@ import junit.framework.Assert;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
public class ABTestContextManagerTest extends ComponentTestCase {
public class ABTestCodecTest extends ComponentTestCase {
@Test
public void testCodec() throws Exception {
check("1=ab:A|cd:B&2=ab:A|cd:B", "1=ab:A|cd:B&2=ab:A|cd:B");
......
package com.dianping.cat.abtest.spi.internal;
public class ABTestContextTest {
}
package com.dianping.cat.abtest.spi.internal.groupstrategy;
import junit.framework.Assert;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import com.dianping.cat.abtest.spi.ABTestContext;
import com.dianping.cat.abtest.spi.ABTestEntity;
import com.dianping.cat.abtest.spi.ABTestGroupStrategy;
import com.dianping.cat.abtest.spi.internal.DefaultABTestContext;
public class TrafficDistributionGroupStrategyTest extends ComponentTestCase {
@Test
public void test() throws Exception {
testApply(50, 50);
testApply(40, 60);
testApply(55, 45);
}
public void testApply(int expectDefault, int expectA) throws Exception {
TrafficDistributionGroupStrategy strategy = (TrafficDistributionGroupStrategy) lookup(ABTestGroupStrategy.class,
TrafficDistributionGroupStrategy.ID);
ABTestContext ctx = new DefaultABTestContext(new ABTestEntity());
strategy.init(expectDefault, expectA);
int countDefault = 0;
int countA = 0;
for (int i = 0; i < 100; i++) {
strategy.apply(ctx);
if (ctx.getGroupName().equals(ABTestContext.DEFAULT_GROUP)) {
countDefault++;
} else {
countA++;
}
}
Assert.assertEquals(expectDefault, countDefault);
Assert.assertEquals(expectA, countA);
}
}
......@@ -25,6 +25,8 @@ public class InstallMojo extends AbstractMojo {
private String m_path = "/data/appdatas/cat";
private String m_logPath = "/data/applogs/cat";
private String m_clientPath = m_path + File.separator + "client.xml";
private String m_serverPath = m_path + File.separator + "server.xml";
......@@ -91,6 +93,7 @@ public class InstallMojo extends AbstractMojo {
getLog().info("Preparing Cat environment ... DONE");
getLog().info("Use following command line to start local Cat server:");
getLog().info(" cd cat-home; mvn jetty:run");
getLog().info("Please open http://localhost:2281/cat in your browser");
}
}
......@@ -101,16 +104,18 @@ public class InstallMojo extends AbstractMojo {
return conn;
}
private boolean setupConfigurationFiles() {
private boolean setupConfigurationFiles() throws MojoFailureException {
File path = new File(m_path);
File logPath = new File(m_logPath);
if (!path.exists()) {
path.mkdirs();
logPath.mkdirs();
}
if (!path.canRead() || !path.canWrite()) {
if (!path.canRead() || !path.canWrite() || !logPath.canRead() || !logPath.canWrite()) {
getLog().error("Don't have privilege to read/write " + m_path);
return false;
throw new MojoFailureException("Don't have privilege to read/write " + m_path);
}
getLog().info("Generating the configuration files to " + m_path + " ...");
......@@ -153,7 +158,7 @@ public class InstallMojo extends AbstractMojo {
}
}
private boolean setupDatabase() {
private boolean setupDatabase() throws MojoFailureException {
Connection conn = null;
Statement stmt = null;
boolean isSuccess = false;
......@@ -175,6 +180,7 @@ public class InstallMojo extends AbstractMojo {
isSuccess = true;
} catch (Throwable e) {
getLog().error(e);
throw new MojoFailureException(e.getMessage());
} finally {
try {
if (stmt != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册