Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
d6b9f6f3
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6b9f6f3
编写于
7月 21, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
差异文件
merge newest code and solve conflicts
上级
32fd8d42
67926035
变更
77
展开全部
隐藏空白更改
内联
并排
Showing
77 changed file
with
7231 addition
and
1041 deletion
+7231
-1041
README.md
README.md
+1
-2
cat-agent/src/main/java/com/dianping/cat/agent/build/ComponentsConfigurator.java
.../com/dianping/cat/agent/build/ComponentsConfigurator.java
+1
-1
cat-agent/src/main/java/com/dianping/cat/agent/monitor/executors/EnvConfig.java
...a/com/dianping/cat/agent/monitor/executors/EnvConfig.java
+61
-19
cat-agent/src/main/java/com/dianping/cat/agent/monitor/executors/TaskExecutors.java
...m/dianping/cat/agent/monitor/executors/TaskExecutors.java
+20
-3
cat-agent/src/main/java/com/dianping/cat/agent/monitor/paas/DataBuilder.java
...java/com/dianping/cat/agent/monitor/paas/DataBuilder.java
+26
-51
cat-agent/src/main/resources/META-INF/plexus/components.xml
cat-agent/src/main/resources/META-INF/plexus/components.xml
+10
-0
cat-agent/src/main/webapp/paas-monitor.py
cat-agent/src/main/webapp/paas-monitor.py
+52
-13
cat-agent/src/main/webapp/rmp/cat-agent-makerpm.sh
cat-agent/src/main/webapp/rmp/cat-agent-makerpm.sh
+59
-0
cat-agent/src/main/webapp/rmp/cat-agent-tomcat.spec
cat-agent/src/main/webapp/rmp/cat-agent-tomcat.spec
+84
-0
cat-agent/src/main/webapp/startup.sh
cat-agent/src/main/webapp/startup.sh
+15
-2
cat-broker/pom.xml
cat-broker/pom.xml
+180
-181
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppData.java
...rc/main/java/com/dianping/cat/broker/api/app/AppData.java
+150
-0
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppDataConsumer.java
...java/com/dianping/cat/broker/api/app/AppDataConsumer.java
+171
-0
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppDataQueue.java
...in/java/com/dianping/cat/broker/api/app/AppDataQueue.java
+24
-0
cat-broker/src/main/java/com/dianping/cat/broker/api/app/BucketHandler.java
...n/java/com/dianping/cat/broker/api/app/BucketHandler.java
+182
-0
cat-broker/src/main/java/com/dianping/cat/broker/api/page/IpService.java
...main/java/com/dianping/cat/broker/api/page/IpService.java
+10
-10
cat-broker/src/main/java/com/dianping/cat/broker/api/page/batch/Handler.java
.../java/com/dianping/cat/broker/api/page/batch/Handler.java
+80
-1
cat-broker/src/main/java/com/dianping/cat/broker/api/page/js/Handler.java
...ain/java/com/dianping/cat/broker/api/page/js/Handler.java
+7
-7
cat-broker/src/main/java/com/dianping/cat/broker/build/ComponentsConfigurator.java
...com/dianping/cat/broker/build/ComponentsConfigurator.java
+10
-0
cat-broker/src/main/resources/META-INF/plexus/components.xml
cat-broker/src/main/resources/META-INF/plexus/components.xml
+81
-0
cat-broker/src/main/resources/META-INF/wizard/model/manifest.xml
...ker/src/main/resources/META-INF/wizard/model/manifest.xml
+5
-0
cat-broker/src/main/resources/META-INF/wizard/model/wizard.xml
...roker/src/main/resources/META-INF/wizard/model/wizard.xml
+6
-0
cat-broker/src/main/webapp/jsp/api/app.jsp
cat-broker/src/main/webapp/jsp/api/app.jsp
+5
-0
cat-broker/src/test/java/com/dianping/cat/broker/AppTest.java
...broker/src/test/java/com/dianping/cat/broker/AppTest.java
+54
-0
cat-client/src/main/java/com/dianping/cat/CatClientModule.java
...lient/src/main/java/com/dianping/cat/CatClientModule.java
+1
-1
cat-client/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
.../dianping/cat/message/internal/DefaultMessageManager.java
+8
-3
cat-client/src/main/java/com/dianping/cat/message/spi/MessageManager.java
...ain/java/com/dianping/cat/message/spi/MessageManager.java
+6
-0
cat-client/src/main/java/com/dianping/cat/servlet/CatFilter.java
...ent/src/main/java/com/dianping/cat/servlet/CatFilter.java
+186
-39
cat-client/src/test/java/com/dianping/cat/servlet/CatFilterTest.java
...src/test/java/com/dianping/cat/servlet/CatFilterTest.java
+12
-17
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/metric/MetricAnalyzer.java
...java/com/dianping/cat/consumer/metric/MetricAnalyzer.java
+1
-1
cat-consumer-advanced/src/test/java/com/dianping/cat/consumer/metric/MetricConfigManagerTest.java
...dianping/cat/consumer/metric/MetricConfigManagerTest.java
+0
-1
cat-core/pom.xml
cat-core/pom.xml
+2
-1
cat-core/src/main/java/com/dianping/cat/build/AppDatabaseConfigurator.java
.../java/com/dianping/cat/build/AppDatabaseConfigurator.java
+21
-0
cat-core/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
.../java/com/dianping/cat/build/CatDatabaseConfigurator.java
+24
-0
cat-core/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
...n/java/com/dianping/cat/build/ComponentsConfigurator.java
+6
-2
cat-core/src/main/java/com/dianping/cat/config/app/AppConfigManager.java
...in/java/com/dianping/cat/config/app/AppConfigManager.java
+107
-9
cat-core/src/main/java/com/dianping/cat/config/app/AppDataCommandTableProvider.java
.../dianping/cat/config/app/AppDataCommandTableProvider.java
+42
-0
cat-core/src/main/java/com/dianping/cat/config/app/AppDataService.java
...main/java/com/dianping/cat/config/app/AppDataService.java
+173
-0
cat-core/src/main/java/com/dianping/cat/config/app/QueryEntity.java
...rc/main/java/com/dianping/cat/config/app/QueryEntity.java
+8
-1
cat-core/src/main/resources/META-INF/dal/jdbc/app-codegen.xml
...core/src/main/resources/META-INF/dal/jdbc/app-codegen.xml
+60
-0
cat-core/src/main/resources/META-INF/dal/jdbc/app-dal.xml
cat-core/src/main/resources/META-INF/dal/jdbc/app-dal.xml
+108
-0
cat-core/src/main/resources/META-INF/dal/jdbc/app-manifest.xml
...ore/src/main/resources/META-INF/dal/jdbc/app-manifest.xml
+6
-0
cat-core/src/main/resources/META-INF/dal/jdbc/config-codegen.xml
...e/src/main/resources/META-INF/dal/jdbc/config-codegen.xml
+1
-1
cat-core/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
...e/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
+15
-14
cat-core/src/main/resources/META-INF/dal/model/app-config-model.xml
...rc/main/resources/META-INF/dal/model/app-config-model.xml
+12
-2
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+12
-0
cat-core/src/main/resources/META-INF/wizard/jdbc/wizard.xml
cat-core/src/main/resources/META-INF/wizard/jdbc/wizard.xml
+12
-0
cat-hadoop/pom.xml
cat-hadoop/pom.xml
+1
-1
cat-home/pom.xml
cat-home/pom.xml
+0
-5
cat-home/src/main/java/com/dianping/cat/CookieFilter.class
cat-home/src/main/java/com/dianping/cat/CookieFilter.class
+167
-0
cat-home/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
.../java/com/dianping/cat/build/CatDatabaseConfigurator.java
+2
-0
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
...n/java/com/dianping/cat/build/ComponentsConfigurator.java
+108
-29
cat-home/src/main/java/com/dianping/cat/build/UserDatabaseConfigurator.java
...java/com/dianping/cat/build/UserDatabaseConfigurator.java
+2
-0
cat-home/src/main/java/com/dianping/cat/report/chart/AbstractGraphCreator.java
...a/com/dianping/cat/report/chart/AbstractGraphCreator.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/page/app/Handler.java
...c/main/java/com/dianping/cat/report/page/app/Handler.java
+28
-4
cat-home/src/main/java/com/dianping/cat/report/page/app/Model.java
...src/main/java/com/dianping/cat/report/page/app/Model.java
+107
-0
cat-home/src/main/java/com/dianping/cat/report/page/app/Payload.java
...c/main/java/com/dianping/cat/report/page/app/Payload.java
+72
-44
cat-home/src/main/java/com/dianping/cat/report/page/app/graph/AppGraphCreator.java
...m/dianping/cat/report/page/app/graph/AppGraphCreator.java
+82
-0
cat-home/src/main/java/com/dianping/cat/report/page/system/graph/SystemGraphCreator.java
...ping/cat/report/page/system/graph/SystemGraphCreator.java
+5
-5
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/CityManager.java
...com/dianping/cat/report/page/userMonitor/CityManager.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
...at/report/task/alert/exception/AlertExceptionBuilder.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
...nping/cat/report/task/alert/exception/ExceptionAlert.java
+5
-0
cat-home/src/main/java/com/dianping/cat/report/view/NavigationBar.java
...main/java/com/dianping/cat/report/view/NavigationBar.java
+3
-1
cat-home/src/main/java/com/dianping/cat/system/tool/DefaultMailImpl.java
...in/java/com/dianping/cat/system/tool/DefaultMailImpl.java
+1
-1
cat-home/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
...e/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
+1
-54
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+3860
-91
cat-home/src/main/resources/config/default-alert-config.xml
cat-home/src/main/resources/config/default-alert-config.xml
+0
-18
cat-home/src/main/resources/config/default-app-config.xml
cat-home/src/main/resources/config/default-app-config.xml
+62
-4
cat-home/src/main/webapp/WEB-INF/web.xml
cat-home/src/main/webapp/WEB-INF/web.xml
+66
-66
cat-home/src/main/webapp/js/baseGraph.js
cat-home/src/main/webapp/js/baseGraph.js
+97
-12
cat-home/src/main/webapp/jsp/report/app.jsp
cat-home/src/main/webapp/jsp/report/app.jsp
+269
-160
cat-home/src/main/webapp/jsp/report/cdn.jsp
cat-home/src/main/webapp/jsp/report/cdn.jsp
+6
-0
cat-home/src/test/java/com/dianping/cat/report/analyzer/TopologyGraphTest.java
...a/com/dianping/cat/report/analyzer/TopologyGraphTest.java
+35
-16
cat-maven-plugin/src/main/java/com/dianping/cat/plugin/InstallMojo.java
...in/src/main/java/com/dianping/cat/plugin/InstallMojo.java
+1
-1
cat-maven-plugin/src/main/resources/com/dianping/cat/plugin/Cat.sql
...plugin/src/main/resources/com/dianping/cat/plugin/Cat.sql
+101
-138
pom.xml
pom.xml
+1
-0
script/Cat.sql
script/Cat.sql
+29
-6
未找到文件。
README.md
浏览文件 @
d6b9f6f3
...
...
@@ -28,7 +28,6 @@ CAT监控系统将每次URL、Service的请求内部执行情况都封装为一
![
Alt text
](
https://raw.github.com/dianping/cat/master/cat-home/src/main/webapp/images/logviewAll03.png
)
Requirements
---------------------
*
Java 6
...
...
@@ -38,7 +37,7 @@ Requirements
Quick Started
---------------------
#####1、在CAT目录下,用maven构建项目
mvn clean install
mvn clean install
-DskipTests
#####2、配置CAT的环境
mvn cat:install
Note:
...
...
cat-agent/src/main/java/com/dianping/cat/agent/build/ComponentsConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -45,7 +45,7 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
Executor
.
class
,
SystemStateExecutor
.
ID
,
SystemStateExecutor
.
class
).
req
(
EnvConfig
.
class
,
CommandUtils
.
class
));
all
.
add
(
C
(
TaskExecutors
.
class
).
req
(
DataSender
.
class
));
all
.
add
(
C
(
TaskExecutors
.
class
).
req
(
DataSender
.
class
,
EnvConfig
.
class
));
all
.
add
(
C
(
PaasTask
.
class
).
req
(
DataSender
.
class
,
DataBuilder
.
class
));
...
...
cat-agent/src/main/java/com/dianping/cat/agent/monitor/executors/EnvConfig.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.agent.monitor.executors
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Properties
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.codehaus.plexus.util.StringUtils
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.configuration.NetworkInterfaceManager
;
public
class
EnvConfig
implements
Initializable
{
...
...
@@ -20,6 +24,8 @@ public class EnvConfig implements Initializable {
private
String
m_hostName
;
private
String
m_monitors
;
private
String
MD5_PATH
=
"/usr/sbin/sshd"
;
private
String
PACKAGE_INTERFACE
=
"eth0"
;
...
...
@@ -28,9 +34,9 @@ public class EnvConfig implements Initializable {
private
String
CATALINA_PATH
=
"/data/applogs/tomcat/catalina.out"
;
private
List
<
String
>
TRAFFIC_INTERFACE_LIST
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"eth0"
,
"lo"
)
);
private
List
<
String
>
TRAFFIC_INTERFACE_LIST
=
Arrays
.
asList
(
"eth0"
,
"lo"
);
private
List
<
String
>
DISK_LIST
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"/"
,
"/data"
,
"/usr"
,
"/var"
)
);
private
List
<
String
>
DISK_LIST
=
Arrays
.
asList
(
"/"
,
"/data"
,
"/usr"
,
"/var"
);
public
String
getDomain
()
{
return
m_domain
;
...
...
@@ -48,6 +54,10 @@ public class EnvConfig implements Initializable {
return
m_hostName
;
}
public
String
getMonitors
()
{
return
m_monitors
;
}
public
String
getConfig
()
{
return
CONFIG_FILE
;
}
...
...
@@ -91,31 +101,63 @@ public class EnvConfig implements Initializable {
return
domain
;
}
@Override
public
void
initialize
()
{
private
void
loadFromConfig
(
String
defaultMonitors
)
{
Properties
properties
=
new
Properties
();
InputStream
in
=
null
;
try
{
String
agent
=
System
.
getProperty
(
"agent"
,
"executors"
);
in
=
new
BufferedInputStream
(
new
FileInputStream
(
getConfig
()));
properties
.
load
(
in
);
if
(
"executors"
.
equals
(
agent
))
{
Properties
properties
=
new
Properties
();
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
getConfig
()));
properties
.
load
(
in
);
m_hostName
=
properties
.
getProperty
(
"host.name"
);
m_hostName
=
properties
.
getProperty
(
"host.name"
);
if
(
m_hostName
==
null
)
{
m_hostName
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostName
();
m_domain
=
"unset"
;
}
else
{
m_domain
=
buildDomain
(
m_hostName
);
}
m_ip
=
properties
.
getProperty
(
"host.ip"
);
if
(
m_hostName
==
null
)
{
m_hostName
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostName
();
}
if
(
m_ip
==
null
)
{
m_ip
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostAddress
();
}
m_domain
=
buildDomain
(
m_hostName
);
m_ip
=
properties
.
getProperty
(
"host.ip"
);
m_monitors
=
properties
.
getProperty
(
"host.monitors"
);
if
(
m_ip
==
null
)
{
m_ip
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostAddress
();
}
if
(
m_monitors
==
null
)
{
m_monitors
=
defaultMonitors
;
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Error when init environment info "
,
e
);
}
finally
{
if
(
in
!=
null
)
{
try
{
in
.
close
();
}
catch
(
IOException
e
)
{
Cat
.
logError
(
e
);
}
}
}
}
@Override
public
void
initialize
()
throws
InitializationException
{
String
agent
=
System
.
getProperty
(
"agent"
,
"executors"
);
if
(
"executors"
.
equals
(
agent
))
{
File
configFile
=
new
File
(
getConfig
());
String
envMoniotors
=
System
.
getenv
(
"MONITORS"
);
String
defaultMonitors
=
StringUtils
.
isEmpty
(
envMoniotors
)
?
"system"
:
envMoniotors
;
if
(
configFile
.
exists
())
{
loadFromConfig
(
defaultMonitors
);
}
else
{
m_domain
=
"unset"
;
m_monitors
=
defaultMonitors
;
m_ip
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostAddress
();
m_hostName
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostName
();
}
}
}
}
cat-agent/src/main/java/com/dianping/cat/agent/monitor/executors/TaskExecutors.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.agent.monitor.executors
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -14,15 +15,22 @@ import org.unidal.lookup.annotation.Inject;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.agent.monitor.DataEntity
;
import
com.dianping.cat.agent.monitor.DataSender
;
import
com.dianping.cat.agent.monitor.executors.jvm.JVMMemoryExecutor
;
import
com.dianping.cat.agent.monitor.executors.jvm.JVMStateExecutor
;
import
com.dianping.cat.agent.monitor.executors.system.SystemPerformanceExecutor
;
import
com.dianping.cat.agent.monitor.executors.system.SystemStateExecutor
;
import
com.dianping.cat.message.Transaction
;
public
class
TaskExecutors
extends
ContainerHolder
implements
Task
,
Initializable
{
private
Collection
<
Executor
>
m_executors
;
@Inject
private
DataSender
m_sender
;
@Inject
private
EnvConfig
m_config
;
private
Collection
<
Executor
>
m_executors
=
new
ArrayList
<
Executor
>();
private
static
final
long
DURATION
=
5
*
1000
;
@Override
...
...
@@ -36,8 +44,17 @@ public class TaskExecutors extends ContainerHolder implements Task, Initializabl
if
(
"executors"
.
equalsIgnoreCase
(
agent
))
{
Map
<
String
,
Executor
>
map
=
lookupMap
(
Executor
.
class
);
m_executors
=
map
.
value
s
();
String
monitors
=
m_config
.
getMonitor
s
();
if
(
monitors
.
toLowerCase
().
contains
(
"system"
))
{
m_executors
.
add
(
map
.
get
(
SystemPerformanceExecutor
.
ID
));
m_executors
.
add
(
map
.
get
(
SystemStateExecutor
.
ID
));
}
if
(
monitors
.
toLowerCase
().
contains
(
"tomcat"
))
{
m_executors
.
add
(
map
.
get
(
JVMMemoryExecutor
.
ID
));
m_executors
.
add
(
map
.
get
(
JVMStateExecutor
.
ID
));
}
Threads
.
forGroup
(
"Cat"
).
start
(
this
);
}
}
...
...
cat-agent/src/main/java/com/dianping/cat/agent/monitor/paas/DataBuilder.java
浏览文件 @
d6b9f6f3
...
...
@@ -7,7 +7,6 @@ import java.util.Map;
import
org.codehaus.plexus.util.StringUtils
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.tuple.Pair
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.agent.monitor.CommandUtils
;
...
...
@@ -18,40 +17,38 @@ public class DataBuilder {
@Inject
private
CommandUtils
m_commandUtils
;
private
Map
<
String
,
String
>
m_ip2Md5
=
new
HashMap
<
String
,
String
>();
private
Map
<
String
,
Double
>
m_lastValues
=
new
HashMap
<
String
,
Double
>();
private
Map
<
String
,
Pair
<
Double
,
Double
>>
m_lastFlow
=
new
HashMap
<
String
,
Pair
<
Double
,
Double
>
>();
private
Map
<
String
,
String
>
m_ip2Md5
=
new
HashMap
<
String
,
String
>();
public
String
getPaasMonintor
()
{
return
System
.
getProperty
(
"user.dir"
)
+
"/paas-monitor.py"
;
}
private
Pair
<
Double
,
Double
>
findOrCreateFlow
(
String
ip
)
{
Pair
<
Double
,
Double
>
flow
=
m_lastFlow
.
get
(
ip
);
private
double
findOrCreateSumValue
(
String
key
)
{
Double
value
=
m_lastValues
.
get
(
key
);
if
(
flow
==
null
)
{
flow
=
new
Pair
<
Double
,
Double
>(-
1
D
,
-
1
D
);
m_last
Flow
.
put
(
ip
,
flow
);
if
(
value
==
null
)
{
value
=
new
Double
(
-
1
D
);
m_last
Values
.
put
(
key
,
value
);
}
return
flow
;
return
value
;
}
private
String
findOrCreateMd5Info
(
String
ip
)
{
String
md5Info
=
m_ip2Md5
.
get
(
ip
);
private
String
findOrCreateMd5Info
(
String
key
)
{
String
md5Info
=
m_ip2Md5
.
get
(
key
);
if
(
md5Info
==
null
)
{
md5Info
=
""
;
m_ip2Md5
.
put
(
ip
,
md5Info
);
m_ip2Md5
.
put
(
key
,
md5Info
);
}
return
md5Info
;
}
private
List
<
DataEntity
>
convert2DataEntities
(
List
<
String
>
lines
)
{
List
<
DataEntity
>
dataEntities
=
new
ArrayList
<
DataEntity
>();
Pair
<
Double
,
Double
>
flow
=
null
;
String
domain
=
null
;
String
ip
=
null
;
for
(
String
line
:
lines
)
{
try
{
...
...
@@ -64,21 +61,15 @@ public class DataBuilder {
if
(
line
.
startsWith
(
"domain"
))
{
domain
=
value
;
ip
=
key
.
substring
(
key
.
lastIndexOf
(
"_"
));
flow
=
findOrCreateFlow
(
ip
);
}
else
if
(
line
.
startsWith
(
"system_eth0-in-flow"
))
{
DataEntity
inFlow
=
buildInFlowData
(
domain
,
type
,
realKey
,
flow
,
value
);
}
else
if
(
"sum"
.
equals
(
type
))
{
DataEntity
inFlow
=
buildSumEntity
(
domain
,
type
,
realKey
,
key
,
value
);
add2Entities
(
dataEntities
,
inFlow
);
}
else
if
(
line
.
startsWith
(
"system_eth0-out-flow"
))
{
DataEntity
outFlow
=
buildOutFlowData
(
domain
,
type
,
realKey
,
flow
,
value
);
add2Entities
(
dataEntities
,
outFlow
);
}
else
if
(
line
.
startsWith
(
"system_md5Change"
))
{
DataEntity
md5Info
=
buildMd5Info
(
domain
,
type
,
realKey
,
ip
,
value
);
DataEntity
md5Info
=
buildMd5Info
(
domain
,
type
,
realKey
,
key
,
value
);
add2Entities
(
dataEntities
,
md5Info
);
}
else
{
}
else
if
(
"avg"
.
equals
(
type
))
{
DataEntity
entity
=
new
DataEntity
();
entity
.
setGroup
(
"system-"
+
domain
).
setDomain
(
domain
).
setId
(
realKey
).
setTime
(
System
.
currentTimeMillis
())
...
...
@@ -98,21 +89,21 @@ public class DataBuilder {
}
}
private
DataEntity
build
InFlowData
(
String
domain
,
String
type
,
String
key
,
Pair
<
Double
,
Double
>
flow
,
String
value
)
{
private
DataEntity
build
SumEntity
(
String
domain
,
String
type
,
String
realKey
,
String
key
,
String
value
)
{
DataEntity
entity
=
null
;
try
{
double
flow
Value
=
Double
.
parseDouble
(
value
);
double
last
InFlow
=
flow
.
getKey
(
);
double
current
Value
=
Double
.
parseDouble
(
value
);
double
last
Value
=
findOrCreateSumValue
(
key
);
if
(
last
InFlow
>=
0
)
{
double
gap
=
flowValue
-
lastInFlow
;
if
(
last
Value
>=
0
)
{
double
gap
=
currentValue
-
lastValue
;
entity
=
new
DataEntity
();
entity
.
setGroup
(
buildGroup
(
domain
)).
setDomain
(
domain
).
setId
(
k
ey
).
setTime
(
System
.
currentTimeMillis
())
entity
.
setGroup
(
buildGroup
(
domain
)).
setDomain
(
domain
).
setId
(
realK
ey
).
setTime
(
System
.
currentTimeMillis
())
.
setType
(
type
).
setValue
(
gap
);
}
flow
.
setKey
(
flow
Value
);
m_lastValues
.
put
(
key
,
current
Value
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
...
...
@@ -120,29 +111,13 @@ public class DataBuilder {
return
entity
;
}
private
DataEntity
buildOutFlowData
(
String
domain
,
String
type
,
String
key
,
Pair
<
Double
,
Double
>
flow
,
String
value
)
{
DataEntity
entity
=
null
;
double
flowValue
=
Double
.
parseDouble
(
value
);
double
lastFlow
=
flow
.
getValue
();
if
(
lastFlow
>=
0
)
{
double
gap
=
flowValue
-
lastFlow
;
entity
=
new
DataEntity
();
entity
.
setGroup
(
buildGroup
(
domain
)).
setDomain
(
domain
).
setId
(
key
).
setTime
(
System
.
currentTimeMillis
())
.
setType
(
type
).
setValue
(
gap
);
}
flow
.
setValue
(
flowValue
);
return
entity
;
}
private
DataEntity
buildMd5Info
(
String
domain
,
String
type
,
String
key
,
String
ip
,
String
value
)
{
String
md5Info
=
findOrCreateMd5Info
(
ip
);
private
DataEntity
buildMd5Info
(
String
domain
,
String
type
,
String
realKey
,
String
key
,
String
value
)
{
String
md5Info
=
findOrCreateMd5Info
(
key
);
DataEntity
entity
=
null
;
if
(
StringUtils
.
isNotEmpty
(
md5Info
))
{
entity
=
new
DataEntity
();
entity
.
setGroup
(
buildGroup
(
domain
)).
setDomain
(
domain
).
setId
(
k
ey
).
setTime
(
System
.
currentTimeMillis
())
entity
.
setGroup
(
buildGroup
(
domain
)).
setDomain
(
domain
).
setId
(
realK
ey
).
setTime
(
System
.
currentTimeMillis
())
.
setType
(
type
);
if
(
md5Info
.
equals
(
value
))
{
entity
.
setValue
(
1
);
...
...
@@ -150,7 +125,7 @@ public class DataBuilder {
entity
.
setValue
(
0
);
}
}
else
{
m_ip2Md5
.
put
(
ip
,
value
);
m_ip2Md5
.
put
(
key
,
value
);
}
return
entity
;
}
...
...
cat-agent/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
d6b9f6f3
...
...
@@ -101,6 +101,9 @@
<requirement>
<role>
com.dianping.cat.agent.monitor.DataSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.agent.monitor.executors.EnvConfig
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -175,8 +178,15 @@
<requirement>
<role>
com.dianping.cat.agent.monitor.DataSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.agent.monitor.executors.EnvConfig
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.agent.monitor.executors.EnvConfig
</role>
<implementation>
com.dianping.cat.agent.monitor.executors.EnvConfig
</implementation>
</component>
<component>
<role>
com.dianping.cat.agent.monitor.paas.PaasTask
</role>
<implementation>
com.dianping.cat.agent.monitor.paas.PaasTask
</implementation>
...
...
cat-agent/src/main/webapp/paas-monitor.py
浏览文件 @
d6b9f6f3
...
...
@@ -15,6 +15,11 @@ def execute(command):
return
p
.
returncode
,
p
.
stdout
.
read
(),
p
.
stderr
.
read
()
def
docker_command
(
pid
,
command
):
_
,
result
,
_
=
execute
(
COMMAND_PATTERN
%
(
pid
,
command
))
return
result
.
strip
()
def
get_instance_ids
():
return
[
ele
[
'Id'
]
for
ele
in
json
.
loads
(
urllib2
.
urlopen
(
'http://0.0.0.0:8090/containers/ps'
).
read
())]
...
...
@@ -49,12 +54,12 @@ def get_name(inspect_info):
def
get_cpu_usage
(
metric_info
):
if
'current_usage'
in
metric_info
[
'cpu_stats'
][
'cpu_usage'
]:
return
metric_info
[
'cpu_stats'
][
'cpu_usage'
][
'c
urrent
_usage'
]
return
metric_info
[
'cpu_stats'
][
'cpu_usage'
][
'c
pu
_usage'
]
return
0
def
get_network_info
(
pid
,
network_name
):
_
,
flow
,
_
=
execute
(
COMMAND_PATTERN
%
(
pid
,
'ifconfig %s'
%
network_name
)
)
flow
=
docker_command
(
pid
,
'ifconfig %s'
%
network_name
)
total_error
,
total_dropped
,
total_collision
=
[
0
]
*
3
m
=
re
.
search
(
r
'RX bytes:\s*(\d+).*?TX bytes:\s*(\d+)'
,
flow
,
re
.
IGNORECASE
)
...
...
@@ -77,12 +82,11 @@ def get_network_info(pid, network_name):
return
rx
,
tx
,
total_error
,
total_dropped
,
total_collision
def
get_container_info
(
inspect_info
):
pid
=
inspect_info
[
'State'
][
'Pid'
]
_
,
disk_usage
,
_
=
execute
(
COMMAND_PATTERN
%
(
pid
,
'df -h | grep "rootfs"'
))
def
get_container_info
(
pid
):
disk_usage
=
docker_command
(
pid
,
'df -h | grep "rootfs"'
)
disk_usage
=
re
.
split
(
r
'\s+'
,
disk_usage
.
strip
())[
-
2
][:
-
1
]
disk_usage
=
int
(
disk_usage
)
*
1.0
/
100
_
,
ssh_md5
,
_
=
execute
(
COMMAND_PATTERN
%
(
pid
,
'md5sum /usr/sbin/sshd'
)
)
ssh_md5
=
docker_command
(
pid
,
'md5sum /usr/sbin/sshd'
)
ssh_md5
=
re
.
split
(
r
'\s+'
,
ssh_md5
.
strip
())[
0
]
eth0_rx
,
eth0_tx
,
eth0_errors
,
eth0_dropped
,
eth0_collision
=
get_network_info
(
pid
,
'eth0'
)
...
...
@@ -97,7 +101,8 @@ def get_swap_usage(metric_info):
def
get_memory_info
(
metric_info
,
instance_id
):
used
,
cached
=
metric_info
[
'memory_stats'
][
'usage'
],
metric_info
[
'memory_stats'
][
'stats'
][
'cache'
]
used
,
cached
=
metric_info
[
'memory_stats'
][
'stats'
][
'rss'
],
metric_info
[
'memory_stats'
][
'stats'
][
'cache'
]
shared
,
buffered
=
[
0
,
0
]
total
=
-
1
try
:
result
=
json
.
loads
(
post
(
'http://localhost:8090/containers/%s/cgroup'
%
instance_id
,
...
...
@@ -109,7 +114,29 @@ def get_memory_info(metric_info, instance_id):
except
Exception
,
e
:
pass
return
total
,
used
,
cached
free
=
int
(
total
)
-
int
(
used
)
-
int
(
cached
)
return
total
,
used
,
cached
,
free
,
shared
,
buffered
def
get_process_info
(
pid
):
result
=
docker_command
(
pid
,
"top -b -n1 | grep Tasks | awk '{print $2,$4}'"
)
return
re
.
split
(
r
'\s+'
,
result
.
strip
())
def
get_number_of_user_connected
(
pid
):
result
=
docker_command
(
pid
,
"who | awk '{ print $1 }' | sort | uniq | wc -l"
)
return
result
.
strip
()
def
get_tcp_established
(
pid
):
result
=
docker_command
(
pid
,
'netstat -anot | grep ESTABLISHED | wc -l'
)
return
result
.
strip
()
def
get_inodes_info
(
pid
):
result
=
docker_command
(
pid
,
"df -i | grep rootfs | awk '{print $2,$4}'"
)
return
re
.
split
(
r
'\s+'
,
result
.
strip
())
def
post
(
url
,
data
,
headers
=
{}):
...
...
@@ -130,10 +157,16 @@ def get_all_info(current_instance=None):
inspect_info
=
instance_inspect
(
instance_id
)
metric_info
=
instance_metric
(
instance_id
)
pid
=
inspect_info
[
'State'
][
'Pid'
]
disk_usage
,
ssh_md5
,
eth0_rx
,
eth0_tx
,
eth0_errors
,
eth0_dropped
,
eth0_collision
,
lo_rx
,
lo_tx
,
\
lo_errors
,
lo_dropped
,
lo_collision
=
get_container_info
(
inspect_info
)
lo_errors
,
lo_dropped
,
lo_collision
=
get_container_info
(
pid
)
ip
=
get_ip
(
inspect_info
)
mem_total
,
mem_used
,
mem_cached
=
get_memory_info
(
metric_info
,
instance_id
)
mem_total
,
mem_used
,
mem_cached
,
mem_free
,
mem_shared
,
mem_buffered
=
get_memory_info
(
metric_info
,
instance_id
)
process_total
,
process_running
=
get_process_info
(
pid
)
number_of_user_connected
=
get_number_of_user_connected
(
pid
)
tcp_established_num
=
get_tcp_established
(
pid
)
inodes_total
,
inodes_free
=
get_inodes_info
(
pid
)
m
=
[
(
'domain'
,
''
,
get_name
(
inspect_info
)),
...
...
@@ -141,6 +174,9 @@ def get_all_info(current_instance=None):
(
'system_cachedMem'
,
'avg'
,
mem_cached
),
(
'system_totalMem'
,
'avg'
,
mem_total
),
(
'system_usedMem'
,
'avg'
,
mem_used
),
(
'system_freeMem'
,
'avg'
,
mem_free
),
(
'system_sharedMem'
,
'avg'
,
mem_shared
),
(
'system_buffersMem'
,
'avg'
,
mem_buffered
),
(
'system_/-usage'
,
'avg'
,
disk_usage
),
(
'system_swapUsage'
,
'avg'
,
get_swap_usage
(
metric_info
)),
(
'system_md5Change'
,
'avg'
,
ssh_md5
),
...
...
@@ -152,9 +188,12 @@ def get_all_info(current_instance=None):
(
'system_eth0-collisions'
,
'sum'
,
eth0_collision
),
(
'system_lo-outFlow'
,
'sum'
,
lo_tx
),
(
'system_lo-inFlow'
,
'sum'
,
lo_rx
),
(
'system_lo-dropped'
,
'sum'
,
lo_dropped
),
(
'system_lo-errors'
,
'sum'
,
lo_errors
),
(
'system_lo-collisions'
,
'sum'
,
lo_collision
),
(
'system_totalProcess'
,
'avg'
,
process_total
),
(
'system_runningProcess'
,
'avg'
,
process_running
),
(
'system_establishedTcp'
,
'avg'
,
tcp_established_num
),
(
'system_loginUsers'
,
'avg'
,
number_of_user_connected
),
(
'system_/-freeInodes'
,
'avg'
,
"%.3f"
%
(
float
(
inodes_free
)
/
int
(
inodes_total
))),
]
print
'
\n
'
.
join
([
'%s_%s%s=%s'
%
(
k
,
ip
,
t
and
':'
+
t
,
v
)
for
k
,
t
,
v
in
m
])
...
...
cat-agent/src/main/webapp/rmp/cat-agent-makerpm.sh
0 → 100644
浏览文件 @
d6b9f6f3
# pull cat-agent source and packge to RPM
# yum install rpm-build
# yum install rpmdevtools
set
-e
set
-u
if
[
!
$#
-eq
2
]
;
then
echo
"Usage: makerpm.sh tomcat/jboss version."
exit
1
fi
container
=
$1
version
=
$2
if
[
!
"
$1
"
=
"tomcat"
]
&&
[
!
"
$1
"
=
"jboss"
]
;
then
echo
"Usage: makerpm.sh tomcat/jboss version."
echo
"Container can only be tomcat or jboss."
exit
1
fi
CAT_ROOT
=
~/cat
CAT_DIR
=
~/cat/cat
TMP_DIR
=
~/tmp
RPM_SOURCE_NAME
=
cat-agent-
$container
-
$version
CAT_AGENT_INSTALL_DIR_NAME
=
cat-agent
mkdir
-p
$CAT_ROOT
cd
$CAT_ROOT
if
[
!
-e
$CAT_DIR
]
;
then
git clone https://github.com/dianping/cat.git
fi
cd
-
# pull lastest cat code
cd
$CAT_DIR
/cat-agent
git pull
# package it
mvn
-Dmaven
.test.skip clean package
cd
-
# prepare agent code
mkdir
-p
$TMP_DIR
cd
$TMP_DIR
rm
-rf
*
mkdir
-p
$RPM_SOURCE_NAME
/
$CAT_AGENT_INSTALL_DIR_NAME
unzip
-d
$RPM_SOURCE_NAME
/
$CAT_AGENT_INSTALL_DIR_NAME
$CAT_DIR
/cat-agent/target/cat-agent-
*
.war
tar
czf
$RPM_SOURCE_NAME
.tar.gz
$RPM_SOURCE_NAME
rpmdev-setuptree
cp
$RPM_SOURCE_NAME
.tar.gz ~/rpmbuild/SOURCES/
cp
$CAT_DIR
/cat-agent/src/main/rpm/cat-agent-
$container
.spec ~/rpmbuild/SPECS/
cd
-
rpmbuild
-bb
~/rpmbuild/SPECS/cat-agent-
$container
.spec
cat-agent/src/main/webapp/rmp/cat-agent-tomcat.spec
0 → 100644
浏览文件 @
d6b9f6f3
#%define name value
%define __jar_repack 0
Name: cat-agent-tomcat
Version: 1.0.5
Release: 1
Summary: cat-agent-tomcat
Requires: git
Requires(pre): /usr/sbin/useradd, /usr/bin/getent, /usr/sbin/usermod
Group: Development/Tools
License: GPL
Source0: %{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-XXXXXXXXXX)
%description
A powerful customized J2EE web container (JBoss, Jetty, Tomcat)
%pre
# add user cat
/usr/bin/getent passwd cat || /usr/sbin/useradd -u 2200 cat
/usr/sbin/usermod -a -G nobody cat || true
%prep
%setup -q
%build
%install
[ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT/*
# where to install agent files
AGENT_INSTALL_DIR=$RPM_BUILD_ROOT/data/webapps/cat/cat-agent
# create agent directories
[ -d $AGENT_INSTALL_DIR ] || mkdir -p $AGENT_INSTALL_DIR
# copy agent files to corresponding directories
cp -r cat-agent/* $AGENT_INSTALL_DIR/
chmod +x $AGENT_INSTALL_DIR/startup.sh
/bin/bash $AGENT_INSTALL_DIR/startup.sh
%post
# change required file permissions
APPLOGS_DIR=/data/applogs
APPDATAS_DIR=/data/appdatas
CAT_ROOT_DIR=/data/webapps/cat/
[ -d $APPLOGS_DIR ] && chown nobody:nobody $APPLOGS_DIR && chmod 775 $APPLOGS_DIR
[ -d $APPDATAS_DIR ] && chown nobody:nobody $APPDATAS_DIR && chmod 775 $APPDATAS_DIR
[ -d $CAT_ROOT_DIR ] && chown -R cat:cat $CAT_ROOT_DIR
# comment out Defaults requiretty to enabel sudo in scripts
awk 'BEGIN{result=""}{if(match($0, "^[^#]*Defaults[[:space:]]+requiretty")>0){result=sprintf("%s#%s\n",result,$0);}else{result=sprintf("%s%s\n",result,$0);}}END{print result > "/etc/sudoers"}' /etc/sudoers
AGENT_INSTALL_DIR=$RPM_BUILD_ROOT/data/webapps/cat/cat-agent
/bin/bash $AGENT_INSTALL_DIR/startup.sh
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,cat,cat,-)
/data/webapps/cat/cat-agent
%doc
%changelog
%preun
/usr/local/jdk/bin/jps -lvm | awk '$2=="com.dianping.cat.agent.monitor.CatAgent"{cmd=sprintf("kill -9 %s", $1);system(cmd)}'
%postun
/usr/local/jdk/bin/jps -lvm | awk '$2=="com.dianping.cat.agent.monitor.CatAgent"{cmd=sprintf("kill -9 %s", $1);system(cmd)}'
rm -rf /data/webapps/cat/cat-agent
cat-agent/src/main/webapp/startup.sh
浏览文件 @
d6b9f6f3
...
...
@@ -5,7 +5,13 @@ cd `dirname $0`
function
kill_by_javaclass
{
local
javaclass
=
$1
/usr/local/jdk/bin/jps
-lvm
|
awk
-v
javaclass
=
$javaclass
'$2==javaclass{cmd=sprintf("kill -s TERM %s; sleep 1; kill -9 %s", $1, $1);system(cmd)}'
jps
=
/usr/local/jdk/bin/jps
if
[
!
-x
$jps
]
;
then
jps
=
jps
fi
$jps
-lvm
|
awk
-v
javaclass
=
$javaclass
'$2==javaclass{cmd=sprintf("kill -s TERM %s; sleep 1; kill -9 %s", $1, $1);system(cmd)}'
}
agent_class
=
"com.dianping.cat.agent.monitor.CatAgent"
...
...
@@ -35,5 +41,12 @@ java=java
fi
echo
"Starting cat-agent
$agent_class
$port
`
pwd
`
"
nohup
$java
-Xms128m
-Xmx128m
-classpath
classes:
"lib/*"
-Dagent
=
$agent
$agent_class
$port
/agent
`
pwd
`
>>
/data/applogs/cat/agent-startup.log 2>&1 &
para
=
""
if
[
"
$agent
"
=
"paas"
]
;
then
ip
=
$(
sh
-c
"ifconfig br0 | awk -v FS='[
\t
:]+' 'NR == 2 {print
\$
4}'"
)
para
=
"-Dhost.ip=
$ip
"
fi
nohup
$java
-Xms128m
-Xmx128m
-classpath
classes:
"lib/*"
-Dagent
=
$agent
$para
$agent_class
$port
/agent
`
pwd
`
>>
/data/applogs/cat/agent-startup.log 2>&1 &
echo
"Started"
\ No newline at end of file
cat-broker/pom.xml
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<parent>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
parent
</artifactId>
<version>
1.0.5
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
broker-service
</artifactId>
<name>
broker-service
</name>
<packaging>
war
</packaging>
<dependencies>
<dependency>
<groupId>
org.unidal.eunit
</groupId>
<artifactId>
EunitTestFwk
</artifactId>
<version>
1.2.1
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
foundation-service
</artifactId>
<version>
2.0.5
</version>
</dependency>
<dependency>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
cat-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
1.6
</version>
</dependency>
<dependency>
<groupId>
org.unidal.webres
</groupId>
<artifactId>
WebResServer
</artifactId>
<version>
1.2.1
</version>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
web-framework
</artifactId>
<version>
2.0.5
</version>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
servlet-api
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
jstl
</artifactId>
<version>
1.2
</version>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jsp-api-2.1
</artifactId>
<version>
6.1.14
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jsp-2.1
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
<version>
2.3.9
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jetty
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
test-framework
</artifactId>
<version>
2.0.4
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
dal-jdbc
</artifactId>
<version>
2.0.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-email
</artifactId>
<version>
1.1
</version>
</dependency>
<dependency>
<groupId>
javax.mail
</groupId>
<artifactId>
mail
</artifactId>
<version>
1.4.4
</version>
</dependency>
<dependency>
<groupId>
com.google.code.javaparser
</groupId>
<artifactId>
javaparser
</artifactId>
<version>
1.0.8
</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>
${basedir}/src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>
org.unidal.maven.plugins
</groupId>
<artifactId>
codegen-maven-plugin
</artifactId>
<version>
2.0.9
</version>
<executions>
<execution>
<id>
generate plexus component descriptor
</id>
<phase>
process-classes
</phase>
<goals>
<goal>
plexus
</goal>
</goals>
<configuration>
<className>
com.dianping.cat.broker.build.ComponentsConfigurator
</className>
<env>
dev
</env>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-war-plugin
</artifactId>
<version>
2.1.1
</version>
<configuration>
<warName>
broker-service-${env}-${version}
</warName>
<webResources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
false
</filtering>
<targetPath>
WEB-INF/classes
</targetPath>
</resource>
<resource>
<directory>
src/main/webapp
</directory>
<filtering>
false
</filtering>
<includes>
<include>
WEB-INF/web.xml
</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
maven-jetty-plugin
</artifactId>
<version>
6.1.26
</version>
<configuration>
<scanIntervalSeconds>
10
</scanIntervalSeconds>
<contextPath>
/cat
</contextPath>
<defaultsDescriptor>
src/main/webapp/WEB-INF/web.xml
</defaultsDescriptor>
<connectors>
<connector
implementation=
"org.mortbay.jetty.nio.SelectChannelConnector"
>
<port>
2281
</port>
<maxIdleTime>
500000
</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<packaging>
war
</packaging>
<env>
alpha
</env>
<project.build.sourceEncoding>
utf-8
</project.build.sourceEncoding>
</properties>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<parent>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
parent
</artifactId>
<version>
1.0.5
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
broker-service
</artifactId>
<name>
broker-service
</name>
<packaging>
war
</packaging>
<dependencies>
<dependency>
<groupId>
org.unidal.eunit
</groupId>
<artifactId>
EunitTestFwk
</artifactId>
<version>
1.2.1
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
foundation-service
</artifactId>
<version>
2.0.5
</version>
</dependency>
<dependency>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
cat-core
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
1.6
</version>
</dependency>
<dependency>
<groupId>
org.unidal.webres
</groupId>
<artifactId>
WebResServer
</artifactId>
<version>
1.2.1
</version>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
web-framework
</artifactId>
<version>
2.0.5
</version>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
servlet-api
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
jstl
</artifactId>
<version>
1.2
</version>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jsp-api-2.1
</artifactId>
<version>
6.1.14
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jsp-2.1
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
<version>
2.3.9
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
jetty
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
test-framework
</artifactId>
<version>
2.0.4
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
dal-jdbc
</artifactId>
<version>
2.0.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-email
</artifactId>
<version>
1.1
</version>
</dependency>
<dependency>
<groupId>
javax.mail
</groupId>
<artifactId>
mail
</artifactId>
<version>
1.4.4
</version>
</dependency>
<dependency>
<groupId>
com.google.code.javaparser
</groupId>
<artifactId>
javaparser
</artifactId>
<version>
1.0.8
</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>
${basedir}/src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>
org.unidal.maven.plugins
</groupId>
<artifactId>
codegen-maven-plugin
</artifactId>
<version>
2.0.9
</version>
<executions>
<execution>
<id>
generate plexus component descriptor
</id>
<phase>
process-classes
</phase>
<goals>
<goal>
plexus
</goal>
</goals>
<configuration>
<className>
com.dianping.cat.broker.build.ComponentsConfigurator
</className>
<env>
dev
</env>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-war-plugin
</artifactId>
<version>
2.1.1
</version>
<configuration>
<warName>
broker-service-${env}-${version}
</warName>
<webResources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
false
</filtering>
<targetPath>
WEB-INF/classes
</targetPath>
</resource>
<resource>
<directory>
src/main/webapp
</directory>
<filtering>
false
</filtering>
<includes>
<include>
WEB-INF/web.xml
</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>
org.mortbay.jetty
</groupId>
<artifactId>
maven-jetty-plugin
</artifactId>
<version>
6.1.26
</version>
<configuration>
<scanIntervalSeconds>
10
</scanIntervalSeconds>
<contextPath>
/cat
</contextPath>
<defaultsDescriptor>
src/main/webapp/WEB-INF/web.xml
</defaultsDescriptor>
<connectors>
<connector
implementation=
"org.mortbay.jetty.nio.SelectChannelConnector"
>
<port>
2281
</port>
<maxIdleTime>
500000
</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<packaging>
war
</packaging>
<env>
alpha
</env>
<project.build.sourceEncoding>
utf-8
</project.build.sourceEncoding>
</properties>
</project>
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppData.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.broker.api.app
;
public
class
AppData
{
private
long
m_timestamp
;
private
int
m_city
;
private
int
m_operator
;
private
int
m_network
;
private
int
m_version
;
private
int
m_connectType
;
private
int
m_command
;
private
int
m_code
;
private
int
m_platform
;
private
int
m_count
;
private
int
m_requestByte
;
private
int
m_responseByte
;
private
int
m_responseTime
;
public
AppData
()
{
}
public
int
getCity
()
{
return
m_city
;
}
public
int
getCode
()
{
return
m_code
;
}
public
int
getCommand
()
{
return
m_command
;
}
public
int
getConnectType
()
{
return
m_connectType
;
}
public
int
getCount
()
{
return
m_count
;
}
public
int
getNetwork
()
{
return
m_network
;
}
public
int
getOperator
()
{
return
m_operator
;
}
public
int
getPlatform
()
{
return
m_platform
;
}
public
int
getRequestByte
()
{
return
m_requestByte
;
}
public
int
getResponseByte
()
{
return
m_responseByte
;
}
public
int
getResponseTime
()
{
return
m_responseTime
;
}
public
long
getTimestamp
()
{
return
m_timestamp
;
}
public
int
getVersion
()
{
return
m_version
;
}
public
AppData
setCity
(
int
city
)
{
m_city
=
city
;
return
this
;
}
public
AppData
setCode
(
int
code
)
{
m_code
=
code
;
return
this
;
}
public
AppData
setCommand
(
int
command
)
{
m_command
=
command
;
return
this
;
}
public
AppData
setConnectType
(
int
connectType
)
{
m_connectType
=
connectType
;
return
this
;
}
public
AppData
setCount
(
int
count
)
{
m_count
=
count
;
return
this
;
}
public
AppData
setNetwork
(
int
network
)
{
m_network
=
network
;
return
this
;
}
public
AppData
setOperator
(
int
operator
)
{
m_operator
=
operator
;
return
this
;
}
public
AppData
setPlatform
(
int
platform
)
{
m_platform
=
platform
;
return
this
;
}
public
AppData
setRequestByte
(
int
requestByte
)
{
m_requestByte
=
requestByte
;
return
this
;
}
public
AppData
setResponseByte
(
int
responseByte
)
{
m_responseByte
=
responseByte
;
return
this
;
}
public
AppData
setResponseTime
(
int
responseTime
)
{
m_responseTime
=
responseTime
;
return
this
;
}
public
AppData
setTimestamp
(
long
timestamp
)
{
m_timestamp
=
timestamp
;
return
this
;
}
public
AppData
setVersion
(
int
version
)
{
m_version
=
version
;
return
this
;
}
}
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppDataConsumer.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.broker.api.app
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.unidal.helper.Threads
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.config.app.AppDataService
;
public
class
AppDataConsumer
implements
Initializable
,
LogEnabled
{
public
static
final
long
DURATION
=
5
*
60
*
1000L
;
@Inject
private
AppDataService
m_appDataService
;
private
AppDataQueue
m_appDataQueue
;
private
long
m_dataLoss
;
private
Logger
m_logger
;
private
ConcurrentHashMap
<
Long
,
BucketHandler
>
m_tasks
;
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
public
void
enqueue
(
AppData
appData
)
{
m_appDataQueue
.
offer
(
appData
);
}
public
long
getDataLoss
()
{
return
m_dataLoss
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
m_appDataQueue
=
new
AppDataQueue
();
m_tasks
=
new
ConcurrentHashMap
<
Long
,
BucketHandler
>();
AppDataDispatcherThread
appDataDispatcherThread
=
new
AppDataDispatcherThread
();
BucketThreadController
bucketThreadController
=
new
BucketThreadController
();
Threads
.
forGroup
(
"Cat"
).
start
(
bucketThreadController
);
Threads
.
forGroup
(
"Cat"
).
start
(
appDataDispatcherThread
);
}
public
void
setDataLoss
(
long
dataLoss
)
{
m_dataLoss
=
dataLoss
;
}
private
class
AppDataDispatcherThread
implements
Task
{
private
static
final
String
NAME
=
"AppDataDispatcherThread"
;
@Override
public
String
getName
()
{
return
NAME
;
}
@Override
public
void
run
()
{
while
(
true
)
{
try
{
AppData
appData
=
m_appDataQueue
.
poll
();
if
(
appData
!=
null
)
{
long
timestamp
=
appData
.
getTimestamp
();
timestamp
-=
timestamp
%
DURATION
;
BucketHandler
handler
=
m_tasks
.
get
(
new
Long
(
timestamp
));
if
(
handler
==
null
||
!
handler
.
isActive
())
{
m_dataLoss
++;
if
(
m_dataLoss
%
1000
==
0
)
{
m_logger
.
error
(
"error timestamp in consumer, loss:"
+
m_dataLoss
);
}
}
else
{
handler
.
enqueue
(
appData
);
}
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
}
@Override
public
void
shutdown
()
{
}
}
private
class
BucketThreadController
implements
Task
{
private
void
closeLastTask
(
long
currentDuration
)
{
Long
last
=
new
Long
(
currentDuration
-
DURATION
);
BucketHandler
lastBucketHandler
=
m_tasks
.
get
(
last
);
if
(
lastBucketHandler
!=
null
)
{
lastBucketHandler
.
shutdown
();
}
}
@Override
public
String
getName
()
{
return
"BucketThreadController"
;
}
private
void
removeLastLastTask
(
long
currentDuration
)
{
Long
lastLast
=
new
Long
(
currentDuration
-
2
*
DURATION
);
m_tasks
.
remove
(
lastLast
);
}
@Override
public
void
run
()
{
while
(
true
)
{
long
curTime
=
System
.
currentTimeMillis
();
try
{
long
currentDuration
=
curTime
-
curTime
%
DURATION
;
removeLastLastTask
(
currentDuration
);
closeLastTask
(
currentDuration
);
startCurrentTask
(
currentDuration
);
startNextTask
(
currentDuration
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
long
elapsedTime
=
System
.
currentTimeMillis
()
-
curTime
;
try
{
Thread
.
sleep
(
DURATION
-
elapsedTime
);
}
catch
(
InterruptedException
e
)
{
}
}
}
@Override
public
void
shutdown
()
{
}
private
void
startCurrentTask
(
long
currentDuration
)
{
Long
cur
=
new
Long
(
currentDuration
);
if
(
m_tasks
.
get
(
cur
)
==
null
)
{
BucketHandler
curBucketHandler
=
new
BucketHandler
(
cur
,
m_appDataService
);
Threads
.
forGroup
(
"Cat"
).
start
(
curBucketHandler
);
m_tasks
.
put
(
cur
,
curBucketHandler
);
}
}
private
void
startNextTask
(
long
currentDuration
)
{
Long
next
=
new
Long
(
currentDuration
+
DURATION
);
if
(
m_tasks
.
get
(
next
)
==
null
)
{
BucketHandler
nextBucketHandler
=
new
BucketHandler
(
next
,
m_appDataService
);
Threads
.
forGroup
(
"Cat"
).
start
(
nextBucketHandler
);
m_tasks
.
put
(
next
,
nextBucketHandler
);
}
}
}
}
cat-broker/src/main/java/com/dianping/cat/broker/api/app/AppDataQueue.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.broker.api.app
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.TimeUnit
;
public
class
AppDataQueue
{
private
BlockingQueue
<
AppData
>
m_dataQueue
=
new
LinkedBlockingQueue
<
AppData
>(
10000
);
public
boolean
offer
(
AppData
appData
)
{
return
m_dataQueue
.
offer
(
appData
);
}
public
AppData
poll
()
{
AppData
appData
;
try
{
appData
=
m_dataQueue
.
poll
(
5
,
TimeUnit
.
MICROSECONDS
);
}
catch
(
InterruptedException
e
)
{
return
null
;
}
return
appData
;
}
}
cat-broker/src/main/java/com/dianping/cat/broker/api/app/BucketHandler.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.broker.api.app
;
import
java.io.BufferedWriter
;
import
java.io.FileWriter
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map.Entry
;
import
org.unidal.helper.Threads.Task
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.app.AppDataCommand
;
import
com.dianping.cat.config.app.AppDataService
;
public
class
BucketHandler
implements
Task
{
private
static
final
String
FILEDIRECTORY
=
"/data/appdatas/cat/app/"
;
private
static
int
ONE_MINUTE
=
60
*
1000
;
private
static
int
ONE_DAY
=
24
*
60
*
ONE_MINUTE
;
private
AppDataQueue
m_appDataQueue
;
private
AppDataService
m_appDataService
;
private
boolean
m_isActive
=
true
;
private
HashMap
<
Integer
,
HashMap
<
String
,
AppData
>>
m_mergedData
;
private
long
m_startTime
;
public
BucketHandler
(
long
startTime
,
AppDataService
appDataService
)
{
m_startTime
=
startTime
;
m_appDataQueue
=
new
AppDataQueue
();
m_mergedData
=
new
LinkedHashMap
<
Integer
,
HashMap
<
String
,
AppData
>>();
m_appDataService
=
appDataService
;
}
private
void
end
()
{
for
(
Entry
<
Integer
,
HashMap
<
String
,
AppData
>>
outerEntry
:
m_mergedData
.
entrySet
())
{
for
(
Entry
<
String
,
AppData
>
entry
:
outerEntry
.
getValue
().
entrySet
())
{
AppData
appData
=
entry
.
getValue
();
saveToDataBase
(
appData
);
}
}
}
public
void
enqueue
(
AppData
appData
)
{
m_appDataQueue
.
offer
(
appData
);
}
@Override
public
String
getName
()
{
return
"BucketHandler"
;
}
public
boolean
isActive
()
{
synchronized
(
this
)
{
return
m_isActive
;
}
}
private
void
processEntity
(
AppData
appData
)
{
int
command
=
appData
.
getCommand
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
m_startTime
).
append
(
":"
);
sb
.
append
(
appData
.
getCity
()).
append
(
":"
);
sb
.
append
(
appData
.
getOperator
()).
append
(
":"
);
sb
.
append
(
appData
.
getConnectType
()).
append
(
":"
);
sb
.
append
(
appData
.
getVersion
()).
append
(
":"
);
sb
.
append
(
appData
.
getNetwork
()).
append
(
":"
);
sb
.
append
(
appData
.
getCode
()).
append
(
":"
);
sb
.
append
(
appData
.
getPlatform
());
String
key
=
sb
.
toString
();
HashMap
<
String
,
AppData
>
secondMap
=
m_mergedData
.
get
(
command
);
if
(
secondMap
==
null
)
{
secondMap
=
new
LinkedHashMap
<
String
,
AppData
>();
secondMap
.
put
(
key
,
appData
);
m_mergedData
.
put
(
command
,
secondMap
);
}
else
{
AppData
mergedAppData
=
secondMap
.
get
(
key
);
if
(
mergedAppData
==
null
)
{
secondMap
.
put
(
key
,
appData
);
}
else
{
mergedAppData
.
setCount
(
mergedAppData
.
getCount
()
+
1
);
mergedAppData
.
setRequestByte
(
mergedAppData
.
getRequestByte
()
+
appData
.
getRequestByte
());
mergedAppData
.
setResponseByte
(
mergedAppData
.
getResponseByte
()
+
appData
.
getResponseByte
());
mergedAppData
.
setResponseTime
(
mergedAppData
.
getResponseTime
()
+
appData
.
getResponseTime
());
}
}
}
@Override
public
void
run
()
{
while
(
isActive
())
{
AppData
appData
=
m_appDataQueue
.
poll
();
if
(
appData
!=
null
)
{
processEntity
(
appData
);
}
}
while
(
true
)
{
AppData
appData
=
m_appDataQueue
.
poll
();
if
(
appData
!=
null
)
{
processEntity
(
appData
);
}
else
{
break
;
}
}
end
();
}
private
void
saveToDataBase
(
AppData
appData
)
{
int
minute
=
(
int
)
(
m_startTime
%
ONE_DAY
/
ONE_MINUTE
);
Date
period
=
new
Date
(
m_startTime
-
minute
*
ONE_MINUTE
);
try
{
AppDataCommand
proto
=
new
AppDataCommand
();
proto
.
setPeriod
(
period
);
proto
.
setMinuteOrder
(
minute
);
proto
.
setCommandId
(
appData
.
getCommand
());
proto
.
setCity
(
appData
.
getCity
());
proto
.
setOperator
(
appData
.
getOperator
());
proto
.
setNetwork
(
appData
.
getNetwork
());
proto
.
setAppVersion
(
appData
.
getVersion
());
proto
.
setConnnectType
(
appData
.
getConnectType
());
proto
.
setCode
(
appData
.
getCode
());
proto
.
setPlatform
(
appData
.
getPlatform
());
proto
.
setAccessNumber
(
appData
.
getCount
());
proto
.
setResponseSumTime
(
appData
.
getResponseTime
());
proto
.
setRequestPackage
(
appData
.
getRequestByte
());
proto
.
setResponsePackage
(
appData
.
getResponseByte
());
proto
.
setCreationDate
(
new
Date
());
m_appDataService
.
insert
(
proto
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
saveToFile
(
appData
);
}
}
private
void
saveToFile
(
AppData
appData
)
{
Date
date
=
new
Date
();
SimpleDateFormat
formater
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
dateStr
=
formater
.
format
(
date
);
String
filePath
=
FILEDIRECTORY
+
dateStr
;
try
{
BufferedWriter
writer
=
new
BufferedWriter
(
new
FileWriter
(
filePath
));
String
content
=
appData
.
getTimestamp
()
+
"\t"
+
appData
.
getCity
()
+
"\t"
+
appData
.
getOperator
()
+
"\t"
+
appData
.
getNetwork
()
+
"\t"
+
appData
.
getVersion
()
+
"\t"
+
appData
.
getConnectType
()
+
"\t"
+
appData
.
getCommand
()
+
"\t"
+
appData
.
getCode
()
+
"\t"
+
appData
.
getPlatform
()
+
"\t"
+
appData
.
getRequestByte
()
+
"\t"
+
appData
.
getResponseByte
()
+
"\t"
+
appData
.
getResponseTime
()
+
"\n"
;
writer
.
append
(
content
);
writer
.
close
();
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
@Override
public
void
shutdown
()
{
synchronized
(
this
)
{
m_isActive
=
false
;
}
}
}
cat-broker/src/main/java/com/dianping/cat/broker/api/page/IpService.java
浏览文件 @
d6b9f6f3
...
...
@@ -13,14 +13,14 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
import
com.dianping.cat.Cat
;
public
class
IpService
implements
Initializable
{
private
Map
<
Integer
,
Area
>
m_areas
;
private
Map
<
Integer
,
Corporation
>
m_corps
;
private
int
[]
m_areaIds
;
private
Map
<
Integer
,
Area
>
m_areas
;
private
int
[]
m_corpIds
;
private
Map
<
Integer
,
Corporation
>
m_corps
;
private
long
[]
m_ends
;
private
long
[]
m_starts
;
...
...
@@ -176,12 +176,12 @@ public class IpService implements Initializable {
public
static
class
Area
{
private
Integer
m_areaId
;
private
String
m_city
;
private
String
m_nation
;
private
String
m_province
;
private
String
m_city
;
public
Integer
getAreaId
()
{
return
m_areaId
;
}
...
...
@@ -240,13 +240,13 @@ public class IpService implements Initializable {
}
public
static
class
IpInfo
{
private
String
m_nation
;
private
String
m_province
;
private
String
m_channel
;
private
String
m_city
;
private
String
m_channel
;
private
String
m_nation
;
private
String
m_province
;
public
String
getChannel
()
{
return
m_channel
;
...
...
cat-broker/src/main/java/com/dianping/cat/broker/api/page/batch/Handler.java
浏览文件 @
d6b9f6f3
...
...
@@ -15,13 +15,27 @@ import org.unidal.web.mvc.annotation.InboundActionMeta;
import
org.unidal.web.mvc.annotation.OutboundActionMeta
;
import
org.unidal.web.mvc.annotation.PayloadMeta
;
import
com.dianping.cat.broker.api.app.AppData
;
import
com.dianping.cat.broker.api.app.AppDataConsumer
;
import
com.dianping.cat.broker.api.page.Constrants
;
import
com.dianping.cat.broker.api.page.IpService
;
import
com.dianping.cat.broker.api.page.IpService.IpInfo
;
import
com.dianping.cat.broker.api.page.MonitorEntity
;
import
com.dianping.cat.broker.api.page.MonitorManager
;
import
com.dianping.cat.broker.api.page.RequestUtils
;
import
com.dianping.cat.config.app.AppConfigManager
;
public
class
Handler
implements
PageHandler
<
Context
>,
LogEnabled
{
@Inject
private
AppDataConsumer
m_appDataConsumer
;
@Inject
private
IpService
m_ipService
;
@Inject
private
AppConfigManager
m_appConfigManager
;
@Inject
private
MonitorManager
m_manager
;
...
...
@@ -49,7 +63,18 @@ public class Handler implements PageHandler<Context>, LogEnabled {
HttpServletRequest
request
=
ctx
.
getHttpServletRequest
();
HttpServletResponse
response
=
ctx
.
getHttpServletResponse
();
String
userIp
=
m_util
.
getRemoteIp
(
request
);
String
version
=
payload
.
getVersion
();
if
(
version
.
equals
(
"1"
))
{
processVersion1
(
payload
,
request
,
userIp
);
}
else
if
(
version
.
equals
(
"2"
))
{
processVersion2
(
payload
,
request
,
userIp
);
}
response
.
getWriter
().
write
(
"OK"
);
}
private
void
processVersion1
(
Payload
payload
,
HttpServletRequest
request
,
String
userIp
)
{
if
(
userIp
!=
null
)
{
try
{
String
content
=
payload
.
getContent
();
...
...
@@ -88,7 +113,61 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
else
{
m_logger
.
info
(
"unknown http request, x-forwarded-for:"
+
request
.
getHeader
(
"x-forwarded-for"
));
}
response
.
getWriter
().
write
(
"OK"
);
}
private
void
processVersion2
(
Payload
payload
,
HttpServletRequest
request
,
String
userIp
)
{
if
(
userIp
!=
null
)
{
String
content
=
payload
.
getContent
();
String
records
[]
=
content
.
split
(
"\n"
);
IpInfo
ipInfo
=
m_ipService
.
findIpInfoByString
(
userIp
);
if
(
ipInfo
!=
null
)
{
String
province
=
ipInfo
.
getProvince
();
String
operatorStr
=
ipInfo
.
getChannel
();
Integer
cityId
=
m_appConfigManager
.
getCities
().
get
(
province
);
Integer
operatorId
=
m_appConfigManager
.
getOperators
().
get
(
operatorStr
);
if
(
cityId
!=
null
&&
operatorId
!=
null
)
{
for
(
String
record
:
records
)
{
processOneRecord
(
cityId
,
operatorId
,
record
);
}
}
}
}
else
{
m_logger
.
info
(
"unknown http request, x-forwarded-for:"
+
request
.
getHeader
(
"x-forwarded-for"
));
}
}
private
void
processOneRecord
(
int
cityId
,
int
operatorId
,
String
record
)
{
String
items
[]
=
record
.
split
(
"\t"
);
if
(
items
.
length
==
10
)
{
AppData
appData
=
new
AppData
();
try
{
appData
.
setTimestamp
(
Long
.
parseLong
(
items
[
0
]));
Integer
command
=
m_appConfigManager
.
getCommands
().
get
(
items
[
2
]);
if
(
command
!=
null
)
{
appData
.
setCommand
(
command
);
appData
.
setNetwork
(
Integer
.
parseInt
(
items
[
2
]));
appData
.
setVersion
(
Integer
.
parseInt
(
items
[
3
]));
appData
.
setConnectType
(
Integer
.
parseInt
(
items
[
4
]));
appData
.
setCode
(
Integer
.
parseInt
(
items
[
5
]));
appData
.
setPlatform
(
Integer
.
parseInt
(
items
[
6
]));
appData
.
setRequestByte
(
Integer
.
parseInt
(
items
[
7
]));
appData
.
setResponseByte
(
Integer
.
parseInt
(
items
[
8
]));
appData
.
setResponseTime
(
Integer
.
parseInt
(
items
[
9
]));
appData
.
setCity
(
cityId
);
appData
.
setOperator
(
operatorId
);
appData
.
setCount
(
1
);
m_appDataConsumer
.
enqueue
(
appData
);
}
}
catch
(
Exception
e
)
{
m_logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
private
boolean
validate
(
String
errorCode
,
String
httpStatus
)
{
...
...
cat-broker/src/main/java/com/dianping/cat/broker/api/page/js/Handler.java
浏览文件 @
d6b9f6f3
...
...
@@ -46,12 +46,12 @@ public class Handler implements PageHandler<Context> {
Payload
payload
=
ctx
.
getPayload
();
long
timestamp
=
payload
.
getTimestamp
();
String
error
=
payload
.
getError
();
String
url
=
payload
.
getUrl
();
String
host
=
parseHost
();
String
url
=
payload
.
getUrl
();
HttpServletResponse
response
=
ctx
.
getHttpServletResponse
();
if
(
host
.
contains
(
"dianping"
))
{
if
(
url
==
null
||
url
.
length
()
==
0
||
(!
url
.
startsWith
(
"http:"
))
)
{
if
(
url
==
null
||
url
.
length
()
==
0
)
{
if
(
m_referer
!=
null
)
{
url
=
m_referer
;
}
else
{
...
...
@@ -63,7 +63,7 @@ public class Handler implements PageHandler<Context> {
if
(
index
>
-
1
)
{
url
=
url
.
substring
(
0
,
index
);
}
Cat
.
logEvent
(
"Error"
,
parse
File
(
url
),
"Error"
,
error
);
Cat
.
logEvent
(
"Error"
,
parse
Url
(
url
),
"Error"
,
error
);
Cat
.
logEvent
(
"Agent"
,
parseValue
(
"Agent"
,
m_data
),
Message
.
SUCCESS
,
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
).
format
(
new
Date
(
timestamp
)));
...
...
@@ -76,11 +76,11 @@ public class Handler implements PageHandler<Context> {
response
.
getWriter
().
write
(
"OK"
);
}
private
String
parse
File
(
String
file
)
{
String
result
=
m_manager
.
handle
(
AggregationConfigManager
.
PROBLEM_TYPE
,
Constants
.
FRONT_END
,
file
);
private
String
parse
Url
(
String
url
)
{
String
result
=
m_manager
.
handle
(
AggregationConfigManager
.
PROBLEM_TYPE
,
Constants
.
FRONT_END
,
url
);
if
(
result
.
equals
(
file
))
{
return
subUrl
(
file
);
if
(
result
.
equals
(
url
))
{
return
subUrl
(
url
);
}
else
{
return
result
;
}
...
...
cat-broker/src/main/java/com/dianping/cat/broker/build/ComponentsConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -4,12 +4,17 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.unidal.dal.jdbc.datasource.JdbcDataSourceDescriptorManager
;
import
org.unidal.dal.jdbc.mapping.TableProvider
;
import
org.unidal.lookup.configuration.AbstractResourceConfigurator
;
import
org.unidal.lookup.configuration.Component
;
import
com.dianping.cat.broker.api.app.AppDataConsumer
;
import
com.dianping.cat.broker.api.page.IpService
;
import
com.dianping.cat.broker.api.page.MonitorManager
;
import
com.dianping.cat.broker.api.page.RequestUtils
;
import
com.dianping.cat.build.AppDatabaseConfigurator
;
import
com.dianping.cat.config.app.AppDataCommandTableProvider
;
import
com.dianping.cat.config.app.AppDataService
;
import
com.dianping.cat.config.url.UrlPatternConfigManager
;
public
class
ComponentsConfigurator
extends
AbstractResourceConfigurator
{
...
...
@@ -20,11 +25,16 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
IpService
.
class
));
all
.
add
(
C
(
RequestUtils
.
class
));
all
.
add
(
C
(
MonitorManager
.
class
).
req
(
UrlPatternConfigManager
.
class
,
IpService
.
class
));
all
.
add
(
C
(
AppDataConsumer
.
class
).
req
(
AppDataService
.
class
));
all
.
add
(
C
(
TableProvider
.
class
,
"app-data-command"
,
AppDataCommandTableProvider
.
class
));
// database
all
.
add
(
C
(
JdbcDataSourceDescriptorManager
.
class
)
//
.
config
(
E
(
"datasourceFile"
).
value
(
"/data/appdatas/cat/datasources.xml"
)));
all
.
addAll
(
new
AppDatabaseConfigurator
().
defineComponents
());
// Please keep it as last
all
.
addAll
(
new
WebComponentConfigurator
().
defineComponents
());
...
...
cat-broker/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
d6b9f6f3
...
...
@@ -20,6 +20,20 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.broker.api.app.AppDataConsumer
</role>
<implementation>
com.dianping.cat.broker.api.app.AppDataConsumer
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.config.app.AppDataService
</role>
</requirement>
</requirements>
</component>
<component>
<role>
org.unidal.dal.jdbc.mapping.TableProvider
</role>
<role-hint>
app-data-command
</role-hint>
<implementation>
com.dianping.cat.config.app.AppDataCommandTableProvider
</implementation>
</component>
<component>
<role>
org.unidal.dal.jdbc.datasource.JdbcDataSourceDescriptorManager
</role>
<implementation>
org.unidal.dal.jdbc.datasource.JdbcDataSourceDescriptorManager
</implementation>
...
...
@@ -27,6 +41,25 @@
<datasourceFile>
/data/appdatas/cat/datasources.xml
</datasourceFile>
</configuration>
</component>
<component>
<role>
org.unidal.dal.jdbc.mapping.TableProvider
</role>
<role-hint>
app-data-command
</role-hint>
<implementation>
org.unidal.dal.jdbc.mapping.SimpleTableProvider
</implementation>
<configuration>
<logical-table-name>
app-data-command
</logical-table-name>
<physical-table-name>
app_data_command
</physical-table-name>
<data-source-name>
app
</data-source-name>
</configuration>
</component>
<component>
<role>
com.dianping.cat.app.AppDataCommandDao
</role>
<implementation>
com.dianping.cat.app.AppDataCommandDao
</implementation>
<requirements>
<requirement>
<role>
org.unidal.dal.jdbc.QueryEngine
</role>
</requirement>
</requirements>
</component>
<component>
<role>
org.unidal.web.mvc.model.ModuleRegistry
</role>
<implementation>
org.unidal.web.mvc.model.ModuleRegistry
</implementation>
...
...
@@ -97,6 +130,15 @@
<role>
com.dianping.cat.broker.api.page.batch.Handler
</role>
<implementation>
com.dianping.cat.broker.api.page.batch.Handler
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.broker.api.app.AppDataConsumer
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.broker.api.page.IpService
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.config.app.AppConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.broker.api.page.MonitorManager
</role>
</requirement>
...
...
@@ -105,6 +147,45 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.broker.api.app.AppDataConsumer
</role>
<implementation>
com.dianping.cat.broker.api.app.AppDataConsumer
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.config.app.AppDataService
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.config.app.AppDataService
</role>
<implementation>
com.dianping.cat.config.app.AppDataService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.app.AppDataCommandDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.config.app.AppConfigManager
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.app.AppDataCommandDao
</role>
<implementation>
com.dianping.cat.app.AppDataCommandDao
</implementation>
<requirements>
<requirement>
<role>
org.unidal.dal.jdbc.QueryEngine
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.config.app.AppConfigManager
</role>
<implementation>
com.dianping.cat.config.app.AppConfigManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.config.ConfigDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.broker.api.page.js.Handler
</role>
<implementation>
com.dianping.cat.broker.api.page.js.Handler
</implementation>
...
...
cat-broker/src/main/resources/META-INF/wizard/model/manifest.xml
0 → 100644
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<file
path=
"wizard.xml"
/>
</manifest>
cat-broker/src/main/resources/META-INF/wizard/model/wizard.xml
0 → 100644
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="utf-8"?>
<wizard
package=
"com.dianping.cat.service"
>
<model
package=
"com.dianping.cat.service.appData"
name=
"appData"
>
<sample-model>
app
</sample-model>
</model>
</wizard>
cat-broker/src/main/webapp/jsp/api/app.jsp
0 → 100644
浏览文件 @
d6b9f6f3
<%@ page
contentType=
"text/html; charset=utf-8"
%>
<jsp:useBean
id=
"ctx"
type=
"com.dianping.cat.broker.api.page.app.Context"
scope=
"request"
/>
<jsp:useBean
id=
"payload"
type=
"com.dianping.cat.broker.api.page.app.Payload"
scope=
"request"
/>
<jsp:useBean
id=
"model"
type=
"com.dianping.cat.broker.api.page.app.Model"
scope=
"request"
/>
View of app page under api
\ No newline at end of file
cat-broker/src/test/java/com/dianping/cat/broker/AppTest.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.broker
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
AppTest
{
public
static
void
main
(
String
[]
args
)
throws
UnsupportedEncodingException
{
List
<
String
>
urls
=
new
ArrayList
<
String
>();
String
url_pre
=
"http://localhost:2765/broker-service/api/batch"
;
long
timestamp
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
urls
.
add
(
url_pre
+
"?v=2&c="
+
timestamp
+
URLEncoder
.
encode
(
"\tshop.bin\t1\t1\t1\t1\t1\t1\t1\t1\n"
,
"utf-8"
));
}
for
(
String
url
:
urls
)
{
System
.
out
.
println
(
url
);
sendGet
(
url
);
}
}
public
static
String
sendGet
(
String
url
)
{
String
result
=
""
;
BufferedReader
in
=
null
;
try
{
URL
realUrl
=
new
URL
(
url
);
URLConnection
connection
=
realUrl
.
openConnection
();
connection
.
connect
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
}
return
result
;
}
}
cat-client/src/main/java/com/dianping/cat/CatClientModule.java
浏览文件 @
d6b9f6f3
...
...
@@ -34,7 +34,7 @@ public class CatClientModule extends AbstractModule {
ThreadRenamingRunnable
.
setThreadNameDeterminer
(
ThreadNameDeterminer
.
CURRENT
);
// tracking thread start/stop
//
Threads.addListener(new CatThreadListener(ctx));
Threads
.
addListener
(
new
CatThreadListener
(
ctx
));
File
clientConfigFile
=
ctx
.
getAttribute
(
"cat-client-config-file"
);
ClientConfigManager
clientConfigManager
=
ctx
.
lookup
(
ClientConfigManager
.
class
);
...
...
cat-client/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
浏览文件 @
d6b9f6f3
...
...
@@ -233,10 +233,10 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
public
void
setTraceMode
(
boolean
traceMode
)
{
Context
conte
n
t
=
getContext
();
Context
conte
x
t
=
getContext
();
if
(
conte
n
t
!=
null
)
{
conte
n
t
.
setTraceMode
(
traceMode
);
if
(
conte
x
t
!=
null
)
{
conte
x
t
.
setTraceMode
(
traceMode
);
}
}
...
...
@@ -583,4 +583,9 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
}
}
@Override
public
String
getDomain
()
{
return
m_domain
.
getId
();
}
}
cat-client/src/main/java/com/dianping/cat/message/spi/MessageManager.java
浏览文件 @
d6b9f6f3
...
...
@@ -97,5 +97,11 @@ public interface MessageManager {
* title shown in the logview
*/
public
void
bind
(
String
tag
,
String
title
);
/**
* get domain
*
*/
public
String
getDomain
();
}
\ No newline at end of file
cat-client/src/main/java/com/dianping/cat/servlet/CatFilter.java
浏览文件 @
d6b9f6f3
...
...
@@ -16,7 +16,9 @@ import javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponseWrapper
;
import
org.unidal.helper.Joiners
;
import
org.unidal.helper.Joiners.IBuilder
;
...
...
@@ -25,6 +27,7 @@ import com.dianping.cat.Cat;
import
com.dianping.cat.CatConstants
;
import
com.dianping.cat.configuration.NetworkInterfaceManager
;
import
com.dianping.cat.configuration.client.entity.Server
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.MessageProducer
;
import
com.dianping.cat.message.Transaction
;
...
...
@@ -44,7 +47,8 @@ public class CatFilter implements Filter {
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
Context
ctx
=
new
Context
((
HttpServletRequest
)
request
,
(
HttpServletResponse
)
response
,
chain
,
m_handlers
);
Context
ctx
=
new
Context
(
new
RequestWrapper
((
HttpServletRequest
)
request
),
new
ResponseWrapper
(
(
HttpServletResponse
)
response
),
chain
,
m_handlers
);
ctx
.
handle
();
}
...
...
@@ -78,6 +82,8 @@ public class CatFilter implements Filter {
protected
int
detectMode
(
HttpServletRequest
req
)
{
String
source
=
req
.
getHeader
(
"X-CAT-SOURCE"
);
String
id
=
req
.
getHeader
(
"X-CAT-ID"
);
Cat
.
setup
(
null
);
if
(
"container"
.
equals
(
source
))
{
return
2
;
...
...
@@ -88,20 +94,6 @@ public class CatFilter implements Filter {
}
}
protected
String
getCookie
(
HttpServletRequest
req
,
String
name
)
{
Cookie
[]
cookies
=
req
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
Cookie
cookie
:
cookies
)
{
if
(
name
.
equalsIgnoreCase
(
cookie
.
getName
()))
{
return
cookie
.
getValue
();
}
}
}
return
null
;
}
@Override
public
void
handle
(
Context
ctx
)
throws
IOException
,
ServletException
{
HttpServletRequest
req
=
ctx
.
getRequest
();
...
...
@@ -113,8 +105,6 @@ public class CatFilter implements Filter {
ctx
.
setMode
(
detectMode
(
req
));
ctx
.
setType
(
CatConstants
.
TYPE_URL
);
Cat
.
setup
(
getCookie
(
req
,
"JSESSIONID"
));
setTraceMode
(
req
);
}
else
{
ctx
.
setType
(
CatConstants
.
TYPE_URL_FORWARD
);
...
...
@@ -167,6 +157,8 @@ public class CatFilter implements Filter {
@Override
public
void
handle
(
Context
ctx
)
throws
IOException
,
ServletException
{
boolean
isTraceMode
=
Cat
.
getManager
().
isTraceMode
();
HttpServletRequest
req
=
ctx
.
getRequest
();
HttpServletResponse
res
=
ctx
.
getResponse
();
MessageProducer
producer
=
Cat
.
getProducer
();
...
...
@@ -190,28 +182,30 @@ public class CatFilter implements Filter {
throw
new
RuntimeException
(
String
.
format
(
"Internal Error: unsupported mode(%s)!"
,
mode
));
}
MessageTree
tree
=
Cat
.
getManager
().
getThreadLocalMessageTree
();
tree
.
setMessageId
(
ctx
.
getId
());
tree
.
setParentMessageId
(
ctx
.
getParentId
());
tree
.
setRootMessageId
(
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-SERVER"
,
getCatServer
());
switch
(
mode
)
{
case
0
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getId
());
break
;
case
1
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-PARENT-ID"
,
ctx
.
getParentId
());
res
.
setHeader
(
"X-CAT-ID"
,
ctx
.
getId
());
break
;
case
2
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-PARENT-ID"
,
ctx
.
getParentId
());
res
.
setHeader
(
"X-CAT-ID"
,
ctx
.
getId
());
break
;
if
(
isTraceMode
)
{
MessageTree
tree
=
Cat
.
getManager
().
getThreadLocalMessageTree
();
tree
.
setMessageId
(
ctx
.
getId
());
tree
.
setParentMessageId
(
ctx
.
getParentId
());
tree
.
setRootMessageId
(
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-SERVER"
,
getCatServer
());
switch
(
mode
)
{
case
0
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getId
());
break
;
case
1
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-PARENT-ID"
,
ctx
.
getParentId
());
res
.
setHeader
(
"X-CAT-ID"
,
ctx
.
getId
());
break
;
case
2
:
res
.
setHeader
(
"X-CAT-ROOT-ID"
,
ctx
.
getRootId
());
res
.
setHeader
(
"X-CAT-PARENT-ID"
,
ctx
.
getParentId
());
res
.
setHeader
(
"X-CAT-ID"
,
ctx
.
getId
());
break
;
}
}
ctx
.
handle
();
...
...
@@ -433,7 +427,160 @@ public class CatFilter implements Filter {
}
}
public
static
class
CookieWrapper
extends
Cookie
{
private
Cookie
m_cookie
;
public
CookieWrapper
(
Cookie
cookie
)
{
super
(
cookie
.
getName
(),
cookie
.
getValue
());
m_cookie
=
cookie
;
}
public
CookieWrapper
(
String
name
,
String
value
)
{
super
(
name
,
value
);
}
public
Object
clone
()
{
return
m_cookie
.
clone
();
}
public
boolean
equals
(
Object
obj
)
{
return
m_cookie
.
equals
(
obj
);
}
public
String
getComment
()
{
return
m_cookie
.
getComment
();
}
public
String
getDomain
()
{
return
m_cookie
.
getDomain
();
}
public
int
getMaxAge
()
{
return
m_cookie
.
getMaxAge
();
}
public
String
getName
()
{
return
m_cookie
.
getName
();
}
public
String
getPath
()
{
return
m_cookie
.
getPath
();
}
public
boolean
getSecure
()
{
return
m_cookie
.
getSecure
();
}
public
String
getValue
()
{
Event
event
=
Cat
.
newEvent
(
Cat
.
getManager
().
getDomain
()
+
":ReadCookie"
,
m_cookie
.
getName
());
event
.
setStatus
(
Event
.
SUCCESS
);
event
.
addData
(
"domain"
,
m_cookie
.
getDomain
());
event
.
addData
(
"path"
,
m_cookie
.
getPath
());
event
.
addData
(
"maxAge"
,
m_cookie
.
getMaxAge
());
event
.
complete
();
return
m_cookie
.
getValue
();
}
public
int
getVersion
()
{
return
m_cookie
.
getVersion
();
}
public
int
hashCode
()
{
return
m_cookie
.
hashCode
();
}
public
void
setComment
(
String
purpose
)
{
m_cookie
.
setComment
(
purpose
);
}
public
void
setDomain
(
String
pattern
)
{
m_cookie
.
setDomain
(
pattern
);
}
public
void
setMaxAge
(
int
expiry
)
{
m_cookie
.
setMaxAge
(
expiry
);
}
public
void
setPath
(
String
uri
)
{
m_cookie
.
setPath
(
uri
);
}
public
void
setSecure
(
boolean
flag
)
{
m_cookie
.
setSecure
(
flag
);
}
public
void
setValue
(
String
newValue
)
{
m_cookie
.
setValue
(
newValue
);
}
public
void
setVersion
(
int
v
)
{
m_cookie
.
setVersion
(
v
);
}
public
String
toString
()
{
return
m_cookie
.
toString
();
}
}
protected
static
interface
Handler
{
public
void
handle
(
Context
ctx
)
throws
IOException
,
ServletException
;
}
public
static
class
RequestWrapper
extends
HttpServletRequestWrapper
{
private
HttpServletRequest
m_request
;
public
RequestWrapper
(
HttpServletRequest
request
)
{
super
(
request
);
m_request
=
request
;
}
@Override
public
Cookie
[]
getCookies
()
{
Cookie
[]
cookies
=
m_request
.
getCookies
();
if
(
cookies
!=
null
)
{
int
length
=
cookies
.
length
;
CookieWrapper
[]
wappers
=
new
CookieWrapper
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
wappers
[
i
]
=
new
CookieWrapper
(
cookies
[
i
]);
}
return
wappers
;
}
else
{
return
null
;
}
}
}
public
static
class
ResponseWrapper
extends
HttpServletResponseWrapper
{
public
ResponseWrapper
(
HttpServletResponse
response
)
{
super
(
response
);
}
@Override
public
void
addCookie
(
Cookie
cookie
)
{
Event
event
=
Cat
.
newEvent
(
Cat
.
getManager
().
getDomain
()
+
":SetCookie"
,
cookie
.
getName
());
event
.
setStatus
(
Event
.
SUCCESS
);
event
.
addData
(
"domain"
,
cookie
.
getDomain
());
event
.
addData
(
"path"
,
cookie
.
getPath
());
event
.
addData
(
"maxAge"
,
cookie
.
getMaxAge
());
event
.
complete
();
super
.
addCookie
(
cookie
);
}
@Override
public
void
addHeader
(
String
name
,
String
value
)
{
Event
event
=
Cat
.
newEvent
(
Cat
.
getManager
().
getDomain
()
+
":SetHead"
,
name
);
event
.
setStatus
(
Event
.
SUCCESS
);
event
.
addData
(
"value"
,
value
);
event
.
complete
();
super
.
addHeader
(
name
,
value
);
}
}
}
cat-client/src/test/java/com/dianping/cat/servlet/CatFilterTest.java
浏览文件 @
d6b9f6f3
...
...
@@ -63,17 +63,6 @@ public class CatFilterTest extends JettyServer {
context
.
addFilter
(
CatFilter
.
class
,
"/*"
,
Handler
.
REQUEST
);
}
@Test
public
void
testForABTest
()
throws
Exception
{
String
url
=
"http://localhost:2282/mock/abtest?metricType=mockMetric"
;
InputStream
in
=
Urls
.
forIO
().
openStream
(
url
);
String
content
=
Files
.
forIO
().
readFrom
(
in
,
"utf-8"
);
Assert
.
assertEquals
(
"mock content here!"
,
content
);
TimeUnit
.
MILLISECONDS
.
sleep
(
100
);
}
@Test
public
void
testMode0
()
throws
Exception
{
String
url
=
"http://localhost:2282/mock/mode0"
;
...
...
@@ -119,6 +108,7 @@ public class CatFilterTest extends JettyServer {
Map
<
String
,
List
<
String
>>
headers
=
new
HashMap
<
String
,
List
<
String
>>();
InputStream
in
=
Urls
.
forIO
().
connectTimeout
(
100
)
//
.
header
(
"X-Cat-Source"
,
"container"
)
//
.
header
(
"X-CAT-TRACE-MODE"
,
"true"
)
//
.
openStream
(
url
,
headers
);
String
content
=
Files
.
forIO
().
readFrom
(
in
,
"utf-8"
);
...
...
@@ -150,14 +140,19 @@ public class CatFilterTest extends JettyServer {
private
String
getHeader
(
Map
<
String
,
List
<
String
>>
headers
,
String
name
)
{
List
<
String
>
values
=
headers
.
get
(
name
);
int
len
=
values
.
size
();
if
(
len
==
0
)
{
if
(
values
!=
null
)
{
int
len
=
values
.
size
();
if
(
len
==
0
)
{
return
null
;
}
else
if
(
len
==
1
)
{
return
values
.
get
(
0
);
}
else
{
return
Joiners
.
by
(
','
).
join
(
values
);
}
}
else
{
return
null
;
}
else
if
(
len
==
1
)
{
return
values
.
get
(
0
);
}
else
{
return
Joiners
.
by
(
','
).
join
(
values
);
}
}
...
...
cat-consumer-advanced/src/main/java/com/dianping/cat/consumer/metric/MetricAnalyzer.java
浏览文件 @
d6b9f6f3
...
...
@@ -103,7 +103,7 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
if
(
StringUtils
.
isEmpty
(
data
))
{
data
=
"1"
;
}
int
count
=
Integer
.
parseInt
(
data
);
int
count
=
(
int
)
Double
.
parseDouble
(
data
);
config
.
setCount
(
count
);
config
.
setValue
((
double
)
count
);
...
...
cat-consumer-advanced/src/test/java/com/dianping/cat/consumer/metric/MetricConfigManagerTest.java
浏览文件 @
d6b9f6f3
...
...
@@ -74,7 +74,6 @@ public class MetricConfigManagerTest {
configs
.
put
(
item
,
3L
);
Assert
.
assertEquals
(
3L
,
configs
.
get
(
item
).
longValue
());
Assert
.
assertEquals
(
1
,
configs
.
size
());
}
@Test
...
...
cat-core/pom.xml
浏览文件 @
d6b9f6f3
...
...
@@ -27,7 +27,7 @@
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
dal-jdbc
</artifactId>
<version>
2.
0.4
</version>
<version>
2.
1.1
</version>
</dependency>
<dependency>
<groupId>
org.jboss.netty
</groupId>
...
...
@@ -83,6 +83,7 @@
<manifest>
${basedir}/src/main/resources/META-INF/dal/jdbc/report-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/jdbc/config-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/jdbc/app-manifest.xml,
</manifest>
</configuration>
</execution>
...
...
cat-core/src/main/java/com/dianping/cat/build/AppDatabaseConfigurator.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.build
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.unidal.dal.jdbc.configuration.AbstractJdbcResourceConfigurator
;
import
org.unidal.lookup.configuration.Component
;
final
public
class
AppDatabaseConfigurator
extends
AbstractJdbcResourceConfigurator
{
@Override
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
// all.add(defineJdbcDataSourceComponent("app", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1:3306/cat", "root", "***", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
defineSimpleTableProviderComponents
(
all
,
"app"
,
com
.
dianping
.
cat
.
app
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
app
.
_INDEX
.
getDaoClasses
());
return
all
;
}
}
cat-core/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.build
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.unidal.dal.jdbc.configuration.AbstractJdbcResourceConfigurator
;
import
org.unidal.lookup.configuration.Component
;
final
class
CatDatabaseConfigurator
extends
AbstractJdbcResourceConfigurator
{
@Override
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
// all.add(defineJdbcDataSourceComponent("cat", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1:3306/cat", "root", "***", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
defineSimpleTableProviderComponents
(
all
,
"cat"
,
com
.
dianping
.
cat
.
core
.
dal
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
core
.
dal
.
_INDEX
.
getDaoClasses
());
defineSimpleTableProviderComponents
(
all
,
"cat"
,
com
.
dianping
.
cat
.
core
.
config
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
core
.
config
.
_INDEX
.
getDaoClasses
());
return
all
;
}
}
cat-core/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -12,10 +12,12 @@ import com.dianping.cat.DomainManager;
import
com.dianping.cat.ServerConfigManager
;
import
com.dianping.cat.analysis.DefaultMessageAnalyzerManager
;
import
com.dianping.cat.analysis.MessageAnalyzerManager
;
import
com.dianping.cat.app.AppDataCommandDao
;
import
com.dianping.cat.config.aggregation.AggregationConfigManager
;
import
com.dianping.cat.config.aggregation.AggregationHandler
;
import
com.dianping.cat.config.aggregation.DefaultAggregationHandler
;
import
com.dianping.cat.config.app.AppConfigManager
;
import
com.dianping.cat.config.app.AppDataService
;
import
com.dianping.cat.config.url.DefaultUrlPatternHandler
;
import
com.dianping.cat.config.url.UrlPatternConfigManager
;
import
com.dianping.cat.config.url.UrlPatternHandler
;
...
...
@@ -61,9 +63,11 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
AggregationHandler
.
class
,
DefaultAggregationHandler
.
class
));
all
.
add
(
C
(
AggregationConfigManager
.
class
).
req
(
AggregationHandler
.
class
,
ConfigDao
.
class
));
all
.
add
(
C
(
AppConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
AppConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
AppDataService
.
class
).
req
(
AppConfigManager
.
class
,
AppDataCommandDao
.
class
));
all
.
add
(
C
(
UrlPatternHandler
.
class
,
DefaultUrlPatternHandler
.
class
));
all
.
add
(
C
(
UrlPatternConfigManager
.
class
).
req
(
ConfigDao
.
class
,
UrlPatternHandler
.
class
));
...
...
cat-core/src/main/java/com/dianping/cat/config/app/AppConfigManager.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.config.app
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.unidal.dal.jdbc.DalException
;
...
...
@@ -12,17 +18,26 @@ import org.unidal.lookup.annotation.Inject;
import
org.xml.sax.SAXException
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.configuration.app.entity.AppConfig
;
import
com.dianping.cat.configuration.app.entity.Code
;
import
com.dianping.cat.configuration.app.entity.ConfigItem
;
import
com.dianping.cat.configuration.app.entity.Item
;
import
com.dianping.cat.configuration.app.entity.Command
;
import
com.dianping.cat.configuration.app.transform.DefaultSaxParser
;
import
com.dianping.cat.core.config.Config
;
import
com.dianping.cat.core.config.ConfigDao
;
import
com.dianping.cat.core.config.ConfigEntity
;
import
com.dianping.cat.home.app.entity.AppConfig
;
import
com.dianping.cat.home.app.entity.ConfigItem
;
import
com.dianping.cat.home.app.transform.DefaultSaxParser
;
public
class
AppConfigManager
implements
Initializable
{
@Inject
protected
ConfigDao
m_configDao
;
private
Map
<
String
,
Integer
>
m_commands
=
new
HashMap
<
String
,
Integer
>();
private
Map
<
String
,
Integer
>
m_cities
=
new
HashMap
<
String
,
Integer
>();
private
Map
<
String
,
Integer
>
m_operators
=
new
HashMap
<
String
,
Integer
>();
private
int
m_configId
;
private
static
final
String
CONFIG_NAME
=
"app-config"
;
...
...
@@ -31,6 +46,22 @@ public class AppConfigManager implements Initializable {
private
long
m_modifyTime
;
public
static
String
NETWORK
=
"网络类型"
;
public
static
String
OPERATOR
=
"运营商"
;
public
static
String
VERSION
=
"版本"
;
public
static
String
PLATFORM
=
"平台"
;
public
static
String
CITY
=
"城市"
;
public
static
String
CONNECT_TYPE
=
"连接类型"
;
public
AppConfig
getConfig
()
{
return
m_config
;
}
@Override
public
void
initialize
()
{
try
{
...
...
@@ -74,12 +105,76 @@ public class AppConfigManager implements Initializable {
}
}
public
AppConfig
getConfig
()
{
return
m_config
;
public
Collection
<
Code
>
queryCodeByCommand
(
int
command
)
{
Command
c
=
m_config
.
findCommand
(
command
);
if
(
c
!=
null
)
{
return
c
.
getCodes
().
values
();
}
else
{
return
Collections
.
emptySet
();
}
}
public
ConfigItem
queryConfigItem
(
String
name
)
{
return
m_config
.
findConfigItem
(
name
);
public
List
<
Command
>
queryCommands
()
{
return
new
ArrayList
<
Command
>(
m_config
.
getCommands
().
values
());
}
public
List
<
Item
>
queryConfigItem
(
String
name
)
{
ConfigItem
config
=
m_config
.
findConfigItem
(
name
);
if
(
config
!=
null
)
{
return
new
ArrayList
<
Item
>(
config
.
getItems
().
values
());
}
else
{
return
new
ArrayList
<
Item
>();
}
}
public
Map
<
String
,
Integer
>
getCommands
()
{
return
m_commands
;
}
public
Map
<
String
,
Integer
>
getCities
()
{
return
m_cities
;
}
public
Map
<
String
,
Integer
>
getOperators
()
{
return
m_operators
;
}
private
void
refreshData
()
{
Collection
<
Command
>
commands
=
m_config
.
getCommands
().
values
();
Map
<
String
,
Integer
>
commandMap
=
new
HashMap
<
String
,
Integer
>();
for
(
Command
c
:
commands
)
{
commandMap
.
put
(
c
.
getName
(),
c
.
getId
());
}
m_commands
=
commandMap
;
Map
<
String
,
Integer
>
cityMap
=
new
HashMap
<
String
,
Integer
>();
ConfigItem
cities
=
m_config
.
findConfigItem
(
CITY
);
for
(
Item
item:
cities
.
getItems
().
values
()){
cityMap
.
put
(
item
.
getName
(),
item
.
getId
());
}
m_cities
=
cityMap
;
Map
<
String
,
Integer
>
operatorMap
=
new
HashMap
<
String
,
Integer
>();
ConfigItem
operations
=
m_config
.
findConfigItem
(
OPERATOR
);
for
(
Item
item:
operations
.
getItems
().
values
()){
operatorMap
.
put
(
item
.
getName
(),
item
.
getId
());
}
m_operators
=
operatorMap
;
}
public
Collection
<
Item
>
queryConfigItems
(
String
key
)
{
ConfigItem
configs
=
m_config
.
findConfigItem
(
key
);
if
(
configs
!=
null
)
{
return
configs
.
getItems
().
values
();
}
else
{
return
new
ArrayList
<
Item
>();
}
}
public
void
refreshAppConfigConfig
()
throws
DalException
,
SAXException
,
IOException
{
...
...
@@ -89,9 +184,10 @@ public class AppConfigManager implements Initializable {
synchronized
(
this
)
{
if
(
modifyTime
>
m_modifyTime
)
{
String
content
=
config
.
getContent
();
AppConfig
pattern
=
DefaultSaxParser
.
parse
(
content
);
AppConfig
appConfig
=
DefaultSaxParser
.
parse
(
content
);
m_config
=
pattern
;
m_config
=
appConfig
;
refreshData
();
m_modifyTime
=
modifyTime
;
}
}
...
...
@@ -106,6 +202,8 @@ public class AppConfigManager implements Initializable {
config
.
setName
(
CONFIG_NAME
);
config
.
setContent
(
m_config
.
toString
());
m_configDao
.
updateByPK
(
config
,
ConfigEntity
.
UPDATESET_FULL
);
refreshData
();
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
return
false
;
...
...
cat-core/src/main/java/com/dianping/cat/config/app/AppDataCommandTableProvider.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.config.app
;
import
java.util.Map
;
import
org.unidal.dal.jdbc.QueryEngine
;
import
org.unidal.dal.jdbc.mapping.TableProvider
;
import
com.dianping.cat.app.AppDataCommand
;
public
class
AppDataCommandTableProvider
implements
TableProvider
{
private
String
m_logicalTableName
=
"app-data-command"
;
private
String
m_physicalTableName
=
"app_data_command"
;
private
String
m_dataSourceName
=
"app"
;
@Override
public
String
getDataSourceName
(
Map
<
String
,
Object
>
hints
)
{
return
m_dataSourceName
;
}
@Override
public
String
getLogicalTableName
()
{
return
m_logicalTableName
;
}
@Override
public
String
getPhysicalTableName
(
Map
<
String
,
Object
>
hints
)
{
AppDataCommand
command
=
(
AppDataCommand
)
hints
.
get
(
QueryEngine
.
HINT_DATA_OBJECT
);
return
m_physicalTableName
+
"_"
+
command
.
getCommandId
();
}
public
void
setDataSourceName
(
String
dataSourceName
)
{
m_dataSourceName
=
dataSourceName
;
}
public
void
setLogicalTableName
(
String
logicalTableName
)
{
m_logicalTableName
=
logicalTableName
;
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/config/app/AppDataService.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.config.app
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.tuple.Pair
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.app.AppDataCommand
;
import
com.dianping.cat.app.AppDataCommandDao
;
import
com.dianping.cat.app.AppDataCommandEntity
;
import
com.dianping.cat.configuration.app.entity.Code
;
public
class
AppDataService
{
@Inject
private
AppDataCommandDao
m_dao
;
@Inject
private
AppConfigManager
m_appConfigManager
;
public
static
final
String
SUCCESS
=
"success"
;
public
static
final
String
REQUEST
=
"request"
;
public
static
final
String
DELAY
=
"delay"
;
public
void
insert
(
AppDataCommand
proto
)
throws
DalException
{
m_dao
.
insert
(
proto
);
}
public
void
insert
(
AppDataCommand
[]
proto
)
throws
DalException
{
m_dao
.
insert
(
proto
);
}
public
double
[]
queryValue
(
QueryEntity
entity
,
String
type
)
{
int
commandId
=
entity
.
getCommand
();
Date
period
=
entity
.
getDate
();
int
city
=
entity
.
getCity
();
int
operator
=
entity
.
getOperator
();
int
network
=
entity
.
getNetwork
();
int
appVersion
=
entity
.
getVersion
();
int
connnectType
=
entity
.
getChannel
();
int
code
=
entity
.
getCode
();
int
platform
=
entity
.
getPlatfrom
();
List
<
AppDataCommand
>
datas
;
try
{
if
(
SUCCESS
.
equals
(
type
))
{
datas
=
m_dao
.
findDataByMinuteCode
(
commandId
,
period
,
city
,
operator
,
network
,
appVersion
,
connnectType
,
code
,
platform
,
AppDataCommandEntity
.
READSET_SUCCESS_DATA
);
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
=
convert2AppDataCommandMap
(
datas
);
return
querySuccessRatio
(
commandId
,
dataPair
);
}
else
if
(
REQUEST
.
equals
(
type
))
{
datas
=
m_dao
.
findDataByMinute
(
commandId
,
period
,
city
,
operator
,
network
,
appVersion
,
connnectType
,
code
,
platform
,
AppDataCommandEntity
.
READSET_COUNT_DATA
);
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
=
convert2AppDataCommandMap
(
datas
);
return
queryRequestCount
(
dataPair
);
}
else
if
(
DELAY
.
equals
(
type
))
{
datas
=
m_dao
.
findDataByMinute
(
commandId
,
period
,
city
,
operator
,
network
,
appVersion
,
connnectType
,
code
,
platform
,
AppDataCommandEntity
.
READSET_AVG_DATA
);
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
=
convert2AppDataCommandMap
(
datas
);
return
queryDelayAvg
(
dataPair
);
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
e
.
printStackTrace
();
}
return
null
;
}
private
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
convert2AppDataCommandMap
(
List
<
AppDataCommand
>
fromDatas
)
{
Map
<
Integer
,
List
<
AppDataCommand
>>
dataMap
=
new
LinkedHashMap
<
Integer
,
List
<
AppDataCommand
>>();
int
max
=
-
1
;
for
(
AppDataCommand
from
:
fromDatas
)
{
int
minute
=
from
.
getMinuteOrder
();
if
(
max
<
0
||
max
<
minute
)
{
max
=
minute
;
}
List
<
AppDataCommand
>
data
=
dataMap
.
get
(
minute
);
if
(
data
==
null
)
{
data
=
new
LinkedList
<
AppDataCommand
>();
dataMap
.
put
(
minute
,
data
);
}
data
.
add
(
from
);
}
int
n
=
max
/
5
;
return
new
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>(
n
,
dataMap
);
}
public
double
[]
querySuccessRatio
(
int
commandId
,
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
)
{
double
[]
value
=
new
double
[
dataPair
.
getKey
()];
Map
<
Integer
,
List
<
AppDataCommand
>>
dataMap
=
dataPair
.
getValue
();
try
{
for
(
Entry
<
Integer
,
List
<
AppDataCommand
>>
entry
:
dataMap
.
entrySet
())
{
int
key
=
entry
.
getKey
();
long
success
=
0
;
long
sum
=
0
;
for
(
AppDataCommand
data
:
entry
.
getValue
())
{
long
number
=
data
.
getAccessNumberSum
();
if
(
isSuccessStatus
(
commandId
,
data
.
getCode
()))
{
success
+=
number
;
}
sum
+=
number
;
}
value
[
key
/
5
-
1
]
=
(
double
)
success
/
sum
;
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
return
value
;
}
private
boolean
isSuccessStatus
(
int
commandId
,
int
code
)
{
Collection
<
Code
>
codes
=
m_appConfigManager
.
queryCodeByCommand
(
commandId
);
for
(
Code
c
:
codes
)
{
if
(
c
.
getId
()
==
code
)
{
return
(
c
.
getStatus
()
==
0
);
}
}
return
false
;
}
public
double
[]
queryRequestCount
(
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
)
{
double
[]
value
=
new
double
[
dataPair
.
getKey
()];
for
(
Entry
<
Integer
,
List
<
AppDataCommand
>>
entry
:
dataPair
.
getValue
().
entrySet
())
{
for
(
AppDataCommand
data
:
entry
.
getValue
())
{
long
count
=
data
.
getAccessNumberSum
();
value
[
data
.
getMinuteOrder
()
/
5
-
1
]
=
count
;
}
}
return
value
;
}
public
double
[]
queryDelayAvg
(
Pair
<
Integer
,
Map
<
Integer
,
List
<
AppDataCommand
>>>
dataPair
)
{
double
[]
value
=
new
double
[
dataPair
.
getKey
()];
for
(
Entry
<
Integer
,
List
<
AppDataCommand
>>
entry
:
dataPair
.
getValue
().
entrySet
())
{
for
(
AppDataCommand
data
:
entry
.
getValue
())
{
long
count
=
data
.
getAccessNumberSum
();
long
sum
=
data
.
getResponseSumTimeSum
();
double
avg
=
sum
/
count
;
value
[
data
.
getMinuteOrder
()
/
5
-
1
]
=
avg
;
}
}
return
value
;
}
}
cat-
home/src/main/java/com/dianping/cat/report/page
/app/QueryEntity.java
→
cat-
core/src/main/java/com/dianping/cat/config
/app/QueryEntity.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.
report.page
.app
;
package
com.dianping.cat.
config
.app
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
...
...
@@ -117,4 +117,11 @@ public class QueryEntity {
m_operator
=
operator
;
}
@Override
public
String
toString
()
{
return
"QueryEntity [m_date="
+
m_date
+
", m_command="
+
m_command
+
", m_code="
+
m_code
+
", m_network="
+
m_network
+
", m_version="
+
m_version
+
", m_channel="
+
m_channel
+
", m_platfrom="
+
m_platfrom
+
", m_city="
+
m_city
+
", m_operator="
+
m_operator
+
"]"
;
}
}
cat-core/src/main/resources/META-INF/dal/jdbc/app-codegen.xml
0 → 100644
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<entities>
<entity
name=
"app-data-command"
table=
"app_data_command"
alias=
"adc"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"minute-order"
field=
"minute_order"
value-type=
"int"
length=
"5"
nullable=
"false"
/>
<member
name=
"status"
field=
"status"
value-type=
"int"
length=
"5"
nullable=
"false"
/>
<member
name=
"city"
field=
"city"
value-type=
"int"
length=
"5"
nullable=
"false"
/>
<member
name=
"operator"
field=
"operator"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"network"
field=
"network"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"app-version"
field=
"app_version"
value-type=
"int"
length=
"5"
nullable=
"false"
/>
<member
name=
"connnect-type"
field=
"connnect_type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"code"
field=
"code"
value-type=
"int"
length=
"5"
nullable=
"false"
/>
<member
name=
"platform"
field=
"platform"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"access-number"
field=
"access_number"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"response-sum-time"
field=
"response_sum_time"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"request-package"
field=
"request_package"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"response-package"
field=
"response_package"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
<index
name=
"IX_period_city_minute"
members=
"period ASC, city ASC, minute_order ASC"
/>
<index
name=
"IX_period_operator_minute"
members=
"period ASC, network ASC, minute_order ASC"
/>
<index
name=
"IX_period_network_minute"
members=
"period ASC, network ASC, minute_order ASC"
/>
<index
name=
"IX_period_version_minute"
members=
"period ASC, app_version ASC, minute_order ASC"
/>
<index
name=
"IX_period_connnect_minute"
members=
"period ASC, connnect_type ASC, minute_order ASC"
/>
<index
name=
"IX_period_platform_minute"
members=
"period ASC, platform ASC, minute_order ASC"
/>
<index
name=
"IX_period_code_minute"
members=
"period ASC, code ASC, minute_order ASC"
/>
<readsets>
<readset
name=
"FULL"
all=
"true"
/>
</readsets>
<updatesets>
<updateset
name=
"FULL"
all=
"true"
/>
</updatesets>
<query-defs>
<query
name=
"find-by-PK"
type=
"SELECT"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"insert"
type=
"INSERT"
>
<statement>
<![CDATA[INSERT INTO <TABLE/>
(
<FIELDS/>
)
VALUES(
<VALUES/>
)]]>
</statement>
</query>
<query
name=
"update-by-PK"
type=
"UPDATE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[UPDATE <TABLE/>
SET
<FIELDS/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"delete-by-PK"
type=
"DELETE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[DELETE FROM <TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
</query-defs>
</entity>
</entities>
cat-core/src/main/resources/META-INF/dal/jdbc/app-dal.xml
0 → 100644
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<entities
do-package=
"com.dianping.cat.app"
gen=
"true"
>
<entity
name=
"app-data-command"
table=
"app_data_command"
alias=
"adc"
>
<member
name=
"access-number"
field=
"access_number"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"response-sum-time"
field=
"response_sum_time"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"request-package"
field=
"request_package"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"response-package"
field=
"response_package"
value-type=
"long"
length=
"19"
nullable=
"false"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"access-number-sum"
value-type=
"long"
all=
"false"
select-expr=
"sum(access_number)"
length=
"19"
nullable=
"false"
/>
<member
name=
"response-sum-time-sum"
value-type=
"long"
all=
"false"
select-expr=
"sum(response_sum_time)"
length=
"19"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<var
name=
"command-id"
value-type=
"int"
/>
<readsets>
<readset
name=
"COUNT-DATA"
>
<member
name=
"minute-order"
/>
<member
name=
"access-number-sum"
/>
</readset>
<readset
name=
"AVG-DATA"
>
<member
name=
"minute-order"
/>
<member
name=
"access-number-sum"
/>
<member
name=
"response-sum-time-sum"
/>
</readset>
<readset
name=
"SUCCESS-DATA"
>
<member
name=
"minute-order"
/>
<member
name=
"code"
/>
<member
name=
"access-number-sum"
/>
</readset>
</readsets>
<query-defs>
<query
name=
"insert"
type=
"INSERT"
batch=
"true"
>
<statement>
<![CDATA[INSERT INTO <TABLE/>
(
<FIELDS/>
)
VALUES(
<VALUES/>
)]]>
</statement>
</query>
<query
name=
"find-data-by-minute"
type=
"SELECT"
multiple=
"true"
>
<param
name=
"command-id"
/><param
name=
"period"
/>
<param
name=
"period"
/>
<param
name=
"city"
/>
<param
name=
"operator"
/>
<param
name=
"network"
/>
<param
name=
"app-version"
/>
<param
name=
"connnect-type"
/>
<param
name=
"code"
/>
<param
name=
"platform"
/>
<statement>
<![CDATA[SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'period'
/>
= ${period}
<IF
type=
'NOT_ZERO'
field=
'city'
>
AND
<FIELD
name=
'city'
/>
= ${city}
</IF>
<IF
type=
'NOT_ZERO'
field=
'operator'
>
AND
<FIELD
name=
'operator'
/>
= ${operator}
</IF>
<IF
type=
'NOT_ZERO'
field=
'network'
>
AND
<FIELD
name=
'network'
/>
= ${network}
</IF>
<IF
type=
'NOT_ZERO'
field=
'app-version'
>
AND
<FIELD
name=
'app-version'
/>
= ${app-version}
</IF>
<IF
type=
'NOT_ZERO'
field=
'connnect-type'
>
AND
<FIELD
name=
'connnect-type'
/>
= ${connnect-type}
</IF>
<IF
type=
'NOT_ZERO'
field=
'code'
>
AND
<FIELD
name=
'code'
/>
= ${code}
</IF>
<IF
type=
'NOT_ZERO'
field=
'platform'
>
AND
<FIELD
name=
'platform'
/>
= ${platform}
</IF>
group by
<FIELD
name=
'minute-order'
/>
]]>
</statement>
</query>
<query
name=
"find-data-by-minute-code"
type=
"SELECT"
multiple=
"true"
>
<param
name=
"command-id"
/><param
name=
"period"
/>
<param
name=
"period"
/>
<param
name=
"city"
/>
<param
name=
"operator"
/>
<param
name=
"network"
/>
<param
name=
"app-version"
/>
<param
name=
"connnect-type"
/>
<param
name=
"code"
/>
<param
name=
"platform"
/>
<statement>
<![CDATA[SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'period'
/>
= ${period}
<IF
type=
'NOT_ZERO'
field=
'city'
>
AND
<FIELD
name=
'city'
/>
= ${city}
</IF>
<IF
type=
'NOT_ZERO'
field=
'operator'
>
AND
<FIELD
name=
'operator'
/>
= ${operator}
</IF>
<IF
type=
'NOT_ZERO'
field=
'network'
>
AND
<FIELD
name=
'network'
/>
= ${network}
</IF>
<IF
type=
'NOT_ZERO'
field=
'app-version'
>
AND
<FIELD
name=
'app-version'
/>
= ${app-version}
</IF>
<IF
type=
'NOT_ZERO'
field=
'connnect-type'
>
AND
<FIELD
name=
'connnect-type'
/>
= ${connnect-type}
</IF>
<IF
type=
'NOT_ZERO'
field=
'code'
>
AND
<FIELD
name=
'code'
/>
= ${code}
</IF>
<IF
type=
'NOT_ZERO'
field=
'platform'
>
AND
<FIELD
name=
'platform'
/>
= ${platform}
</IF>
group by
<FIELD
name=
'minute-order'
/>
,
<FIELD
name=
'code'
/>
]]>
</statement>
</query>
</query-defs>
</entity>
</entities>
cat-core/src/main/resources/META-INF/dal/jdbc/app-manifest.xml
0 → 100644
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<file
path=
"app-codegen.xml"
/>
<file
path=
"app-dal.xml"
/>
</manifest>
cat-core/src/main/resources/META-INF/dal/jdbc/config-codegen.xml
浏览文件 @
d6b9f6f3
...
...
@@ -2,7 +2,7 @@
<entities>
<entity
name=
"config"
table=
"config"
alias=
"c"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"50"
nullable=
"false"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"50"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"2147483647"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"modify-date"
field=
"modify_date"
value-type=
"Date"
nullable=
"false"
/>
...
...
cat-core/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
浏览文件 @
d6b9f6f3
...
...
@@ -3,8 +3,8 @@
<entity
name=
"dailygraph"
table=
"dailygraph"
alias=
"d"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"detail-content"
field=
"detail_content"
value-type=
"String"
length=
"16777215"
nullable=
"false"
/>
...
...
@@ -46,8 +46,8 @@
<entity
name=
"dailyreport"
table=
"dailyreport"
alias=
"d2"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"16777215"
nullable=
"false"
/>
...
...
@@ -55,6 +55,7 @@
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
<index
name=
"period"
unique=
"true"
members=
"period ASC, domain ASC, name ASC"
/>
<index
name=
"type"
members=
"type ASC"
/>
<readsets>
<readset
name=
"FULL"
all=
"true"
/>
</readsets>
...
...
@@ -88,8 +89,8 @@
<entity
name=
"graph"
table=
"graph"
alias=
"g"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"detail-content"
field=
"detail_content"
value-type=
"String"
length=
"16777215"
nullable=
"false"
/>
...
...
@@ -171,8 +172,8 @@
<entity
name=
"monthreport"
table=
"monthreport"
alias=
"m"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"16777215"
nullable=
"false"
/>
...
...
@@ -217,8 +218,8 @@
<member
name=
"project-line"
field=
"project_line"
value-type=
"String"
length=
"50"
/>
<member
name=
"department"
field=
"department"
value-type=
"String"
length=
"50"
/>
<member
name=
"owner"
field=
"owner"
value-type=
"String"
length=
"50"
/>
<member
name=
"phone"
field=
"phone"
value-type=
"String"
length=
"20"
/>
<member
name=
"email"
field=
"email"
value-type=
"String"
length=
"200"
/>
<member
name=
"phone"
field=
"phone"
value-type=
"String"
length=
"200"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
/>
<member
name=
"modify-date"
field=
"modify_date"
value-type=
"Date"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
...
...
@@ -257,10 +258,10 @@
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"50"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"2147483647"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"2147483647"
nullable=
"false"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
...
...
@@ -339,7 +340,7 @@
<member
name=
"consumer"
field=
"consumer"
value-type=
"String"
length=
"20"
/>
<member
name=
"failure-count"
field=
"failure_count"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"report-name"
field=
"report_name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"report-domain"
field=
"report_domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"report-domain"
field=
"report_domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"report-period"
field=
"report_period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"status"
field=
"status"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"task-type"
field=
"task_type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
...
...
@@ -382,8 +383,8 @@
<entity
name=
"weeklyreport"
table=
"weeklyreport"
alias=
"w"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"20"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
5
0"
nullable=
"false"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"
2
0"
nullable=
"false"
/>
<member
name=
"period"
field=
"period"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"type"
field=
"type"
value-type=
"int"
length=
"3"
nullable=
"false"
/>
<member
name=
"content"
field=
"content"
value-type=
"String"
length=
"16777215"
nullable=
"false"
/>
...
...
cat-core/src/main/resources/META-INF/dal/model/app-config-model.xml
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<model
model-package=
"com.dianping.cat.
home
.app"
root=
"true"
enable-merger=
"false"
enable-sax-parser=
"true"
<model
model-package=
"com.dianping.cat.
configuration
.app"
root=
"true"
enable-merger=
"false"
enable-sax-parser=
"true"
enable-base-visitor=
"false"
enable-xml-parser=
"false"
enable-xml-builder=
"false"
>
<entity
name=
"app-config"
>
<entity-ref
name=
"config-item"
type=
"map"
names=
"config-items"
method-find-or-create=
"true"
/>
<entity-ref
name=
"command"
type=
"map"
names=
"commands"
method-find-or-create=
"true"
/>
</entity>
<entity
name=
"config-item"
>
<attribute
name=
"id"
value-type=
"String"
key=
"true"
/>
...
...
@@ -11,6 +12,15 @@
<entity
name=
"item"
>
<attribute
name=
"id"
value-type=
"int"
key=
"true"
/>
<attribute
name=
"name"
value-type=
"String"
/>
<attribute
name=
"des"
value-type=
"String"
/>
</entity>
<entity
name=
"command"
>
<attribute
name=
"id"
value-type=
"int"
key=
"true"
/>
<attribute
name=
"name"
value-type=
"String"
/>
<entity-ref
name=
"code"
type=
"map"
names=
"codes"
method-find-or-create=
"true"
/>
</entity>
<entity
name=
"code"
>
<attribute
name=
"id"
value-type=
"int"
key=
"true"
/>
<attribute
name=
"name"
value-type=
"String"
/>
<attribute
name=
"status"
value-type=
"int"
/>
</entity>
</model>
\ No newline at end of file
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
d6b9f6f3
...
...
@@ -88,6 +88,18 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.config.app.AppDataService
</role>
<implementation>
com.dianping.cat.config.app.AppDataService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.config.app.AppConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.app.AppDataCommandDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.config.url.UrlPatternHandler
</role>
<implementation>
com.dianping.cat.config.url.DefaultUrlPatternHandler
</implementation>
...
...
cat-core/src/main/resources/META-INF/wizard/jdbc/wizard.xml
浏览文件 @
d6b9f6f3
...
...
@@ -24,4 +24,16 @@
<table
name=
"config"
/>
</group>
</jdbc>
<jdbc
package=
"com.dianping.cat.app"
name=
"app"
>
<datasource>
<driver>
com.mysql.jdbc.Driver
</driver>
<url>
jdbc:mysql://127.0.0.1:3306/cat
</url>
<user>
root
</user>
<password>
password
</password>
<properties>
useUnicode=true
&
autoReconnect=true
</properties>
</datasource>
<group
name=
"app"
package=
"com.dianping.cat.app"
>
<table
name=
"app_data_command"
/>
</group>
</jdbc>
</wizard>
cat-hadoop/pom.xml
浏览文件 @
d6b9f6f3
...
...
@@ -49,7 +49,7 @@
<plugin>
<groupId>
org.unidal.maven.plugins
</groupId>
<artifactId>
codegen-maven-plugin
</artifactId>
<version>
2.0.
8
</version>
<version>
2.0.
14
</version>
<executions>
<execution>
<id>
generate plexus component descriptor
</id>
...
...
cat-home/pom.xml
浏览文件 @
d6b9f6f3
...
...
@@ -96,11 +96,6 @@
<version>
2.0.4
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
dal-jdbc
</artifactId>
<version>
2.0.4
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-email
</artifactId>
...
...
cat-home/src/main/java/com/dianping/cat/CookieFilter.class
0 → 100644
浏览文件 @
d6b9f6f3
@@
-
0
,
0
+
1
,
166
@@
package
com
.
dianping
.
cat
;
import
java
.
io
.
File
;
import
java
.
io
.
IOException
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
javax
.
servlet
.
Filter
;
import
javax
.
servlet
.
FilterChain
;
import
javax
.
servlet
.
FilterConfig
;
import
javax
.
servlet
.
ServletException
;
import
javax
.
servlet
.
ServletRequest
;
import
javax
.
servlet
.
ServletResponse
;
import
javax
.
servlet
.
http
.
Cookie
;
import
javax
.
servlet
.
http
.
HttpServletRequest
;
import
javax
.
servlet
.
http
.
HttpServletResponse
;
import
org
.
unidal
.
eunit
.
helper
.
Files
;
import
com
.
dianping
.
lion
.
client
.
ConfigCache
;
import
com
.
google
.
gson
.
JsonArray
;
import
com
.
google
.
gson
.
JsonElement
;
import
com
.
google
.
gson
.
JsonObject
;
import
com
.
google
.
gson
.
JsonParser
;
public
class
CookieFilter
implements
Filter
{
private
static
Map
<
String
,
Item
>
validateCookies
;
private
static
final
String
KEY
=
"neocortex-4j.cookies.whiteList"
;
public
static
void
main
(
String
args
[])
throws
Exception
{
String
value
=
Files
.
forIO
().
readFrom
(
new
File
(
"/data/appdatas/cat/cookies"
),
"utf-8"
);
JsonElement
element
=
new
JsonParser
().
parse
(
value
);
JsonArray
array
=
element
.
getAsJsonArray
();
List
<
Item
>
items
=
new
ArrayList
<
Item
>();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
JsonObject
str
=
array
.
get
(
i
).
getAsJsonObject
();
String
name
=
str
.
get
(
"name"
).
getAsString
();
String
domain
=
str
.
get
(
"domain"
).
getAsString
();
String
path
=
str
.
get
(
"path"
).
getAsString
();
items
.
add
(
new
Item
(
name
,
domain
,
path
));
}
validateCookies
=
new
HashMap
<
String
,
Item
>();
for
(
Item
item
:
items
)
{
validateCookies
.
put
(
item
.
getName
(),
item
);
System
.
out
.
println
(
item
.
toString
());
}
}
@
Override
public
void
destroy
()
{
}
@
Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
try
{
HttpServletRequest
httpServletRequest
=
(
HttpServletRequest
)
request
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
response
;
Cookie
[]
cookies
=
httpServletRequest
.
getCookies
();
String
domain
=
httpServletRequest
.
getServerName
();
String
path
=
httpServletRequest
.
getRequestURI
();
System
.
out
.
println
(
"domain:"
+
domain
+
" path:"
+
path
);
if
(
cookies
!= null) {
for
(
Cookie
c
:
cookies
)
{
String
name
=
c
.
getName
();
if
(
validateCookies
!= null) {
Item
item
=
validateCookies
.
get
(
name
);
if
(
item
==
null
||
!item.getPath().equals(path) || !item.getDomain().equals(domain)) {
Cookie
temp
=
new
Cookie
(
name
,
null
);
temp
.
setPath
(
"/"
);
temp
.
setDomain
(
".dianping.com"
);
temp
.
setMaxAge
(
0
);
httpServletResponse
.
addCookie
(
temp
);
System
.
err
.
println
(
"kill "
+
c
.
getName
()
+
" "
+
temp
.
getPath
()+
" "
+
temp
.
getDomain
());
}
else
{
System
.
err
.
println
(
"not kill 222 "
+
c
.
getName
());
}
}
else
{
System
.
out
.
println
(
"map is null"
);
}
}
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
chain
.
doFilter
(
request
,
response
);
}
@
Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
try
{
//
ConfigCache
config
=
ConfigCache
.
getInstance
();
String
value
=
Files
.
forIO
().
readFrom
(
new
File
(
"/data/appdatas/cat/cookies"
),
"utf-8"
);
//
String
value
=
config
.
getProperty
(
KEY
);
JsonElement
element
=
new
JsonParser
().
parse
(
value
);
JsonArray
array
=
element
.
getAsJsonArray
();
List
<
Item
>
items
=
new
ArrayList
<
Item
>();
for
(
int
i
=
0
;
i
<
array
.
size
();
i
++)
{
JsonObject
str
=
array
.
get
(
i
).
getAsJsonObject
();
String
name
=
str
.
get
(
"name"
).
getAsString
();
String
domain
=
str
.
get
(
"domain"
).
getAsString
();
String
path
=
str
.
get
(
"path"
).
getAsString
();
items
.
add
(
new
Item
(
name
,
domain
,
path
));
}
validateCookies
=
new
HashMap
<
String
,
Item
>();
for
(
Item
item
:
items
)
{
validateCookies
.
put
(
item
.
getName
(),
item
);
System
.
out
.
println
(
"put:"
+
item
.
toString
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Cat
.
logError
(
e
);
}
}
public
static
class
Item
{
private
String
name
;
private
String
domain
;
private
String
path
;
public
Item
(
String
name
,
String
domain
,
String
path
)
{
this
.
name
=
name
;
this
.
domain
=
domain
;
this
.
path
=
path
;
}
public
String
getDomain
()
{
return
domain
;
}
public
String
getName
()
{
return
name
;
}
public
String
getPath
()
{
return
path
;
}
@
Override
public
String
toString
()
{
return
"Item [name="
+
name
+
", domain="
+
domain
+
", path="
+
path
+
"]"
;
}
}
}
cat-home/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -11,6 +11,8 @@ final class CatDatabaseConfigurator extends AbstractJdbcResourceConfigurator {
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
// all.add(defineJdbcDataSourceComponent("cat", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1:3306/cat", "root", "***", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
defineSimpleTableProviderComponents
(
all
,
"cat"
,
com
.
dianping
.
cat
.
home
.
dal
.
report
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
home
.
dal
.
report
.
_INDEX
.
getDaoClasses
());
...
...
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.unidal.dal.jdbc.datasource.JdbcDataSourceDescriptorManager
;
import
org.unidal.dal.jdbc.mapping.TableProvider
;
import
org.unidal.initialization.DefaultModuleManager
;
import
org.unidal.initialization.Module
;
import
org.unidal.initialization.ModuleManager
;
...
...
@@ -12,6 +13,8 @@ import org.unidal.lookup.configuration.Component;
import
com.dianping.cat.CatHomeModule
;
import
com.dianping.cat.ServerConfigManager
;
import
com.dianping.cat.config.app.AppDataCommandTableProvider
;
import
com.dianping.cat.config.app.AppDataService
;
import
com.dianping.cat.consumer.dependency.DependencyAnalyzer
;
import
com.dianping.cat.consumer.metric.MetricAnalyzer
;
import
com.dianping.cat.consumer.metric.MetricConfigManager
;
...
...
@@ -37,6 +40,7 @@ import com.dianping.cat.report.graph.GraphBuilder;
import
com.dianping.cat.report.graph.ValueTranslater
;
import
com.dianping.cat.report.page.JsonBuilder
;
import
com.dianping.cat.report.page.PayloadNormalizer
;
import
com.dianping.cat.report.page.app.graph.AppGraphCreator
;
import
com.dianping.cat.report.page.cdn.graph.CdnGraphCreator
;
import
com.dianping.cat.report.page.dependency.graph.TopologyGraphBuilder
;
import
com.dianping.cat.report.page.dependency.graph.TopologyGraphConfigManager
;
...
...
@@ -93,8 +97,40 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
generatePlexusComponentsXmlFile
(
new
ComponentsConfigurator
());
}
@Override
public
List
<
Component
>
defineComponents
()
{
private
List
<
Component
>
defineAlertComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
BusinessAlertConfig
.
class
).
req
(
AlertConfigManager
.
class
));
all
.
add
(
C
(
NetworkAlertConfig
.
class
).
req
(
AlertConfigManager
.
class
));
all
.
add
(
C
(
SystemAlertConfig
.
class
).
req
(
AlertConfigManager
.
class
));
all
.
add
(
C
(
ExceptionAlertConfig
.
class
).
req
(
AlertConfigManager
.
class
));
all
.
add
(
C
(
AlertInfo
.
class
));
all
.
add
(
C
(
DefaultMailImpl
.
class
).
req
(
ServerConfigManager
.
class
));
all
.
add
(
C
(
DataChecker
.
class
,
DefaultDataChecker
.
class
));
all
.
add
(
C
(
RemoteMetricReportService
.
class
).
req
(
ServerConfigManager
.
class
));
all
.
add
(
C
(
BusinessAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
BusinessAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
BusinessRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
NetworkAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
NetworkAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
NetworkRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
SystemAlert
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
BaselineService
.
class
,
MailSMS
.
class
,
SystemAlertConfig
.
class
,
AlertInfo
.
class
,
AlertDao
.
class
)
//
.
req
(
RemoteMetricReportService
.
class
,
SystemRuleConfigManager
.
class
,
DataChecker
.
class
));
all
.
add
(
C
(
AlertExceptionBuilder
.
class
).
req
(
ExceptionConfigManager
.
class
));
all
.
add
(
C
(
ExceptionAlert
.
class
).
req
(
ProjectDao
.
class
,
ExceptionAlertConfig
.
class
,
MailSMS
.
class
,
ExceptionConfigManager
.
class
,
AlertExceptionBuilder
.
class
,
AlertDao
.
class
).
req
(
ModelService
.
class
,
TopAnalyzer
.
ID
));
return
all
;
}
private
List
<
Component
>
defineCommonComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
JsonBuilder
.
class
));
...
...
@@ -107,68 +143,111 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
StateGraphs
.
class
,
StateGraphs
.
class
).
//
req
(
ReportService
.
class
));
all
.
add
(
C
(
Module
.
class
,
CatHomeModule
.
ID
,
CatHomeModule
.
class
));
all
.
add
(
C
(
ModuleManager
.
class
,
DefaultModuleManager
.
class
)
//
.
config
(
E
(
"topLevelModules"
).
value
(
CatHomeModule
.
ID
)));
all
.
add
(
C
(
DomainNavManager
.
class
).
req
(
ProjectDao
.
class
));
all
.
add
(
C
(
EventCollectManager
.
class
).
req
(
EventDao
.
class
,
ServerConfigManager
.
class
));
all
.
add
(
C
(
TopologyGraph
ConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
TopologyGraph
ItemBuilder
.
class
).
req
(
TopologyGraphConfigManager
.
class
));
all
.
add
(
C
(
ExceptionConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
TopologyGraphBuilder
.
class
).
req
(
TopologyGraphItemBuilder
.
class
).
is
(
PER_LOOKUP
));
all
.
add
(
C
(
DomainGroupConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
TopologyGraphManager
.
class
).
req
(
TopologyGraphBuilder
.
class
,
ServerConfigManager
.
class
)
//
.
req
(
ProductLineConfigManager
.
class
,
TopologyGraphDao
.
class
,
DomainNavManager
.
class
)
//
.
req
(
ModelService
.
class
,
DependencyAnalyzer
.
ID
));
all
.
add
(
C
(
BugConfigManager
.
class
).
req
(
ConfigDao
.
class
));
// update project database
all
.
add
(
C
(
ProjectUpdateTask
.
class
)
//
.
req
(
ProjectDao
.
class
,
HostinfoDao
.
class
));
all
.
add
(
C
(
MetricGroupConfigManager
.
class
).
req
(
ConfigDao
.
class
));
return
all
;
}
all
.
add
(
C
(
NetworkRuleConfigManager
.
class
).
req
(
ConfigDao
.
class
));
@Override
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
BusinessRuleConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
All
(
defineCommonComponents
(
));
all
.
add
(
C
(
AlertConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
All
(
defineConfigComponents
(
));
all
.
add
(
C
(
TopologyGraphItemBuilder
.
class
).
req
(
TopologyGraphConfigManager
.
class
));
all
.
add
All
(
defineMetricComponents
(
));
all
.
add
(
C
(
TopologyGraphBuilder
.
class
).
req
(
TopologyGraphItemBuilder
.
class
).
is
(
PER_LOOKUP
));
all
.
add
All
(
defineAlertComponents
(
));
all
.
add
(
C
(
TopologyGraphManager
.
class
).
req
(
TopologyGraphBuilder
.
class
,
ServerConfigManager
.
class
)
//
.
req
(
ProductLineConfigManager
.
class
,
TopologyGraphDao
.
class
,
DomainNavManager
.
class
)
//
.
req
(
ModelService
.
class
,
DependencyAnalyzer
.
ID
));
all
.
add
(
C
(
Module
.
class
,
CatHomeModule
.
ID
,
CatHomeModule
.
class
));
all
.
add
(
C
(
ModuleManager
.
class
,
DefaultModuleManager
.
class
)
//
.
config
(
E
(
"topLevelModules"
).
value
(
CatHomeModule
.
ID
)
));
// report serivce
all
.
addAll
(
new
ReportServiceComponentConfigurator
().
defineComponents
());
// task
all
.
addAll
(
new
TaskComponentConfigurator
().
defineComponents
());
// model service
all
.
addAll
(
new
ServiceComponentConfigurator
().
defineComponents
());
all
.
add
(
C
(
TableProvider
.
class
,
"app-data-command"
,
AppDataCommandTableProvider
.
class
));
// database
all
.
add
(
C
(
JdbcDataSourceDescriptorManager
.
class
)
//
.
config
(
E
(
"datasourceFile"
).
value
(
"/data/appdatas/cat/datasources.xml"
)));
all
.
addAll
(
new
CatDatabaseConfigurator
().
defineComponents
());
all
.
addAll
(
new
AppDatabaseConfigurator
().
defineComponents
());
all
.
addAll
(
new
UserDatabaseConfigurator
().
defineComponents
());
// web, please keep it last
all
.
addAll
(
new
WebComponentConfigurator
().
defineComponents
());
// for alarm module
all
.
addAll
(
new
AlarmComponentConfigurator
().
defineComponents
());
return
all
;
}
private
List
<
Component
>
defineConfigComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
TopologyGraphConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
ExceptionConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
DomainGroupConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
BugConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
MetricGroupConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
NetworkRuleConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
BusinessRuleConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
AlertConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
NetGraphConfigManager
.
class
).
req
(
ConfigDao
.
class
));
all
.
add
(
C
(
ConfigReloadTask
.
class
).
req
(
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
));
return
all
;
}
private
List
<
Component
>
defineMetricComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
C
(
IpService
.
class
));
all
.
add
(
C
(
CdnGraphCreator
.
class
).
req
(
BaselineService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
,
CachedMetricReportService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
CachedMetricReportService
.
class
,
CachedMetricReportServiceImpl
.
class
)
.
req
(
ModelService
.
class
,
MetricAnalyzer
.
ID
).
req
(
ReportService
.
class
).
req
(
IpService
.
class
));
all
.
add
(
C
(
DataExtractor
.
class
,
DataExtractorImpl
.
class
));
all
.
add
(
C
(
MetricDataFetcher
.
class
,
MetricDataFetcherImpl
.
class
));
all
.
add
(
C
(
AlertInfo
.
class
).
req
(
MetricConfigManager
.
class
));
all
.
add
(
C
(
CdnGraphCreator
.
class
).
req
(
BaselineService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
,
CachedMetricReportService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
MetricGraphCreator
.
class
).
req
(
CachedMetricReportService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
).
req
(
BaselineService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
,
ProjectDao
.
class
));
all
.
add
(
C
(
SystemGraphCreator
.
class
).
req
(
CachedMetricReportService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
).
req
(
BaselineService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
UserMonitorGraphCreator
.
class
,
DefaultUserMonitGraphCreator
.
class
).
req
(
CachedMetricReportService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
).
req
(
BaselineService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
NetworkGraphCreator
.
class
).
req
(
CachedMetricReportService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
).
req
(
BaselineService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
all
.
add
(
C
(
AppGraphCreator
.
class
).
req
(
AppDataService
.
class
,
CachedMetricReportService
.
class
,
DataExtractor
.
class
,
MetricDataFetcher
.
class
).
req
(
BaselineService
.
class
,
MetricConfigManager
.
class
,
ProductLineConfigManager
.
class
,
MetricGroupConfigManager
.
class
,
AlertInfo
.
class
));
// report serivce
all
.
addAll
(
new
ReportServiceComponentConfigurator
().
defineComponents
());
// task
...
...
cat-home/src/main/java/com/dianping/cat/build/UserDatabaseConfigurator.java
浏览文件 @
d6b9f6f3
...
...
@@ -11,6 +11,8 @@ final class UserDatabaseConfigurator extends AbstractJdbcResourceConfigurator {
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
// all.add(defineJdbcDataSourceComponent("user", "com.mysql.jdbc.Driver", "jdbc:mysql://192.168.8.44:3306/hawk", "hawk", "***", "<![CDATA[useUnicode=true&autoReconnect=true]]>"));
defineSimpleTableProviderComponents
(
all
,
"user"
,
com
.
dianping
.
cat
.
home
.
dal
.
user
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
home
.
dal
.
user
.
_INDEX
.
getDaoClasses
());
...
...
cat-home/src/main/java/com/dianping/cat/report/chart/AbstractGraphCreator.java
浏览文件 @
d6b9f6f3
...
...
@@ -230,7 +230,7 @@ public abstract class AbstractGraphCreator implements LogEnabled {
}
}
p
rotected
Map
<
Long
,
Double
>
buildNoneData
(
Date
startDate
,
Date
endDate
,
int
step
)
{
p
ublic
Map
<
Long
,
Double
>
buildNoneData
(
Date
startDate
,
Date
endDate
,
int
step
)
{
int
n
=
0
;
long
current
=
System
.
currentTimeMillis
();
...
...
cat-home/src/main/java/com/dianping/cat/report/page/app/Handler.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.report.page.app
;
import
java.io.IOException
;
import
javax.servlet.ServletException
;
import
com.dianping.cat.report.ReportPage
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.web.mvc.PageHandler
;
import
org.unidal.web.mvc.annotation.InboundActionMeta
;
import
org.unidal.web.mvc.annotation.OutboundActionMeta
;
import
org.unidal.web.mvc.annotation.PayloadMeta
;
import
com.dianping.cat.config.app.AppConfigManager
;
import
com.dianping.cat.config.app.QueryEntity
;
import
com.dianping.cat.report.ReportPage
;
import
com.dianping.cat.report.page.LineChart
;
import
com.dianping.cat.report.page.app.graph.AppGraphCreator
;
public
class
Handler
implements
PageHandler
<
Context
>
{
@Inject
private
JspViewer
m_jspViewer
;
@Inject
private
AppConfigManager
m_manager
;
@Inject
private
AppGraphCreator
m_appGraphCreator
;
@Override
@PayloadMeta
(
Payload
.
class
)
@InboundActionMeta
(
name
=
"app"
)
...
...
@@ -29,9 +38,24 @@ public class Handler implements PageHandler<Context> {
model
.
setAction
(
Action
.
VIEW
);
model
.
setPage
(
ReportPage
.
APP
);
model
.
setConnectionTypes
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
CONNECT_TYPE
));
model
.
setCities
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
CITY
));
model
.
setNetworks
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
NETWORK
));
model
.
setOperators
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
OPERATOR
));
model
.
setPlatforms
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
PLATFORM
));
model
.
setVersions
(
m_manager
.
queryConfigItem
(
AppConfigManager
.
VERSION
));
model
.
setCommands
(
m_manager
.
queryCommands
());
Payload
payload
=
ctx
.
getPayload
();
QueryEntity
entity1
=
payload
.
getQueryEntity1
();
QueryEntity
entity2
=
payload
.
getQueryEntity2
();
String
type
=
payload
.
getType
();
LineChart
lineChart
=
m_appGraphCreator
.
buildLineChart
(
entity1
,
entity2
,
type
);
model
.
setLineChart
(
lineChart
);
if
(!
ctx
.
isProcessStopped
())
{
m_jspViewer
.
view
(
ctx
,
model
);
m_jspViewer
.
view
(
ctx
,
model
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/app/Model.java
浏览文件 @
d6b9f6f3
...
...
@@ -2,14 +2,73 @@ package com.dianping.cat.report.page.app;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.unidal.web.mvc.view.annotation.EntityMeta
;
import
com.dianping.cat.configuration.app.entity.Code
;
import
com.dianping.cat.configuration.app.entity.Command
;
import
com.dianping.cat.configuration.app.entity.Item
;
import
com.dianping.cat.report.page.AbstractReportModel
;
import
com.dianping.cat.report.page.JsonBuilder
;
import
com.dianping.cat.report.page.LineChart
;
public
class
Model
extends
AbstractReportModel
<
Action
,
Context
>
{
@EntityMeta
private
LineChart
m_lineChart
;
private
List
<
Item
>
m_cities
;
private
List
<
Item
>
m_versions
;
private
List
<
Item
>
m_connectionTypes
;
private
List
<
Item
>
m_operators
;
private
List
<
Item
>
m_networks
;
private
List
<
Item
>
m_platforms
;
private
List
<
Command
>
m_commands
;
public
String
getCommand
()
{
Map
<
Integer
,
List
<
Code
>>
maps
=
new
LinkedHashMap
<
Integer
,
List
<
Code
>>();
for
(
Command
item
:
m_commands
)
{
List
<
Code
>
items
=
maps
.
get
(
item
.
getId
());
if
(
items
==
null
)
{
items
=
new
ArrayList
<
Code
>();
maps
.
put
(
item
.
getId
(),
items
);
}
items
.
addAll
(
item
.
getCodes
().
values
());
}
return
new
JsonBuilder
().
toJson
(
maps
);
}
public
List
<
Item
>
getPlatforms
()
{
return
m_platforms
;
}
public
void
setPlatforms
(
List
<
Item
>
platforms
)
{
m_platforms
=
platforms
;
}
public
Model
(
Context
ctx
)
{
super
(
ctx
);
}
public
List
<
Item
>
getCities
()
{
return
m_cities
;
}
public
List
<
Command
>
getCommands
()
{
return
m_commands
;
}
@Override
public
Action
getDefaultAction
()
{
return
Action
.
VIEW
;
...
...
@@ -24,4 +83,52 @@ public class Model extends AbstractReportModel<Action, Context> {
public
Collection
<
String
>
getDomains
()
{
return
new
ArrayList
<
String
>();
}
public
List
<
Item
>
getNetworks
()
{
return
m_networks
;
}
public
List
<
Item
>
getOperators
()
{
return
m_operators
;
}
public
List
<
Item
>
getVersions
()
{
return
m_versions
;
}
public
List
<
Item
>
getConnectionTypes
()
{
return
m_connectionTypes
;
}
public
void
setConnectionTypes
(
List
<
Item
>
connectionTypes
)
{
m_connectionTypes
=
connectionTypes
;
}
public
void
setCities
(
List
<
Item
>
cities
)
{
m_cities
=
cities
;
}
public
void
setCommands
(
List
<
Command
>
commands
)
{
m_commands
=
commands
;
}
public
void
setNetworks
(
List
<
Item
>
networks
)
{
m_networks
=
networks
;
}
public
void
setOperators
(
List
<
Item
>
operators
)
{
m_operators
=
operators
;
}
public
void
setVersions
(
List
<
Item
>
versions
)
{
m_versions
=
versions
;
}
public
LineChart
getLineChart
()
{
return
m_lineChart
;
}
public
void
setLineChart
(
LineChart
lineChart
)
{
m_lineChart
=
lineChart
;
}
}
cat-home/src/main/java/com/dianping/cat/report/page/app/Payload.java
浏览文件 @
d6b9f6f3
package
com.dianping.cat.report.page.app
;
import
com.dianping.cat.config.app.QueryEntity
;
import
com.dianping.cat.report.ReportPage
;
import
com.dianping.cat.report.page.AbstractReportPayload
;
...
...
@@ -7,60 +8,87 @@ import org.unidal.web.mvc.ActionContext;
import
org.unidal.web.mvc.payload.annotation.FieldMeta
;
public
class
Payload
extends
AbstractReportPayload
<
Action
>
{
private
ReportPage
m_page
;
private
ReportPage
m_page
;
@FieldMeta
(
"op"
)
private
Action
m_action
;
private
Action
m_action
;
@FieldMeta
(
"query1"
)
private
String
m_query1
;
private
String
m_query1
;
@FieldMeta
(
"query2"
)
private
String
m_query2
;
public
Payload
()
{
super
(
ReportPage
.
APP
);
}
@Override
public
Action
getAction
()
{
return
m_action
;
}
@Override
public
ReportPage
getPage
()
{
return
m_page
;
}
public
void
setAction
(
String
action
)
{
m_action
=
Action
.
getByName
(
action
,
Action
.
VIEW
);
}
@Override
public
void
setPage
(
String
page
)
{
m_page
=
ReportPage
.
getByName
(
page
,
ReportPage
.
APP
);
}
public
String
getQuery1
()
{
return
m_query1
;
}
private
String
m_query2
;
@FieldMeta
(
"type"
)
private
String
m_type
=
"request"
;
public
Payload
()
{
super
(
ReportPage
.
APP
);
}
public
QueryEntity
getQueryEntity1
()
{
if
(
m_query1
!=
null
&&
m_query1
.
length
()
>
0
)
{
return
new
QueryEntity
(
m_query1
);
}
else
{
return
null
;
}
}
public
QueryEntity
getQueryEntity2
()
{
if
(
m_query2
!=
null
&&
m_query2
.
length
()
>
0
)
{
return
new
QueryEntity
(
m_query2
);
}
else
{
return
null
;
}
}
@Override
public
Action
getAction
()
{
return
m_action
;
}
@Override
public
ReportPage
getPage
()
{
return
m_page
;
}
public
void
setAction
(
String
action
)
{
m_action
=
Action
.
getByName
(
action
,
Action
.
VIEW
);
}
@Override
public
void
setPage
(
String
page
)
{
m_page
=
ReportPage
.
getByName
(
page
,
ReportPage
.
APP
);
}
public
String
getQuery1
()
{
return
m_query1
;
}
public
void
setQuery1
(
String
query1
)
{
m_query1
=
query1
;
}
m_query1
=
query1
;
}
public
String
getQuery2
()
{
return
m_query2
;
}
return
m_query2
;
}
public
void
setQuery2
(
String
query2
)
{
m_query2
=
query2
;
}
m_query2
=
query2
;
}
public
void
setType
(
String
type
)
{
m_type
=
type
;
}
public
String
getType
()
{
return
m_type
;
}
@Override
public
void
validate
(
ActionContext
<?>
ctx
)
{
if
(
m_action
==
null
)
{
m_action
=
Action
.
VIEW
;
}
}
public
void
validate
(
ActionContext
<?>
ctx
)
{
if
(
m_action
==
null
)
{
m_action
=
Action
.
VIEW
;
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/app/graph/AppGraphCreator.java
0 → 100644
浏览文件 @
d6b9f6f3
package
com.dianping.cat.report.page.app.graph
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.Map
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.config.app.AppDataService
;
import
com.dianping.cat.config.app.QueryEntity
;
import
com.dianping.cat.helper.TimeUtil
;
import
com.dianping.cat.report.chart.AbstractGraphCreator
;
import
com.dianping.cat.report.page.LineChart
;
public
class
AppGraphCreator
extends
AbstractGraphCreator
{
@Inject
private
AppDataService
m_appDataService
;
public
LineChart
buildLineChart
(
QueryEntity
queryEntity1
,
QueryEntity
queryEntity2
,
String
type
)
{
LinkedList
<
double
[]>
dataList
=
new
LinkedList
<
double
[]>();
if
(
queryEntity1
!=
null
)
{
double
[]
data1
=
prepareQueryData
(
queryEntity1
,
type
);
dataList
.
add
(
data1
);
}
if
(
queryEntity2
!=
null
)
{
double
[]
values2
=
prepareQueryData
(
queryEntity2
,
type
);
dataList
.
add
(
values2
);
}
return
buildChartData
(
dataList
,
type
);
}
private
double
[]
prepareQueryData
(
QueryEntity
queryEntity
,
String
type
)
{
double
[]
value
=
m_appDataService
.
queryValue
(
queryEntity
,
type
);
return
value
;
}
private
String
queryType
(
String
type
)
{
if
(
AppDataService
.
SUCCESS
.
equals
(
type
))
{
return
"成功率"
;
}
else
if
(
AppDataService
.
REQUEST
.
equals
(
type
))
{
return
"请求数"
;
}
else
if
(
AppDataService
.
DELAY
.
equals
(
type
))
{
return
"成功延时(ms)"
;
}
else
{
return
""
;
}
}
public
LineChart
buildChartData
(
final
LinkedList
<
double
[]>
dataList
,
String
type
)
{
LineChart
lineChart
=
new
LineChart
();
lineChart
.
setId
(
"app"
);
lineChart
.
setHtmlTitle
(
queryType
(
type
));
int
i
=
1
;
for
(
double
[]
data
:
dataList
)
{
lineChart
.
add
(
"查询"
+
i
++,
data
);
}
return
lineChart
;
}
@Override
protected
Map
<
Long
,
Double
>
convertToMap
(
double
[]
data
,
Date
start
,
int
step
)
{
Map
<
Long
,
Double
>
map
=
new
LinkedHashMap
<
Long
,
Double
>();
int
length
=
data
.
length
;
long
startTime
=
start
.
getTime
();
long
time
=
startTime
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
time
+=
step
*
TimeUtil
.
ONE_MINUTE
;
map
.
put
(
time
,
data
[
i
]);
}
return
map
;
}
}
cat-home/src/main/java/com/dianping/cat/report/page/system/graph/SystemGraphCreator.java
浏览文件 @
d6b9f6f3
...
...
@@ -31,11 +31,11 @@ public class SystemGraphCreator extends AbstractGraphCreator {
"/-usage:avg"
,
"/-freeInodes:avg"
,
"/-read:sum"
,
"/-write:sum"
,
"/data-usage:avg"
,
"/data-freeInodes:avg"
,
"/data-read:sum"
,
"/data-write:sum"
,
"/usr-usage:avg"
,
"/usr-freeInodes:avg"
,
"/usr-read:sum"
,
"/usr-write:sum"
,
"/var-usage:avg"
,
"/var-freeInodes:avg"
,
"/var-read:sum"
,
"/var-write:sum"
,
"eth0-inFlow:sum"
,
"eth0-outFlow:sum"
,
"eth0-dropped:sum"
,
"eth0-errors:sum"
,
"
lo-inFlow
:sum"
,
"lo-
outFlow:sum"
,
"lo-dropped:sum"
,
"lo-errors:sum"
,
"swapUsage:avg"
,
"loadAvg1:avg"
,
"loadAvg5
:avg"
,
"
totalMem:avg"
,
"usedMem:avg"
,
"freeMem:avg"
,
"sharedMem:avg"
,
"buffersMem:avg"
,
"cachedMem
:avg"
,
"
totalProcess:avg"
,
"runningProcess:avg"
,
"swapUsage:avg"
,
"establishedTcp:avg"
,
"loginUsers
:avg"
,
"
uptime:avg"
,
"md5Change:avg"
,
"
hostNameChange:avg"
,
"hostIpChange:avg"
));
"eth0-inFlow:sum"
,
"eth0-outFlow:sum"
,
"eth0-dropped:sum"
,
"eth0-errors:sum"
,
"
eth0-collisions
:sum"
,
"lo-
inFlow:sum"
,
"lo-outFlow:sum"
,
"swapUsage:avg"
,
"loadAvg1:avg"
,
"loadAvg5:avg"
,
"totalMem
:avg"
,
"
usedMem:avg"
,
"freeMem:avg"
,
"sharedMem:avg"
,
"buffersMem:avg"
,
"cachedMem:avg"
,
"totalProcess
:avg"
,
"
runningProcess:avg"
,
"swapUsage:avg"
,
"establishedTcp:avg"
,
"loginUsers:avg"
,
"uptime:avg"
,
"md5Change
:avg"
,
"hostNameChange:avg"
,
"hostIpChange:avg"
));
private
static
final
List
<
String
>
JVM_KEY_LIST
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
"edenUsage:avg"
,
"oldUsage:avg"
,
"permUsage:avg"
,
"catalinaLogSize:sum"
));
...
...
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/CityManager.java
浏览文件 @
d6b9f6f3
...
...
@@ -16,7 +16,7 @@ import com.dianping.cat.report.page.JsonBuilder;
public
class
CityManager
implements
Initializable
{
public
Map
<
String
,
List
<
City
>>
maps
=
new
LinkedHashMap
<
String
,
List
<
City
>>();
public
String
getCityInfo
()
{
return
new
JsonBuilder
().
toJson
(
maps
);
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
浏览文件 @
d6b9f6f3
...
...
@@ -41,7 +41,7 @@ public class AlertExceptionBuilder {
double
totalWarnLimit
=
totalLimitPair
.
getKey
();
double
totalErrorLimit
=
totalLimitPair
.
getValue
();
double
totalException
=
0
;
for
(
Entry
<
String
,
Double
>
entry
:
item
.
getException
().
entrySet
())
{
String
exceptionName
=
entry
.
getKey
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
浏览文件 @
d6b9f6f3
...
...
@@ -235,6 +235,11 @@ public class ExceptionAlert implements Task, LogEnabled {
String
smsContent
=
m_alertBuilder
.
buildContent
(
errorAndTriggeredExceptions
.
toString
(),
domain
,
contactInfo
);
m_smsSender
.
sendAlert
(
phones
,
domain
,
smsContent
,
smsContent
,
"error"
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[短信告警] "
+
smsContent
);
m_mailSms
.
sendWeiXin
(
mailTitle
,
mailContent
,
domain
,
weixins
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
Cat
.
logEvent
(
"WeiXinAlert"
,
domain
,
Event
.
SUCCESS
,
"[微信告警] "
+
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
}
}
...
...
cat-home/src/main/java/com/dianping/cat/report/view/NavigationBar.java
浏览文件 @
d6b9f6f3
...
...
@@ -26,7 +26,9 @@ public class NavigationBar {
ReportPage
.
METRIC
,
ReportPage
.
USERMONITOR
,
ReportPage
.
APP
,
ReportPage
.
TRANSACTION
,
ReportPage
.
EVENT
,
...
...
cat-home/src/main/java/com/dianping/cat/system/tool/DefaultMailImpl.java
浏览文件 @
d6b9f6f3
...
...
@@ -48,7 +48,7 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
private
Logger
m_logger
;
private
static
final
String
WEIXIN_URL
=
"http://dpoa
-monitorapp-web01.beta
/app/monitor/cat/push"
;
private
static
final
String
WEIXIN_URL
=
"http://dpoa
.api.dianping.com
/app/monitor/cat/push"
;
private
static
final
String
SUCCESS_TEXT
=
"{\"success\":\"1\"}"
;
...
...
cat-home/src/main/resources/META-INF/dal/jdbc/report-codegen.xml
浏览文件 @
d6b9f6f3
...
...
@@ -49,7 +49,6 @@
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
<index
name=
"alert_summary_index"
members=
"alert_time ASC, domain ASC"
/>
<readsets>
<readset
name=
"FULL"
all=
"true"
/>
</readsets>
...
...
@@ -129,7 +128,7 @@
<entity
name=
"baseline"
table=
"baseline"
alias=
"b"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"report-name"
field=
"report_name"
value-type=
"String"
length=
"100"
/>
<member
name=
"index-key"
field=
"index_key"
value-type=
"String"
length=
"256"
nullable=
"false"
/>
<member
name=
"index-key"
field=
"index_key"
value-type=
"String"
length=
"256"
nullable=
"false"
/>
<member
name=
"report-period"
field=
"report_period"
value-type=
"Date"
/>
<member
name=
"data"
field=
"data"
value-type=
"byte[]"
length=
"65535"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
/>
...
...
@@ -279,58 +278,6 @@
</query>
</query-defs>
</entity>
<entity
name=
"sqlreport"
table=
"sqlreport"
alias=
"s"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"domain"
field=
"domain"
value-type=
"String"
length=
"50"
nullable=
"false"
/>
<member
name=
"name"
field=
"name"
value-type=
"String"
length=
"100"
nullable=
"false"
/>
<member
name=
"statement"
field=
"statement"
value-type=
"String"
length=
"3000"
nullable=
"false"
/>
<member
name=
"total-count"
field=
"total_count"
value-type=
"int"
length=
"10"
nullable=
"false"
/>
<member
name=
"failure-count"
field=
"failure_count"
value-type=
"int"
length=
"10"
nullable=
"false"
/>
<member
name=
"long-sqls"
field=
"long_sqls"
value-type=
"int"
length=
"10"
nullable=
"false"
/>
<member
name=
"min-value"
field=
"min_value"
value-type=
"double"
length=
"22"
nullable=
"false"
/>
<member
name=
"max-value"
field=
"max_value"
value-type=
"double"
length=
"22"
nullable=
"false"
/>
<member
name=
"avg2-value"
field=
"avg2_value"
value-type=
"double"
length=
"22"
nullable=
"false"
/>
<member
name=
"sum-value"
field=
"sum_value"
value-type=
"double"
length=
"22"
nullable=
"false"
/>
<member
name=
"sum2-value"
field=
"sum2_value"
value-type=
"double"
length=
"22"
nullable=
"false"
/>
<member
name=
"sample-link"
field=
"sample_link"
value-type=
"String"
length=
"64"
nullable=
"false"
/>
<member
name=
"transaction-date"
field=
"transaction_date"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"creation-date"
field=
"creation_date"
value-type=
"Date"
nullable=
"false"
/>
<member
name=
"duration-distribution"
field=
"duration_distribution"
value-type=
"String"
length=
"512"
nullable=
"false"
/>
<member
name=
"hits-over-time"
field=
"hits_over_time"
value-type=
"String"
length=
"512"
nullable=
"false"
/>
<member
name=
"duration-over-time"
field=
"duration_over_time"
value-type=
"String"
length=
"512"
nullable=
"false"
/>
<member
name=
"failure-over-time"
field=
"failure_over_time"
value-type=
"String"
length=
"512"
nullable=
"false"
/>
<var
name=
"key-id"
value-type=
"int"
key-member=
"id"
/>
<primary-key
name=
"PRIMARY"
members=
"id"
/>
<readsets>
<readset
name=
"FULL"
all=
"true"
/>
</readsets>
<updatesets>
<updateset
name=
"FULL"
all=
"true"
/>
</updatesets>
<query-defs>
<query
name=
"find-by-PK"
type=
"SELECT"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[SELECT <FIELDS/>
FROM
<TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"insert"
type=
"INSERT"
>
<statement>
<![CDATA[INSERT INTO <TABLE/>
(
<FIELDS/>
)
VALUES(
<VALUES/>
)]]>
</statement>
</query>
<query
name=
"update-by-PK"
type=
"UPDATE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[UPDATE <TABLE/>
SET
<FIELDS/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
<query
name=
"delete-by-PK"
type=
"DELETE"
>
<param
name=
"key-id"
/>
<statement>
<![CDATA[DELETE FROM <TABLE/>
WHERE
<FIELD
name=
'id'
/>
= ${key-id}]]>
</statement>
</query>
</query-defs>
</entity>
<entity
name=
"topology-graph"
table=
"topologyGraph"
alias=
"t"
>
<member
name=
"id"
field=
"id"
value-type=
"int"
length=
"10"
nullable=
"false"
key=
"true"
auto-increment=
"true"
/>
<member
name=
"ip"
field=
"ip"
value-type=
"String"
length=
"20"
/>
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
d6b9f6f3
此差异已折叠。
点击以展开。
cat-home/src/main/resources/config/default-alert-config.xml
已删除
100644 → 0
浏览文件 @
32fd8d42
<alert-config>
<receiver
id=
"network"
enable=
"false"
>
<email>
leon.li@dianping.com
</email>
<phone>
18662513308
</phone>
</receiver>
<receiver
id=
"exception"
enable=
"false"
>
<email>
jialin.sun@dianping.com
</email>
</receiver>
<receiver
id=
"business"
enable=
"false"
>
<email>
yong.you@dianping.com
</email>
<email>
argus@dianping.com
</email>
<email>
jialin.sun@dianping.com
</email>
<email>
monitor@dianping.com
</email>
<phone>
13916536843
</phone>
<phone>
18616671676
</phone>
<phone>
13858086694
</phone>
</receiver>
</alert-config>
cat-home/src/main/resources/config/default-app-config.xml
浏览文件 @
d6b9f6f3
<app-config>
<config-item
id=
"网络类型"
>
<item
id=
"1"
name=
"2G"
des=
"2G网络"
></item>
<item
id=
"2"
name=
"3G"
des=
"3G网络"
></item>
<item
id=
"3"
name=
"4G"
des=
"4G网络"
></item>
<item
id=
"1"
name=
"2G"
></item>
<item
id=
"2"
name=
"3G"
></item>
<item
id=
"3"
name=
"4G"
></item>
</config-item>
<config-item></config-item>
<config-item
id=
"运营商"
>
<item
id=
"1"
name=
"移动"
></item>
<item
id=
"2"
name=
"联通"
></item>
</config-item>
<config-item
id=
"版本"
>
<item
id=
"1"
name=
"1.0"
></item>
<item
id=
"2"
name=
"1.1"
></item>
</config-item>
<config-item
id=
"平台"
>
<item
id=
"1"
name=
"andriod"
></item>
<item
id=
"2"
name=
"ios"
></item>
</config-item>
<config-item
id=
"城市"
>
<item
id=
"1"
name=
"上海市"
></item>
<item
id=
"2"
name=
"安徽省"
></item>
<item
id=
"3"
name=
"北京市"
></item>
<item
id=
"4"
name=
"重庆市"
></item>
<item
id=
"5"
name=
"福建省"
></item>
<item
id=
"6"
name=
"甘肃省"
></item>
<item
id=
"7"
name=
"广东省"
></item>
<item
id=
"8"
name=
"广西壮族自治区"
></item>
<item
id=
"9"
name=
"贵州省"
></item>
<item
id=
"10"
name=
"海南省"
></item>
<item
id=
"11"
name=
"河北省"
></item>
<item
id=
"12"
name=
"河南省"
></item>
<item
id=
"13"
name=
"黑龙江省"
></item>
<item
id=
"14"
name=
"湖北省"
></item>
<item
id=
"15"
name=
"湖南省"
></item>
<item
id=
"16"
name=
"吉林省"
></item>
<item
id=
"17"
name=
"江苏省"
></item>
<item
id=
"18"
name=
"江西省"
></item>
<item
id=
"19"
name=
"辽宁省"
></item>
<item
id=
"20"
name=
"内蒙古自治区"
></item>
<item
id=
"21"
name=
"宁夏回族自治区"
></item>
<item
id=
"22"
name=
"青海省"
></item>
<item
id=
"23"
name=
"山东省"
></item>
<item
id=
"24"
name=
"山西省"
></item>
<item
id=
"25"
name=
"陕西省"
></item>
<item
id=
"26"
name=
"四川省"
></item>
<item
id=
"27"
name=
"天津市"
></item>
<item
id=
"28"
name=
"西藏自治区"
></item>
<item
id=
"29"
name=
"香港特别行政区"
></item>
<item
id=
"30"
name=
"新疆维吾尔自治区"
></item>
<item
id=
"31"
name=
"云南省"
></item>
<item
id=
"32"
name=
"浙江省"
></item>
</config-item>
<config-item
id=
"渠道"
>
<item
id=
"1"
name=
"360"
></item>
<item
id=
"2"
name=
"apple"
></item>
</config-item>
<config-item
id=
"连接类型"
>
<item
id=
"1"
name=
"长连接"
></item>
<item
id=
"2"
name=
"短连接"
></item>
</config-item>
<command
id=
"1"
name=
"http://www.dianping.com/"
>
<code
id=
"1"
name=
"成功返回"
status=
"0"
></code>
<code
id=
"2"
name=
"参数错误"
status=
"1"
></code>
<code
id=
"3"
name=
"非常字符"
status=
"1"
></code>
</command>
</app-config>
\ No newline at end of file
cat-home/src/main/webapp/WEB-INF/web.xml
浏览文件 @
d6b9f6f3
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version=
"2.5"
>
<filter>
<filter-name>
cat-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.CatFilter
</filter-class>
</filter>
<filter>
<filter-name>
domain-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.DomainFilter
</filter-class>
</filter>
<servlet>
<servlet-name>
cat-servlet
</servlet-name>
<servlet-class>
com.dianping.cat.servlet.CatServlet
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet>
<servlet-name>
mvc-servlet
</servlet-name>
<servlet-class>
org.unidal.web.MVC
</servlet-class>
<init-param>
<param-name>
cat-client-xml
</param-name>
<param-value>
client.xml
</param-value>
</init-param>
<init-param>
<param-name>
init-modules
</param-name>
<param-value>
false
</param-value>
</init-param>
<load-on-startup>
2
</load-on-startup>
</servlet>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
domain-filter
</filter-name>
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/s/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/jsp/*
</url-pattern>
<dispatcher>
FORWARD
</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>
mvc-servlet
</servlet-name>
<url-pattern>
/r/*
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
mvc-servlet
</servlet-name>
<url-pattern>
/s/*
</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>
/WEB-INF/app.tld
</taglib-uri>
<taglib-location>
/WEB-INF/app.tld
</taglib-location>
</taglib>
</jsp-config>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns=
"http://java.sun.com/xml/ns/javaee"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version=
"2.5"
>
<filter>
<filter-name>
cat-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.CatFilter
</filter-class>
</filter>
<filter>
<filter-name>
domain-filter
</filter-name>
<filter-class>
com.dianping.cat.servlet.DomainFilter
</filter-class>
</filter>
<servlet>
<servlet-name>
cat-servlet
</servlet-name>
<servlet-class>
com.dianping.cat.servlet.CatServlet
</servlet-class>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet>
<servlet-name>
mvc-servlet
</servlet-name>
<servlet-class>
org.unidal.web.MVC
</servlet-class>
<init-param>
<param-name>
cat-client-xml
</param-name>
<param-value>
client.xml
</param-value>
</init-param>
<init-param>
<param-name>
init-modules
</param-name>
<param-value>
false
</param-value>
</init-param>
<load-on-startup>
2
</load-on-startup>
</servlet>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
domain-filter
</filter-name>
<url-pattern>
/r/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/s/*
</url-pattern>
<dispatcher>
REQUEST
</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>
cat-filter
</filter-name>
<url-pattern>
/jsp/*
</url-pattern>
<dispatcher>
FORWARD
</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>
mvc-servlet
</servlet-name>
<url-pattern>
/r/*
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
mvc-servlet
</servlet-name>
<url-pattern>
/s/*
</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>
/WEB-INF/app.tld
</taglib-uri>
<taglib-location>
/WEB-INF/app.tld
</taglib-location>
</taglib>
</jsp-config>
</web-app>
cat-home/src/main/webapp/js/baseGraph.js
浏览文件 @
d6b9f6f3
...
...
@@ -105,7 +105,7 @@ function graphMetricChart(container, data) {
},
title
:
{
text
:
data
.
htmlTitle
,
useHTML
:
true
useHTML
:
true
},
xAxis
:
{
type
:
'
datetime
'
,
...
...
@@ -117,13 +117,97 @@ function graphMetricChart(container, data) {
week
:
'
%Y-%m-%d
'
,
month
:
'
%m-%d
'
,
year
:
'
%Y-%m
'
},
},
yAxis
:
{
min
:
ylabelMin
,
title
:
{
text
:
data
.
unit
,
}
},
credits
:
{
enabled
:
false
},
plotOptions
:
{
spline
:
{
lineWidth
:
2
,
states
:
{
hover
:
{
lineWidth
:
2
}
},
marker
:
{
enabled
:
false
}
}
},
legend
:
{
maxHeight
:
82
},
tooltip
:
{
allowPointSelect
:
false
,
formatter
:
function
()
{
var
number0
=
Number
(
this
.
y
).
toFixed
(
0
);
var
number1
=
Number
(
this
.
y
).
toFixed
(
1
);
var
number
=
number1
;
if
(
Number
(
number1
)
==
Number
(
number0
))
{
number
=
number0
;
}
return
Highcharts
.
dateFormat
(
'
%Y-%m-%d %H:%M
'
,
this
.
x
)
+
'
<br/>[
'
+
this
.
series
.
name
+
'
]
'
+
'
<b>
'
+
number
+
'
</b>
'
;
}
},
series
:
_data
});
}
function
parseMetricLineDataForApp
(
data
)
{
var
res
=
[];
data
.
subTitles
.
forEach
(
function
(
title
,
i
)
{
var
series
=
{}
series
.
name
=
title
;
series
.
data
=
data
.
values
[
i
];
res
.
push
(
series
);
});
return
res
;
}
function
graphMetricChartForApp
(
container
,
data
)
{
Highcharts
.
setOptions
({
global
:
{
useUTC
:
false
}
});
var
ylabelMin
=
data
.
minYlable
;
var
_data
=
parseMetricLineDataForApp
(
data
);
$
(
container
).
highcharts
(
{
chart
:
{
type
:
'
spline
'
},
title
:
{
text
:
data
.
htmlTitle
,
useHTML
:
true
},
xAxis
:
{
type
:
"
category
"
,
labels
:
{
step
:
12
,
maxStaggerLines
:
1
,
formatter
:
function
()
{
return
this
.
value
/
12
;
}
},
max
:
288
},
yAxis
:
{
min
:
ylabelMin
,
title
:
{
text
:
data
.
unit
,
}
title
:
{
text
:
data
.
unit
,
}
},
credits
:
{
enabled
:
false
...
...
@@ -147,22 +231,23 @@ function graphMetricChart(container, data) {
tooltip
:
{
allowPointSelect
:
false
,
formatter
:
function
()
{
var
number0
=
Number
(
this
.
y
).
toFixed
(
0
);
var
number0
=
Number
(
this
.
y
).
toFixed
(
0
);
var
number1
=
Number
(
this
.
y
).
toFixed
(
1
);
var
number
=
number1
;
if
(
Number
(
number1
)
==
Number
(
number0
))
{
if
(
Number
(
number1
)
==
Number
(
number0
))
{
number
=
number0
;
}
return
Highcharts
.
dateFormat
(
'
%Y-%m-%d %H:%M
'
,
this
.
x
)
+
'
<br/>[
'
+
this
.
series
.
name
+
'
]
'
+
'
<b>
'
+
number
+
'
</b>
'
;
return
Highcharts
.
dateFormat
(
'
%Y-%m-%d %H:%M
'
,
this
.
x
)
+
'
<br/>[
'
+
this
.
series
.
name
+
'
]
'
+
'
<b>
'
+
number
+
'
</b>
'
;
}
},
series
:
_data
});
}
function
graphLineChart
(
container
,
data
)
{
Highcharts
.
setOptions
({
global
:
{
...
...
@@ -177,7 +262,7 @@ function graphLineChart(container, data) {
},
title
:
{
text
:
data
.
title
,
useHTML
:
true
useHTML
:
true
},
xAxis
:
{
type
:
'
datetime
'
,
...
...
cat-home/src/main/webapp/jsp/report/app.jsp
浏览文件 @
d6b9f6f3
<%@ page
contentType=
"text/html; charset=utf-8"
%>
<%@ page
contentType=
"text/html; charset=utf-8"
%>
<%@ taglib
prefix=
"a"
uri=
"/WEB-INF/app.tld"
%>
<%@ taglib
prefix=
"w"
uri=
"http://www.unidal.org/web/core"
%>
<%@ taglib
prefix=
"c"
uri=
"http://java.sun.com/jsp/jstl/core"
%>
<%@ taglib
prefix=
"res"
uri=
"http://www.unidal.org/webres"
%>
<jsp:useBean
id=
"ctx"
type=
"com.dianping.cat.report.page.app.Context"
scope=
"request"
/>
<jsp:useBean
id=
"payload"
type=
"com.dianping.cat.report.page.app.Payload"
scope=
"request"
/>
<jsp:useBean
id=
"model"
type=
"com.dianping.cat.report.page.app.Model"
scope=
"request"
/>
<jsp:useBean
id=
"ctx"
type=
"com.dianping.cat.report.page.app.Context"
scope=
"request"
/>
<jsp:useBean
id=
"payload"
type=
"com.dianping.cat.report.page.app.Payload"
scope=
"request"
/>
<jsp:useBean
id=
"model"
type=
"com.dianping.cat.report.page.app.Model"
scope=
"request"
/>
<a:body>
<res:useCss
value=
"
${
res
.
css
.
local
[
'select2.css'
]
}
"
target=
"head-css"
/>
...
...
@@ -14,196 +14,305 @@
<res:useJs
value=
"
${
res
.
js
.
local
[
'bootstrap-datetimepicker.min.js'
]
}
"
target=
"head-js"
/>
<res:useJs
value=
"
${
res
.
js
.
local
[
'baseGraph.js'
]
}
"
target=
"head-js"
/>
<script
type=
"text/javascript"
>
function
check
(){
var
commandInfo
=
$
{
model
.
command
};
function
check
()
{
var
value
=
document
.
getElementById
(
"
checkbox
"
).
checked
;
if
(
value
==
true
)
{
if
(
value
==
true
)
{
$
(
'
#history
'
).
slideDown
();
}
else
{
command2Change
();
}
else
{
$
(
'
#history
'
).
slideUp
();
}
}
function
query
(){
var
time
=
$
(
"
#time1
"
).
val
();
var
command1Change
=
function
command1Change
()
{
var
key
=
$
(
"
#command
"
).
val
();
var
value
=
commandInfo
[
key
];
var
code
=
document
.
getElementById
(
"
code
"
);
for
(
var
prop
in
value
)
{
var
opt
=
$
(
'
<option />
'
);
opt
.
html
(
value
[
prop
].
name
);
opt
.
val
(
value
[
prop
].
id
);
opt
.
appendTo
(
code
);
}
}
var
command2Change
=
function
command2Change
()
{
var
key
=
$
(
"
#command2
"
).
val
();
var
value
=
commandInfo
[
key
];
var
code
=
document
.
getElementById
(
"
code2
"
);
for
(
var
prop
in
value
)
{
var
opt
=
$
(
'
<option />
'
);
opt
.
html
(
value
[
prop
].
name
);
opt
.
val
(
value
[
prop
].
id
);
opt
.
appendTo
(
code
);
}
}
function
getDate
()
{
var
myDate
=
new
Date
();
var
myMonth
=
new
Number
(
myDate
.
getMonth
());
var
month
=
myMonth
+
1
;
return
myDate
.
getFullYear
()
+
"
-
"
+
month
+
"
-
"
+
myDate
.
getDate
();
}
function
query
()
{
var
time
=
$
(
"
#time
"
).
val
();
var
command
=
$
(
"
#command
"
).
val
();
var
code
=
$
(
"
#code
"
).
val
();
var
network
=
$
(
"
#network
"
).
val
();
var
version
=
$
(
"
#version
"
).
val
();
var
channel
=
$
(
"
#channel
"
).
val
();
var
palteform
=
$
(
"
#plateform
"
).
val
();
var
city
=
$
(
"
#city
"
).
val
();
var
operator
=
$
(
"
#operator
"
).
val
();
var
split
=
"
;
"
;
var
query1
=
time
+
split
+
command
+
split
+
code
+
split
+
network
+
split
+
version
+
split
+
channel
+
split
+
palteform
+
split
+
city
+
split
+
operator
;
var
query2
=
""
;
var
code
=
$
(
"
#code
"
).
val
();
var
network
=
$
(
"
#network
"
).
val
();
var
version
=
$
(
"
#version
"
).
val
();
var
connectionType
=
$
(
"
#connectionType
"
).
val
();
var
palteform
=
$
(
"
#platform
"
).
val
();
var
city
=
$
(
"
#city
"
).
val
();
var
operator
=
$
(
"
#operator
"
).
val
();
var
split
=
"
;
"
;
var
query1
=
time
+
split
+
command
+
split
+
code
+
split
+
network
+
split
+
version
+
split
+
connectionType
+
split
+
palteform
+
split
+
city
+
split
+
operator
;
var
query2
=
""
;
var
value
=
document
.
getElementById
(
"
checkbox
"
).
checked
;
if
(
value
==
true
)
{
if
(
value
==
true
)
{
var
time2
=
$
(
"
#time2
"
).
val
();
var
command2
=
$
(
"
#command2
"
).
val
();
var
code2
=
$
(
"
#code2
"
).
val
();
var
network2
=
$
(
"
#network2
"
).
val
();
var
version2
=
$
(
"
#version2
"
).
val
();
var
channel2
=
$
(
"
#channel2
"
).
val
();
var
palteform2
=
$
(
"
#plateform2
"
).
val
();
var
city2
=
$
(
"
#city2
"
).
val
();
var
operator2
=
$
(
"
#operator2
"
).
val
();
query2
=
time2
+
split
+
command2
+
split
+
code2
+
split
+
network2
+
split
+
version2
+
split
+
channel2
+
split
+
palteform2
+
split
+
city2
+
split
+
operator2
;
var
code2
=
$
(
"
#code2
"
).
val
();
var
network2
=
$
(
"
#network2
"
).
val
();
var
version2
=
$
(
"
#version2
"
).
val
();
var
connectionType2
=
$
(
"
#connectionType2
"
).
val
();
var
palteform2
=
$
(
"
#platform2
"
).
val
();
var
city2
=
$
(
"
#city2
"
).
val
();
var
operator2
=
$
(
"
#operator2
"
).
val
();
query2
=
time2
+
split
+
command2
+
split
+
code2
+
split
+
network2
+
split
+
version2
+
split
+
connectionType2
+
split
+
palteform2
+
split
+
city2
+
split
+
operator2
;
}
var
href
=
"
?query1=
"
+
query1
+
"
&query2=
"
+
query2
;
window
.
location
.
href
=
href
;
}
$
(
document
).
ready
(
function
()
{
$
(
'
#datetimepicker1
'
).
datetimepicker
();
$
(
'
#datetimepicker2
'
).
datetimepicker
();
var
query1
=
'
${payload.query1}
'
;
var
query2
=
'
${payload.query2}
'
;
var
words
=
query1
.
split
(
"
;
"
);
$
(
"
#time
"
).
val
(
words
[
0
]);
$
(
"
#command
"
).
val
(
words
[
1
]);
$
(
"
#code
"
).
val
(
words
[
2
]);
$
(
"
#network
"
).
val
(
words
[
3
]);
$
(
"
#version
"
).
val
(
words
[
4
]);
$
(
"
#channel
"
).
val
(
words
[
5
]);
$
(
"
#plateform
"
).
val
(
words
[
6
]);
$
(
"
#city
"
).
val
(
words
[
7
]);
$
(
"
#operator
"
).
val
(
words
[
8
]);
if
(
query2
!=
null
&&
query2
!=
''
){
var
checkboxs
=
document
.
getElementsByName
(
"
typeCheckbox
"
);
var
type
=
""
;
$
(
'
#history
'
).
slideDown
();
document
.
getElementById
(
"
checkbox
"
).
checked
=
true
;
var
words
=
query2
.
split
(
"
;
"
);
$
(
"
#time2
"
).
val
(
words
[
0
]);
$
(
"
#command2
"
).
val
(
words
[
1
]);
$
(
"
#code2
"
).
val
(
words
[
2
]);
$
(
"
#network2
"
).
val
(
words
[
3
]);
$
(
"
#version2
"
).
val
(
words
[
4
]);
$
(
"
#channel2
"
).
val
(
words
[
5
]);
$
(
"
#plateform2
"
).
val
(
words
[
6
]);
$
(
"
#city2
"
).
val
(
words
[
7
]);
$
(
"
#operator2
"
).
val
(
words
[
8
]);
for
(
var
i
=
0
;
i
<
checkboxs
.
length
;
i
++
)
{
if
(
checkboxs
[
i
].
checked
)
{
type
=
checkboxs
[
i
].
value
;
break
;
}
}
});
var
href
=
"
?query1=
"
+
query1
+
"
&query2=
"
+
query2
+
"
&type=
"
+
type
;
window
.
location
.
href
=
href
;
}
$
(
document
).
ready
(
function
()
{
$
(
'
#datetimepicker1
'
).
datetimepicker
();
$
(
'
#datetimepicker2
'
).
datetimepicker
();
var
query1
=
'
${payload.query1}
'
;
var
query2
=
'
${payload.query2}
'
;
var
command1
=
$
(
'
#command
'
);
var
command2
=
$
(
'
#command2
'
);
var
words
=
query1
.
split
(
"
;
"
);
command1
.
on
(
'
change
'
,
command1Change
);
command2
.
on
(
'
change
'
,
command2Change
);
$
(
"
#command
"
).
val
(
words
[
1
]);
if
(
words
[
0
]
==
null
||
words
.
length
==
1
)
{
console
.
log
(
words
.
length
);
$
(
"
#time
"
).
val
(
getDate
());
}
else
{
$
(
"
#time
"
).
val
(
words
[
0
]);
}
command1Change
();
$
(
"
#code
"
).
val
(
words
[
2
]);
$
(
"
#network
"
).
val
(
words
[
3
]);
$
(
"
#version
"
).
val
(
words
[
4
]);
$
(
"
#connectionType
"
).
val
(
words
[
5
]);
$
(
"
#platform
"
).
val
(
words
[
6
]);
$
(
"
#city
"
).
val
(
words
[
7
]);
$
(
"
#operator
"
).
val
(
words
[
8
]);
if
(
query2
!=
null
&&
query2
!=
''
)
{
$
(
'
#history
'
).
slideDown
();
document
.
getElementById
(
"
checkbox
"
).
checked
=
true
;
var
words
=
query2
.
split
(
"
;
"
);
if
(
words
[
0
]
==
null
||
words
[
0
].
length
==
0
)
{
$
(
"
#time2
"
).
val
(
getDate
());
}
else
{
$
(
"
#time2
"
).
val
(
words
[
0
]);
}
$
(
"
#command2
"
).
val
(
words
[
1
]);
command2Change
();
$
(
"
#code2
"
).
val
(
words
[
2
]);
$
(
"
#network2
"
).
val
(
words
[
3
]);
$
(
"
#version2
"
).
val
(
words
[
4
]);
$
(
"
#connectionType2
"
).
val
(
words
[
5
]);
$
(
"
#platform2
"
).
val
(
words
[
6
]);
$
(
"
#city2
"
).
val
(
words
[
7
]);
$
(
"
#operator2
"
).
val
(
words
[
8
]);
}
else
{
$
(
"
#time2
"
).
val
(
getDate
());
}
var
checkboxs
=
document
.
getElementsByName
(
"
typeCheckbox
"
);
for
(
var
i
=
0
;
i
<
checkboxs
.
length
;
i
++
)
{
if
(
checkboxs
[
i
].
value
==
"
${payload.type}
"
)
{
checkboxs
[
i
].
checked
=
true
;
break
;
}
}
var
data
=
$
{
model
.
lineChart
.
jsonString
};
graphMetricChartForApp
(
document
.
getElementById
(
'
${model.lineChart.id}
'
),
data
);
});
</script>
<div
class=
"report"
>
<table>
<tr>
<th
align=
left
>
时间
<div
id=
"datetimepicker1"
class=
"input-append date"
style=
"margin-bottom: 0px;"
>
<input
id=
"time"
name=
"time1"
style=
"height: 30px; width: 150px;"
data-format=
"yyyy-MM-dd"
type=
"text"
></input>
<span
class=
"add-on"
>
<i
data-time-icon=
"icon-time"
data-date-icon=
"icon-calendar"
>
</i>
</span>
</div>
命令字
<select
id=
"command"
style=
"width: 250px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
返回码
<select
id=
"code"
style=
"width: 80px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
网络类型
<select
id=
"network"
style=
"width: 80px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
<th
align=
left
>
时间
<div
id=
"datetimepicker1"
class=
"input-append date"
style=
"margin-bottom: 0px;"
>
<input
id=
"time"
name=
"time"
style=
"height: 30px; width: 150px;"
data-format=
"yyyy-MM-dd"
type=
"text"
></input>
<span
class=
"add-on"
>
<i
data-time-icon=
"icon-time"
data-date-icon=
"icon-calendar"
>
</i>
</span>
</div>
命令字
<select
id=
"command"
style=
"width: 350px;"
>
<c:forEach
var=
"item"
items=
"
${
model
.
commands
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
返回码
<select
id=
"code"
style=
"width: 120px;"
><option
value=
'0'
>
All
</option>
</select>
网络类型
<select
id=
"network"
style=
"width: 80px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
networks
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
</th>
</tr>
<tr>
<th
align=
left
>
版本
<select
id=
"version"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
渠道
<select
id=
"channel"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
平台
<select
id=
"plateform"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
地区
<select
id=
"city"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
运营商
<select
id=
"operator"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
<input
class=
"btn btn-primary "
value=
" 查询 "
onclick=
"query()"
type=
"submit"
/>
<input
class=
"btn btn-primary"
id=
"checkbox"
onclick=
"check()"
type=
"checkbox"
/>
<label
for=
"checkbox"
style=
"display:-webkit-inline-box"
>
选择历史对比
</label>
<th
align=
left
>
版本
<select
id=
"version"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
versions
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
连接类型
<select
id=
"connectionType"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
connectionTypes
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
平台
<select
id=
"platform"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
platforms
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
地区
<select
id=
"city"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
cities
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
运营商
<select
id=
"operator"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
operators
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
<input
class=
"btn btn-primary "
value=
" 查询 "
onclick=
"query()"
type=
"submit"
/>
<input
class=
"btn btn-primary"
id=
"checkbox"
onclick=
"check()"
type=
"checkbox"
/>
<label
for=
"checkbox"
style=
"display: -webkit-inline-box"
>
选择历史对比
</label>
</th>
</tr>
</table>
<table
id=
"history"
style=
"display:none"
>
<table
id=
"history"
style=
"display:
none"
>
<tr>
<th
align=
left
>
时间
<div
id=
"datetimepicker2"
class=
"input-append date"
style=
"margin-bottom: 0px;"
>
<input
id=
"time2"
name=
"time2"
style=
"height: 30px; width: 150px;"
data-format=
"yyyy-MM-dd"
type=
"text"
></input>
<span
class=
"add-on"
>
<i
data-time-icon=
"icon-time"
data-date-icon=
"icon-calendar"
>
</i>
</span>
</div>
命令字
<select
id=
"command2"
style=
"width: 250px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
返回码
<select
id=
"code2"
style=
"width: 80px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
网络类型
<select
id=
"network2"
style=
"width: 80px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
<th
align=
left
>
时间
<div
id=
"datetimepicker2"
class=
"input-append date"
style=
"margin-bottom: 0px;"
>
<input
id=
"time2"
name=
"time2"
style=
"height: 30px; width: 150px;"
data-format=
"yyyy-MM-dd"
type=
"text"
></input>
<span
class=
"add-on"
>
<i
data-time-icon=
"icon-time"
data-date-icon=
"icon-calendar"
>
</i>
</span>
</div>
命令字
<select
id=
"command2"
style=
"width: 350px;"
>
<c:forEach
var=
"item"
items=
"
${
model
.
commands
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
返回码
<select
id=
"code2"
style=
"width: 120px;"
>
<option
value=
'0'
>
All
</option>
</select>
网络类型
<select
id=
"network2"
style=
"width: 80px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
networks
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
</th>
</tr>
<tr>
<th
align=
left
>
版本
<select
id=
"version2"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
渠道
<select
id=
"channel2"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
平台
<select
id=
"plateform2"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
地区
<select
id=
"city2"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
</select>
运营商
<select
id=
"operator2"
style=
"width: 100px;"
>
<option
value=
'1'
>
1
</option><option
value=
'2'
>
2
</option>
<th
align=
left
>
版本
<select
id=
"version2"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
versions
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
连接类型
<select
id=
"connectionType2"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
connectionTypes
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
平台
<select
id=
"platform2"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
platforms
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
地区
<select
id=
"city2"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
cities
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
运营商
<select
id=
"operator2"
style=
"width: 100px;"
>
<option
value=
'0'
>
All
</option>
<c:forEach
var=
"item"
items=
"
${
model
.
operators
}
"
varStatus=
"status"
>
<option
value=
'${item.id}'
>
${item.name}
</option>
</c:forEach>
</select>
</th>
</tr>
</table>
<div
class=
"btn-group"
data-toggle=
"buttons"
>
<label
class=
"btn btn-info"
><input
type=
"radio"
name=
"typeCheckbox"
value=
"request"
>
请求数
</label>
<label
class=
"btn btn-info"
>
<input
type=
"radio"
name=
"typeCheckbox"
value=
"success"
>
成功率
</label>
<label
class=
"btn btn-info"
>
<input
type=
"radio"
name=
"typeCheckbox"
value=
"delay"
>
成功延时(ms)
</label>
</div>
<div
style=
"float: left; width: 95%;"
>
<div
id=
"${model.lineChart.id}"
></div>
</div>
<table
class=
"footer"
>
<tr>
<td>
[ end ]
</td>
...
...
cat-home/src/main/webapp/jsp/report/cdn.jsp
浏览文件 @
d6b9f6f3
...
...
@@ -102,6 +102,12 @@
<div
class=
"report"
>
<table>
<tr>
<th
class=
"left"
>
<select
style=
"width: 120px;"
name=
"innerorouter"
id=
""
innerorouter
""
>
<option
value=
"inner"
>
内部cdn
</option>
<option
value=
"outer"
>
外部cdn
</option>
</select>
</th>
<th
class=
"left"
>
cdn服务商
<select
style=
"width: 120px;"
name=
"cdn"
id=
"cdn"
>
<option
value=
"ALL"
>
ALL
</option>
...
...
cat-home/src/test/java/com/dianping/cat/report/analyzer/TopologyGraphTest.java
浏览文件 @
d6b9f6f3
此差异已折叠。
点击以展开。
cat-maven-plugin/src/main/java/com/dianping/cat/plugin/InstallMojo.java
浏览文件 @
d6b9f6f3
...
...
@@ -217,7 +217,7 @@ public class InstallMojo extends AbstractMojo {
}
});
m_user
=
PropertyProviders
.
fromConsole
().
forString
(
"jdbc.user"
,
"Please input username:"
,
null
,
null
,
null
);
m_password
=
PropertyProviders
.
fromConsole
().
forString
(
"jdbc.password"
,
"Please input password:"
,
null
,
null
,
m_password
=
PropertyProviders
.
fromConsole
().
forString
(
"jdbc.password"
,
"Please input password:"
,
null
,
""
,
null
);
}
}
\ No newline at end of file
cat-maven-plugin/src/main/resources/com/dianping/cat/plugin/Cat.sql
浏览文件 @
d6b9f6f3
此差异已折叠。
点击以展开。
pom.xml
浏览文件 @
d6b9f6f3
...
...
@@ -17,6 +17,7 @@
<module>
cat-home
</module>
<module>
cat-broker
</module>
<module>
cat-agent
</module>
<module>
cat-maven-plugin
</module>
</modules>
<dependencyManagement>
<dependencies>
...
...
script/Cat.sql
浏览文件 @
d6b9f6f3
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录