Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
4433cd7d
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,发现更多精彩内容 >>
提交
4433cd7d
编写于
6月 29, 2015
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify the domain health
上级
cc2b0b77
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
404 addition
and
16 deletion
+404
-16
cat-home/src/main/java/com/dianping/cat/report/page/top/Action.java
...rc/main/java/com/dianping/cat/report/page/top/Action.java
+2
-0
cat-home/src/main/java/com/dianping/cat/report/page/top/DomainInfo.java
...ain/java/com/dianping/cat/report/page/top/DomainInfo.java
+89
-0
cat-home/src/main/java/com/dianping/cat/report/page/top/Handler.java
...c/main/java/com/dianping/cat/report/page/top/Handler.java
+133
-9
cat-home/src/main/java/com/dianping/cat/report/page/top/JspViewer.java
...main/java/com/dianping/cat/report/page/top/JspViewer.java
+2
-0
cat-home/src/main/java/com/dianping/cat/report/page/top/Payload.java
...c/main/java/com/dianping/cat/report/page/top/Payload.java
+23
-1
cat-home/src/main/java/com/dianping/cat/report/page/top/ProblemReportVisitor.java
...om/dianping/cat/report/page/top/ProblemReportVisitor.java
+71
-0
cat-home/src/main/java/com/dianping/cat/report/page/top/TransactionReportVisitor.java
...ianping/cat/report/page/top/TransactionReportVisitor.java
+67
-0
cat-home/src/main/java/com/dianping/cat/report/page/transaction/service/LocalTransactionService.java
...ort/page/transaction/service/LocalTransactionService.java
+4
-6
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+13
-0
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/page/top/Action.java
浏览文件 @
4433cd7d
package
com.dianping.cat.report.page.top
;
public
enum
Action
implements
org
.
unidal
.
web
.
mvc
.
Action
{
HEALTH
(
"health"
),
VIEW
(
"view"
),
API
(
"api"
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/top/DomainInfo.java
0 → 100644
浏览文件 @
4433cd7d
package
com.dianping.cat.report.page.top
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
DomainInfo
{
public
Map
<
String
,
Metric
>
m_metrics
=
new
LinkedHashMap
<
String
,
Metric
>();
public
Metric
getMetric
(
String
key
)
{
Metric
m
=
m_metrics
.
get
(
key
);
if
(
m
==
null
)
{
m
=
new
Metric
();
m_metrics
.
put
(
key
,
m
);
}
return
m
;
}
public
Map
<
String
,
Metric
>
getMetrics
()
{
return
m_metrics
;
}
public
static
class
Item
{
private
long
m_count
;
private
double
m_avg
;
private
long
m_fail
;
public
double
getAvg
()
{
return
m_avg
;
}
public
long
getCount
()
{
return
m_count
;
}
public
long
getFail
()
{
return
m_fail
;
}
public
Item
setAvg
(
double
avg
)
{
m_avg
=
avg
;
return
this
;
}
public
Item
setCount
(
long
count
)
{
m_count
=
count
;
return
this
;
}
public
Item
setFail
(
long
fail
)
{
m_fail
=
fail
;
return
this
;
}
}
public
static
class
Metric
{
private
int
m_exception
;
private
Map
<
String
,
Item
>
m_items
=
new
LinkedHashMap
<
String
,
Item
>();
public
void
addException
(
int
count
)
{
m_exception
=
m_exception
+
count
;
}
public
Item
get
(
String
key
)
{
Item
item
=
m_items
.
get
(
key
);
if
(
item
==
null
)
{
item
=
new
Item
();
m_items
.
put
(
key
,
item
);
}
return
item
;
}
public
int
getException
()
{
return
m_exception
;
}
public
void
setException
(
int
exception
)
{
m_exception
=
exception
;
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/top/Handler.java
浏览文件 @
4433cd7d
...
...
@@ -5,7 +5,11 @@ import java.text.SimpleDateFormat;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
javax.servlet.ServletException
;
...
...
@@ -16,9 +20,14 @@ 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.Cat
;
import
com.dianping.cat.Constants
;
import
com.dianping.cat.consumer.problem.ProblemAnalyzer
;
import
com.dianping.cat.consumer.problem.model.entity.ProblemReport
;
import
com.dianping.cat.consumer.top.TopAnalyzer
;
import
com.dianping.cat.consumer.top.model.entity.TopReport
;
import
com.dianping.cat.consumer.transaction.TransactionAnalyzer
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionReport
;
import
com.dianping.cat.helper.JsonBuilder
;
import
com.dianping.cat.helper.TimeHelper
;
import
com.dianping.cat.mvc.PayloadNormalizer
;
...
...
@@ -28,7 +37,9 @@ import com.dianping.cat.report.page.dependency.ExternalInfoBuilder;
import
com.dianping.cat.report.page.dependency.TopExceptionExclude
;
import
com.dianping.cat.report.page.dependency.TopMetric
;
import
com.dianping.cat.report.page.state.StateBuilder
;
import
com.dianping.cat.report.page.top.DomainInfo.Metric
;
import
com.dianping.cat.report.page.top.service.TopReportService
;
import
com.dianping.cat.report.page.transaction.transform.TransactionMergeHelper
;
import
com.dianping.cat.report.service.ModelRequest
;
import
com.dianping.cat.report.service.ModelResponse
;
import
com.dianping.cat.report.service.ModelService
;
...
...
@@ -49,9 +60,18 @@ public class Handler implements PageHandler<Context> {
@Inject
(
type
=
ModelService
.
class
,
value
=
TopAnalyzer
.
ID
)
private
ModelService
<
TopReport
>
m_topService
;
@Inject
(
type
=
ModelService
.
class
,
value
=
TransactionAnalyzer
.
ID
)
private
ModelService
<
TransactionReport
>
m_transactionService
;
@Inject
(
type
=
ModelService
.
class
,
value
=
ProblemAnalyzer
.
ID
)
private
ModelService
<
ProblemReport
>
m_problemService
;
@Inject
private
TopReportService
m_topReportService
;
@Inject
private
TransactionMergeHelper
m_mergeHelper
;
@Inject
private
ExceptionRuleConfigManager
m_configManager
;
...
...
@@ -100,23 +120,28 @@ public class Handler implements PageHandler<Context> {
public
void
handleOutbound
(
Context
ctx
)
throws
ServletException
,
IOException
{
Model
model
=
new
Model
(
ctx
);
Payload
payload
=
ctx
.
getPayload
();
Action
action
=
payload
.
getAction
();
model
.
setAction
(
action
);
model
.
setPage
(
ReportPage
.
TOP
);
normalize
(
model
,
payload
);
long
date
=
payload
.
getDate
();
buildExceptionDashboard
(
model
,
payload
,
date
);
model
.
setMessage
(
m_stateBuilder
.
buildStateMessage
(
payload
.
getDate
(),
payload
.
getIpAddress
())
);
if
(
action
==
Action
.
HEALTH
)
{
DomainInfo
info
=
buildDomainInfo
(
payload
,
model
);
switch
(
action
)
{
case
VIEW:
if
(!
ctx
.
isProcessStopped
())
{
m_jspViewer
.
view
(
ctx
,
model
);
ctx
.
getHttpServletResponse
().
getWriter
().
write
(
m_builder
.
toJson
(
info
));
}
else
{
buildExceptionDashboard
(
model
,
payload
,
date
);
model
.
setMessage
(
m_stateBuilder
.
buildStateMessage
(
payload
.
getDate
(),
payload
.
getIpAddress
()));
if
(
action
==
Action
.
VIEW
)
{
if
(!
ctx
.
isProcessStopped
())
{
m_jspViewer
.
view
(
ctx
,
model
);
}
}
else
if
(
action
==
Action
.
API
)
{
ctx
.
getHttpServletResponse
().
getWriter
().
write
(
m_builder
.
toJson
(
model
.
getTopMetric
()));
}
case
API:
ctx
.
getHttpServletResponse
().
getWriter
().
write
(
m_builder
.
toJson
(
model
.
getTopMetric
()));
}
}
...
...
@@ -155,6 +180,44 @@ public class Handler implements PageHandler<Context> {
return
minute
;
}
private
DomainInfo
buildDomainInfo
(
Payload
payload
,
Model
model
)
{
long
date
=
payload
.
getDate
();
int
minute
=
model
.
getMinute
();
int
exceptedMinute
=
payload
.
getMinuteCounts
();
DomainInfo
info
=
new
DomainInfo
();
if
(
minute
<
exceptedMinute
)
{
buildTransactionInfo
(
payload
,
date
-
TimeHelper
.
ONE_HOUR
,
info
);
buildProblemInfo
(
payload
,
date
-
TimeHelper
.
ONE_HOUR
,
info
);
}
buildTransactionInfo
(
payload
,
date
,
info
);
buildProblemInfo
(
payload
,
date
,
info
);
Map
<
String
,
Metric
>
metrics
=
info
.
getMetrics
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
long
end
=
date
+
minute
*
TimeHelper
.
ONE_MINUTE
;
long
start
=
end
-
exceptedMinute
*
TimeHelper
.
ONE_MINUTE
;
Set
<
String
>
removed
=
new
HashSet
<
String
>();
for
(
Entry
<
String
,
Metric
>
entry
:
metrics
.
entrySet
())
{
String
key
=
entry
.
getKey
();
try
{
long
d
=
sdf
.
parse
(
key
).
getTime
();
if
(
d
<=
start
||
d
>
end
)
{
removed
.
add
(
key
);
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
for
(
String
s
:
removed
)
{
metrics
.
remove
(
s
);
}
return
info
;
}
private
TopReport
queryTopReport
(
Payload
payload
)
{
String
domain
=
Constants
.
CAT
;
String
date
=
String
.
valueOf
(
payload
.
getDate
());
...
...
@@ -175,4 +238,65 @@ public class Handler implements PageHandler<Context> {
throw
new
RuntimeException
(
"Internal error: no eligable top service registered for "
+
request
+
"!"
);
}
}
private
void
buildTransactionInfo
(
Payload
payload
,
long
date
,
DomainInfo
info
)
{
String
domain
=
payload
.
getDomain
();
String
ipAddress
=
payload
.
getIpAddress
();
if
(
StringUtils
.
isEmpty
(
ipAddress
))
{
ipAddress
=
Constants
.
ALL
;
}
TransactionReport
urlReport
=
quertTrasactionReport
(
domain
,
ipAddress
,
date
,
"URL"
);
TransactionReport
serviceReport
=
quertTrasactionReport
(
domain
,
ipAddress
,
date
,
"PigeonService"
);
new
TransactionReportVisitor
(
ipAddress
,
info
,
"URL"
).
visitTransactionReport
(
urlReport
);
new
TransactionReportVisitor
(
ipAddress
,
info
,
"PigeonService"
).
visitTransactionReport
(
serviceReport
);
}
private
void
buildProblemInfo
(
Payload
payload
,
long
date
,
DomainInfo
info
)
{
String
domain
=
payload
.
getDomain
();
String
ipAddress
=
payload
.
getIpAddress
();
if
(
StringUtils
.
isEmpty
(
ipAddress
))
{
ipAddress
=
Constants
.
ALL
;
}
ProblemReport
report
=
queryProblemReport
(
domain
,
ipAddress
,
date
,
"error"
);
new
ProblemReportVisitor
(
ipAddress
,
info
,
"error"
).
visitProblemReport
(
report
);
}
private
TransactionReport
quertTrasactionReport
(
String
domain
,
String
ipAddress
,
long
date
,
String
type
)
{
ModelRequest
request
=
new
ModelRequest
(
domain
,
date
).
setProperty
(
"type"
,
type
)
.
setProperty
(
"name"
,
Constants
.
ALL
).
setProperty
(
"ip"
,
ipAddress
);
if
(
m_transactionService
.
isEligable
(
request
))
{
ModelResponse
<
TransactionReport
>
response
=
m_transactionService
.
invoke
(
request
);
TransactionReport
report
=
response
.
getModel
();
report
=
m_mergeHelper
.
mergeAllMachines
(
report
,
ipAddress
);
return
report
;
}
else
{
throw
new
RuntimeException
(
"Internal error: no eligable transaction service registered for "
+
request
+
"!"
);
}
}
private
ProblemReport
queryProblemReport
(
String
domain
,
String
ipAddress
,
long
date
,
String
type
)
{
ModelRequest
request
=
new
ModelRequest
(
domain
,
date
).
setProperty
(
"type"
,
type
)
.
setProperty
(
"queryType"
,
"detail"
);
if
(!
Constants
.
ALL
.
equals
(
ipAddress
))
{
request
.
setProperty
(
"ip"
,
ipAddress
);
}
if
(
m_problemService
.
isEligable
(
request
))
{
ModelResponse
<
ProblemReport
>
response
=
m_problemService
.
invoke
(
request
);
ProblemReport
report
=
response
.
getModel
();
return
report
;
}
else
{
throw
new
RuntimeException
(
"Internal error: no eligible problem service registered for "
+
request
+
"!"
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/top/JspViewer.java
浏览文件 @
4433cd7d
...
...
@@ -13,6 +13,8 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model>
return
JspFile
.
VIEW
.
getPath
();
case
API:
return
JspFile
.
API
.
getPath
();
case
HEALTH:
return
JspFile
.
API
.
getPath
();
}
throw
new
RuntimeException
(
"Unknown action: "
+
action
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/top/Payload.java
浏览文件 @
4433cd7d
...
...
@@ -6,7 +6,7 @@ import org.unidal.web.mvc.payload.annotation.FieldMeta;
import
com.dianping.cat.mvc.AbstractReportPayload
;
import
com.dianping.cat.report.ReportPage
;
public
class
Payload
extends
AbstractReportPayload
<
Action
,
ReportPage
>
{
public
class
Payload
extends
AbstractReportPayload
<
Action
,
ReportPage
>
{
private
ReportPage
m_page
;
@FieldMeta
(
"op"
)
...
...
@@ -30,6 +30,12 @@ public class Payload extends AbstractReportPayload<Action,ReportPage> {
@FieldMeta
(
"fullScreen"
)
private
boolean
m_fullScreen
=
false
;
@FieldMeta
(
"domain"
)
private
String
m_domain
;
@FieldMeta
(
"ip"
)
private
String
m_ip
;
public
Payload
()
{
super
(
ReportPage
.
TOP
);
}
...
...
@@ -105,6 +111,22 @@ public class Payload extends AbstractReportPayload<Action,ReportPage> {
m_topCounts
=
topCounts
;
}
public
String
getDomain
()
{
return
m_domain
;
}
public
void
setDomain
(
String
domain
)
{
m_domain
=
domain
;
}
public
String
getIp
()
{
return
m_ip
;
}
public
void
setIp
(
String
ip
)
{
m_ip
=
ip
;
}
@Override
public
void
validate
(
ActionContext
<?>
ctx
)
{
if
(
m_action
==
null
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/page/top/ProblemReportVisitor.java
0 → 100644
浏览文件 @
4433cd7d
package
com.dianping.cat.report.page.top
;
import
java.text.SimpleDateFormat
;
import
com.dianping.cat.Constants
;
import
com.dianping.cat.consumer.problem.model.entity.Entity
;
import
com.dianping.cat.consumer.problem.model.entity.Machine
;
import
com.dianping.cat.consumer.problem.model.entity.ProblemReport
;
import
com.dianping.cat.consumer.problem.model.entity.Segment
;
import
com.dianping.cat.consumer.problem.model.transform.BaseVisitor
;
import
com.dianping.cat.report.page.top.DomainInfo.Metric
;
public
class
ProblemReportVisitor
extends
BaseVisitor
{
private
DomainInfo
m_info
;
private
String
m_ipAddress
;
private
String
m_type
;
private
String
m_date
;
private
Integer
m_minute
;
@Override
public
void
visitProblemReport
(
ProblemReport
problemReport
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:"
);
m_date
=
sdf
.
format
(
problemReport
.
getStartTime
());
super
.
visitProblemReport
(
problemReport
);
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
String
id
=
machine
.
getIp
();
if
(
Constants
.
ALL
.
equals
(
m_ipAddress
)
||
id
.
equals
(
m_ipAddress
))
{
super
.
visitMachine
(
machine
);
}
}
public
ProblemReportVisitor
(
String
ipAddress
,
DomainInfo
info
,
String
type
)
{
m_info
=
info
;
m_type
=
type
;
m_ipAddress
=
ipAddress
;
}
@Override
public
void
visitEntity
(
Entity
entity
)
{
if
(
m_type
.
equals
(
entity
.
getType
()))
{
super
.
visitEntity
(
entity
);
}
}
@Override
public
void
visitSegment
(
Segment
segment
)
{
m_minute
=
segment
.
getId
();
int
count
=
segment
.
getCount
();
String
key
=
""
;
if
(
m_minute
>=
10
)
{
key
=
m_date
+
m_minute
;
}
else
{
key
=
m_date
+
'0'
+
m_minute
;
}
Metric
metric
=
m_info
.
getMetric
(
key
);
metric
.
addException
(
count
);
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/page/top/TransactionReportVisitor.java
0 → 100644
浏览文件 @
4433cd7d
package
com.dianping.cat.report.page.top
;
import
java.text.SimpleDateFormat
;
import
com.dianping.cat.Constants
;
import
com.dianping.cat.consumer.transaction.model.entity.Machine
;
import
com.dianping.cat.consumer.transaction.model.entity.Range
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionReport
;
import
com.dianping.cat.consumer.transaction.model.entity.TransactionType
;
import
com.dianping.cat.consumer.transaction.model.transform.BaseVisitor
;
import
com.dianping.cat.report.page.top.DomainInfo.Metric
;
public
class
TransactionReportVisitor
extends
BaseVisitor
{
private
DomainInfo
m_info
;
private
String
m_ipAddress
;
private
String
m_type
;
private
String
m_date
;
@Override
public
void
visitTransactionReport
(
TransactionReport
transactionReport
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:"
);
m_date
=
sdf
.
format
(
transactionReport
.
getStartTime
());
super
.
visitTransactionReport
(
transactionReport
);
}
@Override
public
void
visitMachine
(
Machine
machine
)
{
String
id
=
machine
.
getIp
();
if
(
Constants
.
ALL
.
equals
(
m_ipAddress
)
||
id
.
equals
(
m_ipAddress
))
{
super
.
visitMachine
(
machine
);
}
}
public
TransactionReportVisitor
(
String
ipAddress
,
DomainInfo
info
,
String
type
)
{
m_info
=
info
;
m_type
=
type
;
m_ipAddress
=
ipAddress
;
}
@Override
public
void
visitType
(
TransactionType
type
)
{
if
(
type
.
getId
().
equals
(
m_type
))
{
super
.
visitType
(
type
);
}
}
@Override
public
void
visitRange
(
Range
range
)
{
int
minute
=
range
.
getValue
();
String
key
=
""
;
if
(
minute
>=
10
)
{
key
=
m_date
+
minute
;
}
else
{
key
=
m_date
+
'0'
+
minute
;
}
Metric
metric
=
m_info
.
getMetric
(
key
);
metric
.
get
(
m_type
).
setFail
(
range
.
getFails
()).
setCount
(
range
.
getCount
()).
setAvg
(
range
.
getCount
());
}
}
\ No newline at end of file
cat-home/src/main/java/com/dianping/cat/report/page/transaction/service/LocalTransactionService.java
浏览文件 @
4433cd7d
...
...
@@ -139,12 +139,10 @@ public class LocalTransactionService extends LocalModelService<TransactionReport
@Override
public
void
visitMachine
(
com
.
dianping
.
cat
.
consumer
.
transaction
.
model
.
entity
.
Machine
machine
)
{
synchronized
(
machine
)
{
if
(
m_ipAddress
==
null
||
m_ipAddress
.
equals
(
Constants
.
ALL
))
{
super
.
visitMachine
(
machine
);
}
else
if
(
machine
.
getIp
().
equals
(
m_ipAddress
))
{
super
.
visitMachine
(
machine
);
}
if
(
m_ipAddress
==
null
||
m_ipAddress
.
equals
(
Constants
.
ALL
))
{
super
.
visitMachine
(
machine
);
}
else
if
(
machine
.
getIp
().
equals
(
m_ipAddress
))
{
super
.
visitMachine
(
machine
);
}
}
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
4433cd7d
...
...
@@ -5833,9 +5833,22 @@
<role-hint>
top
</role-hint>
<field-name>
m_topService
</field-name>
</requirement>
<requirement>
<role>
com.dianping.cat.report.service.ModelService
</role>
<role-hint>
transaction
</role-hint>
<field-name>
m_transactionService
</field-name>
</requirement>
<requirement>
<role>
com.dianping.cat.report.service.ModelService
</role>
<role-hint>
problem
</role-hint>
<field-name>
m_problemService
</field-name>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.top.service.TopReportService
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.transaction.transform.TransactionMergeHelper
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.alert.exception.ExceptionRuleConfigManager
</role>
</requirement>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录