Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
3742102c
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,发现更多精彩内容 >>
提交
3742102c
编写于
2月 07, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust ip model
上级
c08f10f4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
152 addition
and
59 deletion
+152
-59
cat-consumer/pom.xml
cat-consumer/pom.xml
+1
-1
cat-consumer/src/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
...rc/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
+61
-13
cat-consumer/src/main/resources/META-INF/dal/model/ip-codegen.xml
...umer/src/main/resources/META-INF/dal/model/ip-codegen.xml
+5
-5
cat-consumer/src/main/resources/META-INF/dal/model/ip-model.xml
...nsumer/src/main/resources/META-INF/dal/model/ip-model.xml
+5
-5
cat-consumer/src/test/resources/com/dianping/cat/consumer/ip/ip.xml
...er/src/test/resources/com/dianping/cat/consumer/ip/ip.xml
+6
-13
cat-home/src/main/java/com/dianping/cat/report/page/ip/Handler.java
...rc/main/java/com/dianping/cat/report/page/ip/Handler.java
+27
-10
cat-home/src/main/java/com/dianping/cat/report/page/ip/Model.java
.../src/main/java/com/dianping/cat/report/page/ip/Model.java
+10
-0
cat-home/src/main/webapp/WEB-INF/tags/report.tag
cat-home/src/main/webapp/WEB-INF/tags/report.tag
+2
-2
cat-home/src/main/webapp/css/report.css
cat-home/src/main/webapp/css/report.css
+22
-3
cat-home/src/main/webapp/jsp/report/ip.jsp
cat-home/src/main/webapp/jsp/report/ip.jsp
+13
-7
未找到文件。
cat-consumer/pom.xml
浏览文件 @
3742102c
...
...
@@ -34,7 +34,7 @@
<plugin>
<groupId>
com.site.maven.plugins
</groupId>
<artifactId>
maven-codegen-plugin
</artifactId>
<version>
1.0.
5
</version>
<version>
1.0.
6
</version>
<executions>
<execution>
<id>
generate failure report model
</id>
...
...
cat-consumer/src/main/java/com/dianping/cat/consumer/ip/IpAnalyzer.java
浏览文件 @
3742102c
package
com.dianping.cat.consumer.ip
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -15,9 +18,11 @@ import com.dianping.cat.message.spi.AbstractMessageAnalyzer;
import
com.dianping.cat.message.spi.MessageTree
;
public
class
IpAnalyzer
extends
AbstractMessageAnalyzer
<
IpReport
>
{
private
static
final
String
TOKEN
=
"RemoteIP="
;
private
Map
<
String
,
IpReport
>
m_reports
=
new
HashMap
<
String
,
IpReport
>();
private
static
final
String
TOKEN
=
"RemoteIP="
;
private
int
m_lastPhase
;
private
IpReport
findOrCreateReport
(
String
domain
)
{
IpReport
report
=
m_reports
.
get
(
domain
);
...
...
@@ -41,20 +46,31 @@ public class IpAnalyzer extends AbstractMessageAnalyzer<IpReport> {
return
null
;
}
public
IpReport
generate
(
String
domain
)
{
IpReport
report
=
null
;
public
List
<
String
>
getDomains
(
)
{
List
<
String
>
domains
=
new
ArrayList
<
String
>(
m_reports
.
keySet
())
;
if
(
domain
==
null
)
{
if
(!
m_reports
.
isEmpty
())
{
domain
=
m_reports
.
keySet
().
iterator
().
next
();
Collections
.
sort
(
domains
,
new
Comparator
<
String
>()
{
@Override
public
int
compare
(
String
d1
,
String
d2
)
{
if
(
d1
.
equals
(
"Cat"
))
{
return
1
;
}
return
d1
.
compareTo
(
d2
);
}
}
}
);
return
domains
;
}
public
IpReport
generate
(
String
domain
)
{
if
(
domain
!=
null
)
{
report
=
m_reports
.
get
(
domain
);
}
IpReport
report
=
m_reports
.
get
(
domain
);
return
report
;
return
report
;
}
else
{
return
null
;
}
}
private
String
getIpAddress
(
Transaction
root
)
{
...
...
@@ -103,10 +119,42 @@ public class IpAnalyzer extends AbstractMessageAnalyzer<IpReport> {
int
minute
=
cal
.
get
(
Calendar
.
MINUTE
);
IpReport
report
=
findOrCreateReport
(
domain
);
Ip
ip
=
report
.
findOrCreateIp
(
address
);
Period
period
=
ip
.
findOrCreatePeriod
(
minute
);
Period
period
=
report
.
findOrCreatePeriod
(
minute
);
Ip
ip
=
period
.
findOrCreateIp
(
address
);
ip
.
incCount
();
clearLastPhase
();
}
}
private
void
clearLastPhase
()
{
Calendar
cal
=
Calendar
.
getInstance
();
int
minute
=
cal
.
get
(
Calendar
.
MINUTE
);
int
currentPhase
=
minute
/
20
;
// 0, 1, 2
if
(
m_lastPhase
!=
currentPhase
)
{
int
baseIndex
=
m_lastPhase
*
20
;
List
<
String
>
domains
=
new
ArrayList
<
String
>();
for
(
Map
.
Entry
<
String
,
IpReport
>
e
:
m_reports
.
entrySet
())
{
IpReport
report
=
e
.
getValue
();
Map
<
Integer
,
Period
>
periods
=
report
.
getPeriods
();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
periods
.
remove
(
baseIndex
+
i
);
}
if
(
periods
.
isEmpty
())
{
domains
.
add
(
e
.
getKey
());
}
}
for
(
String
domain
:
domains
)
{
m_reports
.
remove
(
domain
);
}
period
.
incValue
()
;
m_lastPhase
=
currentPhase
;
}
}
...
...
cat-consumer/src/main/resources/META-INF/dal/model/ip-codegen.xml
浏览文件 @
3742102c
...
...
@@ -4,15 +4,15 @@
<attribute
name=
"domain"
value-type=
"String"
/>
<attribute
name=
"startTime"
value-type=
"Date"
format=
"yyyy-MM-dd HH:mm:ss"
/>
<attribute
name=
"endTime"
value-type=
"Date"
format=
"yyyy-MM-dd HH:mm:ss"
/>
<entity-ref
name=
"ip"
type=
"list"
names=
"ips"
/>
</entity>
<entity
name=
"ip"
>
<attribute
name=
"address"
value-type=
"String"
/>
<entity-ref
name=
"period"
type=
"list"
names=
"periods"
/>
</entity>
<entity
name=
"period"
>
<attribute
name=
"minute"
value-type=
"int"
/>
<attribute
name=
"value"
value-type=
"int"
/>
<entity-ref
name=
"ip"
type=
"list"
names=
"ips"
/>
</entity>
<entity
name=
"ip"
>
<attribute
name=
"address"
value-type=
"String"
/>
<attribute
name=
"count"
value-type=
"int"
/>
</entity>
</model>
cat-consumer/src/main/resources/META-INF/dal/model/ip-model.xml
浏览文件 @
3742102c
...
...
@@ -2,14 +2,14 @@
<model
model-package=
"com.dianping.cat.consumer.ip.model"
enable-merger=
"true"
enable-json-builder=
"true"
enable-xml-parser=
"true"
enable-base-visitor=
"true"
>
<entity
name=
"ip-report"
root=
"true"
>
<entity-ref
name=
"period"
type=
"map"
names=
"periods"
method-find-or-create=
"true"
/>
</entity>
<entity
name=
"period"
>
<attribute
name=
"minute"
value-type=
"int"
key=
"true"
/>
<entity-ref
name=
"ip"
type=
"map"
names=
"ips"
method-find-or-create=
"true"
/>
</entity>
<entity
name=
"ip"
>
<attribute
name=
"address"
value-type=
"String"
key=
"true"
/>
<entity-ref
name=
"period"
type=
"list"
names=
"periods"
method-find-or-create=
"true"
/>
</entity>
<entity
name=
"period"
>
<attribute
name=
"minute"
value-type=
"int"
key=
"true"
/>
<attribute
name=
"value"
value-type=
"int"
primitive=
"true"
method-inc=
"true"
/>
<attribute
name=
"count"
value-type=
"int"
primitive=
"true"
method-inc=
"true"
/>
</entity>
</model>
cat-consumer/src/test/resources/com/dianping/cat/consumer/ip/ip.xml
浏览文件 @
3742102c
<ip-report
domain=
"Review"
startTime=
"2012-01-25 13:00:00"
endTime=
"2012-01-25 13:59:00"
>
<ip
address=
"127.0.0.1"
>
<period
minute=
"0"
value=
"19"
/>
<period
minute=
"1"
value=
"2"
/>
<period
minute=
"2"
value=
"1"
/>
<period
minute=
"4"
value=
"12"
/>
<period
minute=
"5"
value=
"12"
/>
<period
minute=
"6"
value=
"15"
/>
<period
minute=
"7"
value=
"12"
/>
<period
minute=
"8"
value=
"14"
/>
<period
minute=
"9"
value=
"16"
/>
</ip>
<ip
address=
"192.168.63.30"
>
</ip>
<period
minute=
"0"
>
<ip
address=
"127.0.0.1"
count=
"19"
/>
<ip
address=
"192.168.63.30"
count=
"11"
/>
</period>
<period
minute=
"1"
>
</period>
</ip-report>
cat-home/src/main/java/com/dianping/cat/report/page/ip/Handler.java
浏览文件 @
3742102c
...
...
@@ -5,7 +5,9 @@ import java.util.ArrayList;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.ServletException
;
...
...
@@ -51,20 +53,29 @@ public class Handler implements PageHandler<Context> {
if
(
analyzer
!=
null
)
{
Payload
payload
=
ctx
.
getPayload
();
String
domain
=
payload
.
getDomain
();
List
<
String
>
domains
=
analyzer
.
getDomains
();
if
(
domain
==
null
&&
domains
.
size
()
>
0
)
{
domain
=
domains
.
get
(
0
);
payload
.
setDomain
(
domain
);
}
report
=
analyzer
.
generate
(
domain
);
model
.
setDomains
(
domains
);
}
else
{
report
=
new
IpReport
();
}
Calendar
cal
=
Calendar
.
getInstance
();
int
minute
=
cal
.
get
(
Calendar
.
MINUTE
);
List
<
DisplayModel
>
models
=
new
ArrayList
<
DisplayModel
>();
Map
<
String
,
DisplayModel
>
models
=
new
HashMap
<
String
,
DisplayModel
>();
DisplayModelBuilder
builder
=
new
DisplayModelBuilder
(
models
,
minute
);
report
.
accept
(
builder
);
// prepare display model
Collections
.
sort
(
models
,
new
Comparator
<
DisplayModel
>()
{
List
<
DisplayModel
>
displayModels
=
new
ArrayList
<
DisplayModel
>(
models
.
values
());
Collections
.
sort
(
displayModels
,
new
Comparator
<
DisplayModel
>()
{
@Override
public
int
compare
(
DisplayModel
m1
,
DisplayModel
m2
)
{
return
m2
.
getLastFifteen
()
-
m1
.
getLastFifteen
();
// desc
...
...
@@ -72,33 +83,39 @@ public class Handler implements PageHandler<Context> {
});
model
.
setReport
(
report
);
model
.
setDisplayModels
(
m
odels
);
model
.
setDisplayModels
(
displayM
odels
);
m_jspViewer
.
view
(
ctx
,
model
);
}
static
class
DisplayModelBuilder
extends
BaseVisitor
{
private
int
m_minute
;
private
List
<
DisplayModel
>
m_models
;
private
Map
<
String
,
DisplayModel
>
m_models
;
private
DisplayModel
m_model
;
private
Period
m_period
;
public
DisplayModelBuilder
(
List
<
DisplayModel
>
models
,
int
minute
)
{
public
DisplayModelBuilder
(
Map
<
String
,
DisplayModel
>
models
,
int
minute
)
{
m_models
=
models
;
m_minute
=
minute
;
}
@Override
public
void
visitIp
(
Ip
ip
)
{
m_model
=
new
DisplayModel
(
ip
.
getAddress
());
m_models
.
add
(
m_model
);
String
address
=
ip
.
getAddress
();
DisplayModel
model
=
m_models
.
get
(
address
);
if
(
model
==
null
)
{
model
=
new
DisplayModel
(
address
);
m_models
.
put
(
address
,
model
);
}
super
.
visitIp
(
ip
);
model
.
process
(
m_minute
,
m_period
.
getMinute
(),
ip
.
getCount
()
);
}
@Override
public
void
visitPeriod
(
Period
period
)
{
m_model
.
process
(
m_minute
,
period
.
getMinute
(),
period
.
getValue
());
m_period
=
period
;
super
.
visitPeriod
(
period
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/ip/Model.java
浏览文件 @
3742102c
...
...
@@ -11,6 +11,8 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
private
List
<
DisplayModel
>
m_displayModels
;
private
List
<
String
>
m_domains
;
public
Model
(
Context
ctx
)
{
super
(
ctx
);
}
...
...
@@ -24,6 +26,10 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
return
m_displayModels
;
}
public
List
<
String
>
getDomains
()
{
return
m_domains
;
}
public
IpReport
getReport
()
{
return
m_report
;
}
...
...
@@ -36,6 +42,10 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
m_displayModels
=
models
;
}
public
void
setDomains
(
List
<
String
>
domains
)
{
m_domains
=
domains
;
}
public
void
setReport
(
IpReport
report
)
{
m_report
=
report
;
}
...
...
cat-home/src/main/webapp/WEB-INF/tags/report.tag
浏览文件 @
3742102c
...
...
@@ -5,7 +5,7 @@
<%@ attribute name="title"%>
<%@ attribute name="timestamp"%>
<%@ attribute name="domain" fragment="true"%>
<%@ attribute name="
time
" fragment="true"%>
<%@ attribute name="
nav
" fragment="true"%>
<%@ attribute name="subtitle" fragment="true"%>
<a:body>
...
...
@@ -23,7 +23,7 @@
<table class="navbar">
<tr>
<td class="domain"><jsp:invoke fragment="domain"/></td>
<td class="
time"><jsp:invoke fragment="time
"/></td>
<td class="
nav"><jsp:invoke fragment="nav
"/></td>
</tr>
<tr>
<td class="subtitle"><jsp:invoke fragment="subtitle"/></td>
...
...
cat-home/src/main/webapp/css/report.css
浏览文件 @
3742102c
...
...
@@ -22,18 +22,37 @@
width
:
100%
;
}
.report
.navbar
.time
{
.report
.navbar
.domain
{
text-align
:
left
;
font-size
:
small
;
font-weight
:
bold
;
}
.report
.navbar
.domain
A
{
text-decoration
:
none
;
color
:
blue
;
}
.report
.navbar
.domain
.current
{
color
:
black
;
}
.report
.navbar
.domain
A
:hover
{
color
:
yellow
;
}
.report
.navbar
.nav
{
text-align
:
right
;
font-size
:
small
;
font-weight
:
bold
;
}
.report
.navbar
.
time
A
{
.report
.navbar
.
nav
A
{
text-decoration
:
none
;
color
:
blue
;
}
.report
.navbar
.
time
A
:hover
{
.report
.navbar
.
nav
A
:hover
{
color
:
yellow
;
}
...
...
cat-home/src/main/webapp/jsp/report/ip.jsp
浏览文件 @
3742102c
...
...
@@ -6,12 +6,21 @@
<jsp:useBean
id=
"payload"
type=
"com.dianping.cat.report.page.ip.Payload"
scope=
"request"
/>
<jsp:useBean
id=
"model"
type=
"com.dianping.cat.report.page.ip.Model"
scope=
"request"
/>
<a:report
title=
"Hot IP Report"
>
<a:report
title=
"Hot IP Report"
timestamp=
"2012-02-07"
>
<jsp:attribute
name=
"domain"
>
Domain: ${payload.domain}
<div
class=
"domain"
>
<c:forEach
var=
"domain"
items=
"
${
model
.
domains
}
"
>
[
<c:choose>
<c:when
test=
"
${
payload
.
domain
eq
domain
}
"
><a
href=
"?domain=${domain}"
class=
"current"
>
${domain}
</a></c:when>
<c:otherwise><a
href=
"?domain=${domain}"
>
${domain}
</a></c:otherwise>
</c:choose>
]
</c:forEach>
</div>
</jsp:attribute>
<jsp:attribute
name=
"
time
"
>
<jsp:attribute
name=
"
nav
"
>
[
<a
href=
""
>
-1d
</a>
] [
<a
href=
""
>
-2h
</a>
] [
<a
href=
""
>
-1h
</a>
] [
<a
href=
""
>
+1h
</a>
] [
<a
href=
""
>
+2h
</a>
] [
<a
href=
""
>
+1d
</a>
]
</jsp:attribute>
...
...
@@ -30,10 +39,7 @@
</tr>
</c:forEach>
</table>
<%-- <xmp>
${model.reportInJson}
</xmp> --%>
</jsp:body>
</a:report>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录