Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
44797278
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,发现更多精彩内容 >>
提交
44797278
编写于
5月 21, 2014
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
fix cat broker service
上级
0dfcc047
dec0030c
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
204 addition
and
156 deletion
+204
-156
cat-broker/src/main/java/com/dianping/cat/broker/api/page/MonitorManager.java
...java/com/dianping/cat/broker/api/page/MonitorManager.java
+68
-67
cat-broker/src/main/java/com/dianping/cat/broker/api/page/RequestUtils.java
...n/java/com/dianping/cat/broker/api/page/RequestUtils.java
+11
-3
cat-broker/src/test/java/com/dianping/cat/broker/IpServiceTest.java
.../src/test/java/com/dianping/cat/broker/IpServiceTest.java
+3
-0
cat-broker/src/test/java/com/dianping/cat/broker/RequestUtilsTest.java
...c/test/java/com/dianping/cat/broker/RequestUtilsTest.java
+22
-0
cat-core/src/main/java/com/dianping/cat/config/DefaultUrlPatternHandler.java
...ava/com/dianping/cat/config/DefaultUrlPatternHandler.java
+19
-2
cat-core/src/main/java/com/dianping/cat/config/UrlPatternConfigManager.java
...java/com/dianping/cat/config/UrlPatternConfigManager.java
+3
-5
cat-core/src/main/java/com/dianping/cat/config/UrlPatternHandler.java
.../main/java/com/dianping/cat/config/UrlPatternHandler.java
+3
-6
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/Handler.java
...ava/com/dianping/cat/report/page/userMonitor/Handler.java
+4
-3
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/Model.java
.../java/com/dianping/cat/report/page/userMonitor/Model.java
+3
-3
cat-home/src/main/java/com/dianping/cat/report/task/metric/BaseAlertConfig.java
.../com/dianping/cat/report/task/metric/BaseAlertConfig.java
+56
-50
cat-home/src/main/java/com/dianping/cat/report/task/metric/SwitchAlertConfig.java
...om/dianping/cat/report/task/metric/SwitchAlertConfig.java
+4
-13
cat-home/src/main/java/com/dianping/cat/system/page/config/Model.java
.../main/java/com/dianping/cat/system/page/config/Model.java
+4
-3
cat-home/src/main/webapp/jsp/system/urlPattern/urlPatternUpdate.jsp
...rc/main/webapp/jsp/system/urlPattern/urlPatternUpdate.jsp
+4
-1
未找到文件。
cat-broker/src/main/java/com/dianping/cat/broker/api/page/MonitorManager.java
浏览文件 @
44797278
...
...
@@ -74,87 +74,88 @@ public class MonitorManager implements Initializable, LogEnabled {
}
public
boolean
offer
(
MonitorEntity
entity
)
{
m_total
++;
if
(!
StringUtils
.
isEmpty
(
entity
.
getTargetUrl
()))
{
m_total
++;
int
index
=
(
int
)
(
m_total
%
m_threadCounts
);
int
retryTime
=
0
;
int
index
=
(
int
)
(
m_total
%
m_threadCounts
);
int
retryTime
=
0
;
while
(
retryTime
<
m_threadCounts
)
{
BlockingQueue
<
MonitorEntity
>
queue
=
m_queues
.
get
((
index
+
retryTime
)
%
m_threadCounts
);
boolean
result
=
queue
.
offer
(
entity
);
while
(
retryTime
<
m_threadCounts
)
{
BlockingQueue
<
MonitorEntity
>
queue
=
m_queues
.
get
((
index
+
retryTime
)
%
m_threadCounts
);
boolean
result
=
queue
.
offer
(
entity
);
if
(
result
)
{
return
true
;
if
(
result
)
{
return
true
;
}
retryTime
++;
}
retryTime
++;
}
m_errorCount
++;
if
(
m_errorCount
%
CatConstants
.
ERROR_COUNT
==
0
)
{
m_logger
.
error
(
"Error when offer entity to queues, size:"
+
m_errorCount
);
m_errorCount
++;
if
(
m_errorCount
%
CatConstants
.
ERROR_COUNT
==
0
)
{
m_logger
.
error
(
"Error when offer entity to queues, size:"
+
m_errorCount
);
}
}
return
false
;
}
private
void
processOneEntity
(
MonitorEntity
entity
)
{
String
targetUrl
=
entity
.
getTargetUrl
();
if
(
targetUrl
!=
null
)
{
String
url
=
getFormatUrl
(
targetUrl
);
if
(
url
!=
null
)
{
Transaction
t
=
Cat
.
newTransaction
(
"Monitor"
,
url
);
try
{
String
ip
=
entity
.
getIp
();
IpInfo
ipInfo
=
m_ipService
.
findIpInfoByString
(
ip
);
if
(
ipInfo
!=
null
)
{
String
city
=
ipInfo
.
getProvince
()
+
"-"
+
ipInfo
.
getCity
();
String
channel
=
ipInfo
.
getChannel
();
String
httpCode
=
entity
.
getHttpStatus
();
String
errorCode
=
entity
.
getErrorCode
();
long
timestamp
=
entity
.
getTimestamp
();
double
duration
=
entity
.
getDuration
();
String
group
=
url
;
if
(
duration
>
0
)
{
logMetric
(
timestamp
,
duration
,
group
,
city
+
":"
+
channel
+
":"
+
Monitor
.
HIT
);
}
if
(!
"200"
.
equals
(
httpCode
)
||
!
StringUtils
.
isEmpty
(
errorCode
))
{
logMetric
(
timestamp
,
duration
,
group
,
city
+
":"
+
channel
+
":"
+
Monitor
.
ERROR
);
}
if
(!
StringUtils
.
isEmpty
(
httpCode
))
{
String
key
=
city
+
":"
+
channel
+
":"
+
Monitor
.
HTTP_STATUS
+
"|"
+
httpCode
;
Metric
metric
=
Cat
.
getProducer
().
newMetric
(
group
,
key
);
DefaultMetric
defaultMetric
=
(
DefaultMetric
)
metric
;
defaultMetric
.
setTimestamp
(
timestamp
);
defaultMetric
.
setStatus
(
"C"
);
defaultMetric
.
addData
(
String
.
valueOf
(
1
));
}
if
(!
StringUtils
.
isEmpty
(
errorCode
))
{
String
key
=
city
+
":"
+
channel
+
":"
+
Monitor
.
ERROR_CODE
+
"|"
+
errorCode
;
Metric
metric
=
Cat
.
getProducer
().
newMetric
(
group
,
key
);
DefaultMetric
defaultMetric
=
(
DefaultMetric
)
metric
;
defaultMetric
.
setTimestamp
(
timestamp
);
defaultMetric
.
setStatus
(
"C"
);
defaultMetric
.
addData
(
String
.
valueOf
(
1
));
}
}
else
{
Cat
.
logEvent
(
"IpService"
,
"NotFound"
,
Event
.
SUCCESS
,
ip
);
m_logger
.
error
(
String
.
format
(
"ip service can't resolve ip: "
,
ip
));
String
url
=
getFormatUrl
(
targetUrl
);
if
(
url
!=
null
)
{
Transaction
t
=
Cat
.
newTransaction
(
"Monitor"
,
url
);
try
{
String
ip
=
entity
.
getIp
();
IpInfo
ipInfo
=
m_ipService
.
findIpInfoByString
(
ip
);
if
(
ipInfo
!=
null
)
{
String
city
=
ipInfo
.
getProvince
()
+
"-"
+
ipInfo
.
getCity
();
String
channel
=
ipInfo
.
getChannel
();
String
httpCode
=
entity
.
getHttpStatus
();
String
errorCode
=
entity
.
getErrorCode
();
long
timestamp
=
entity
.
getTimestamp
();
double
duration
=
entity
.
getDuration
();
String
group
=
url
;
if
(
duration
>
0
)
{
logMetric
(
timestamp
,
duration
,
group
,
city
+
":"
+
channel
+
":"
+
Monitor
.
HIT
);
}
if
(!
"200"
.
equals
(
httpCode
)
||
!
StringUtils
.
isEmpty
(
errorCode
))
{
logMetric
(
timestamp
,
duration
,
group
,
city
+
":"
+
channel
+
":"
+
Monitor
.
ERROR
);
}
t
.
setStatus
(
Transaction
.
SUCCESS
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
t
.
setStatus
(
e
);
}
finally
{
t
.
complete
();
if
(!
StringUtils
.
isEmpty
(
httpCode
))
{
String
key
=
city
+
":"
+
channel
+
":"
+
Monitor
.
HTTP_STATUS
+
"|"
+
httpCode
;
Metric
metric
=
Cat
.
getProducer
().
newMetric
(
group
,
key
);
DefaultMetric
defaultMetric
=
(
DefaultMetric
)
metric
;
defaultMetric
.
setTimestamp
(
timestamp
);
defaultMetric
.
setStatus
(
"C"
);
defaultMetric
.
addData
(
String
.
valueOf
(
1
));
}
if
(!
StringUtils
.
isEmpty
(
errorCode
))
{
String
key
=
city
+
":"
+
channel
+
":"
+
Monitor
.
ERROR_CODE
+
"|"
+
errorCode
;
Metric
metric
=
Cat
.
getProducer
().
newMetric
(
group
,
key
);
DefaultMetric
defaultMetric
=
(
DefaultMetric
)
metric
;
defaultMetric
.
setTimestamp
(
timestamp
);
defaultMetric
.
setStatus
(
"C"
);
defaultMetric
.
addData
(
String
.
valueOf
(
1
));
}
}
else
{
Cat
.
logEvent
(
"IpService"
,
"NotFound"
,
Event
.
SUCCESS
,
ip
);
m_logger
.
error
(
String
.
format
(
"ip service can't resolve ip: "
,
ip
));
}
t
.
setStatus
(
Transaction
.
SUCCESS
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
t
.
setStatus
(
e
);
}
finally
{
t
.
complete
();
}
}
else
{
m_logger
.
info
(
String
.
format
(
"no pattern for url"
,
targetUrl
));
}
}
...
...
cat-broker/src/main/java/com/dianping/cat/broker/api/page/RequestUtils.java
浏览文件 @
44797278
...
...
@@ -4,7 +4,7 @@ import javax.servlet.http.HttpServletRequest;
public
class
RequestUtils
{
p
rivate
String
filterXForwardedForIP
(
String
ip
)
{
p
ublic
String
filterXForwardedForIP
(
String
ip
)
{
if
(
ip
==
null
||
ip
.
trim
().
length
()
==
0
)
{
return
null
;
}
else
{
...
...
@@ -19,9 +19,17 @@ public class RequestUtils {
continue
;
}
else
{
subIp
=
subIp
.
trim
();
if
(
subIp
.
startsWith
(
"192.168."
)
||
subIp
.
startsWith
(
"10.1"
)
||
subIp
.
startsWith
(
"10.2"
)
||
"127.0.0.1"
.
equals
(
subIp
))
{
if
(
subIp
.
startsWith
(
"192.168."
)
||
subIp
.
startsWith
(
"10."
)
||
"127.0.0.1"
.
equals
(
subIp
))
{
continue
;
}
else
if
(
subIp
.
startsWith
(
"172."
))
{
String
[]
iptabs
=
subIp
.
split
(
"\\."
);
int
tab2
=
Integer
.
parseInt
(
iptabs
[
1
]);
if
(
tab2
>=
16
&&
tab2
<=
31
)
{
continue
;
}
else
{
return
subIp
;
}
}
else
{
return
subIp
;
}
...
...
cat-broker/src/test/java/com/dianping/cat/broker/IpServiceTest.java
浏览文件 @
44797278
...
...
@@ -10,6 +10,9 @@ public class IpServiceTest extends ComponentTestCase {
@Test
public
void
test
()
throws
Exception
{
IpService
service
=
(
IpService
)
lookup
(
IpService
.
class
);
System
.
err
.
println
(
service
.
findIpInfoByString
(
"10.10.253.20"
));
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
String
ip
=
i
%
255
+
"."
+
i
%
255
+
"."
+
i
%
255
+
"."
+
i
%
255
;
...
...
cat-broker/src/test/java/com/dianping/cat/broker/RequestUtilsTest.java
0 → 100644
浏览文件 @
44797278
package
com.dianping.cat.broker
;
import
junit.framework.Assert
;
import
org.junit.Test
;
import
com.dianping.cat.broker.api.page.RequestUtils
;
public
class
RequestUtilsTest
{
@Test
public
void
test
(){
RequestUtils
utils
=
new
RequestUtils
();
Assert
.
assertEquals
(
null
,
utils
.
filterXForwardedForIP
(
"10.1.6.128,10.1.6.128"
));
Assert
.
assertEquals
(
null
,
utils
.
filterXForwardedForIP
(
"172.16.6.128,172.16.6.128"
));
Assert
.
assertEquals
(
null
,
utils
.
filterXForwardedForIP
(
"172.31.6.128,172.31.6.128"
));
Assert
.
assertEquals
(
null
,
utils
.
filterXForwardedForIP
(
"192.168.0.1,192.168.0.1"
));
Assert
.
assertEquals
(
"172.32.6.128"
,
utils
.
filterXForwardedForIP
(
"172.32.6.128,172.32.6.128"
));
}
}
cat-core/src/main/java/com/dianping/cat/config/DefaultUrlPatternHandler.java
浏览文件 @
44797278
package
com.dianping.cat.config
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -8,9 +9,12 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
com.dianping.cat.configuration.url.pattern.entity.PatternItem
;
public
class
DefaultUrlPatternHandler
implements
UrlPatternHandler
{
public
class
DefaultUrlPatternHandler
implements
UrlPatternHandler
,
LogEnabled
{
private
TrieTreeNode
m_formats
=
new
TrieTreeNode
();
...
...
@@ -18,6 +22,8 @@ public class DefaultUrlPatternHandler implements UrlPatternHandler {
private
Map
<
String
,
String
>
m_urlToId
=
new
HashMap
<
String
,
String
>();
private
Logger
m_logger
;
/**
* build a format tree use prefix as trieTree index and suffix as map key or conversely
*
...
...
@@ -156,11 +162,15 @@ public class DefaultUrlPatternHandler implements UrlPatternHandler {
}
@Override
public
void
register
(
List
<
PatternItem
>
rules
)
{
public
void
register
(
Collection
<
PatternItem
>
rules
)
{
m_logger
.
info
(
"register url pattern start"
);
TrieTreeNode
formats
=
new
TrieTreeNode
();
for
(
PatternItem
item
:
rules
)
{
String
format
=
item
.
getPattern
();
m_logger
.
info
(
String
.
format
(
"url pattern id : %s ,pattern : %s"
,
item
.
getName
(),
item
.
getPattern
()));
if
(
format
==
null
||
format
.
isEmpty
())
{
continue
;
}
...
...
@@ -188,5 +198,12 @@ public class DefaultUrlPatternHandler implements UrlPatternHandler {
buildFormatTree
(
formats
,
key1
.
toCharArray
(),
key2
.
toCharArray
(),
value
);
}
m_formats
=
formats
;
m_logger
.
info
(
"register url pattern end"
);
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
}
cat-core/src/main/java/com/dianping/cat/config/UrlPatternConfigManager.java
浏览文件 @
44797278
...
...
@@ -2,7 +2,7 @@ package com.dianping.cat.config;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.
List
;
import
java.util.
Collection
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.unidal.dal.jdbc.DalException
;
...
...
@@ -90,10 +90,8 @@ public class UrlPatternConfigManager implements Initializable {
return
m_UrlPattern
.
findPatternItem
(
key
);
}
public
List
<
PatternItem
>
queryUrlPatternRules
()
{
ArrayList
<
PatternItem
>
patterns
=
new
ArrayList
<
PatternItem
>(
m_UrlPattern
.
getPatternItems
().
values
());
return
patterns
;
public
Collection
<
PatternItem
>
queryUrlPatternRules
()
{
return
m_UrlPattern
.
getPatternItems
().
values
();
}
public
void
refreshUrlPatternConfig
()
throws
DalException
,
SAXException
,
IOException
{
...
...
cat-core/src/main/java/com/dianping/cat/config/UrlPatternHandler.java
浏览文件 @
44797278
package
com.dianping.cat.config
;
import
java.util.
List
;
import
java.util.
Collection
;
import
com.dianping.cat.configuration.url.pattern.entity.PatternItem
;
public
interface
UrlPatternHandler
{
/**
* register aggregation rule to handler
*
* @param formats
* page type and domain to rule List Map
* register url rule to handler
*/
public
void
register
(
List
<
PatternItem
>
rules
);
public
void
register
(
Collection
<
PatternItem
>
rules
);
/**
* parse input to output use aggregation rule
...
...
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/Handler.java
浏览文件 @
44797278
package
com.dianping.cat.report.page.userMonitor
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.ServletException
;
...
...
@@ -55,7 +56,7 @@ public class Handler implements PageHandler<Context> {
Payload
payload
=
ctx
.
getPayload
();
normalize
(
model
,
payload
);
List
<
PatternItem
>
rules
=
m_patternManager
.
queryUrlPatternRules
();
Collection
<
PatternItem
>
rules
=
m_patternManager
.
queryUrlPatternRules
();
long
start
=
payload
.
getHistoryStartDate
().
getTime
();
long
end
=
payload
.
getHistoryEndDate
().
getTime
();
...
...
@@ -72,7 +73,7 @@ public class Handler implements PageHandler<Context> {
String
url
=
payload
.
getUrl
();
if
(
url
==
null
&&
rules
.
size
()
>
0
)
{
url
=
rules
.
get
(
0
).
getName
();
url
=
new
ArrayList
<
PatternItem
>(
rules
)
.
get
(
0
).
getName
();
}
pars
.
put
(
"type"
,
type
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/userMonitor/Model.java
浏览文件 @
44797278
...
...
@@ -13,7 +13,7 @@ import com.dianping.cat.report.page.PieChart;
public
class
Model
extends
AbstractReportModel
<
Action
,
Context
>
{
private
List
<
PatternItem
>
m_pattermItems
;
private
Collection
<
PatternItem
>
m_pattermItems
;
private
List
<
String
>
m_cities
;
...
...
@@ -72,7 +72,7 @@ public class Model extends AbstractReportModel<Action, Context> {
}
}
public
List
<
PatternItem
>
getPattermItems
()
{
public
Collection
<
PatternItem
>
getPattermItems
()
{
return
m_pattermItems
;
}
...
...
@@ -104,7 +104,7 @@ public class Model extends AbstractReportModel<Action, Context> {
m_lineCharts
=
lineCharts
;
}
public
void
setPattermItems
(
List
<
PatternItem
>
pattermItems
)
{
public
void
setPattermItems
(
Collection
<
PatternItem
>
pattermItems
)
{
m_pattermItems
=
pattermItems
;
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/metric/BaseAlertConfig.java
浏览文件 @
44797278
...
...
@@ -21,14 +21,23 @@ public abstract class BaseAlertConfig {
public
abstract
List
<
String
>
buildExceptionSMSReceivers
(
ProductLine
productLine
);
public
abstract
List
<
String
>
buildMailReceivers
(
ProductLine
productLine
);
protected
double
[]
buildLastMinutes
(
double
[]
doubleList
,
int
remainCount
)
{
if
(
doubleList
.
length
<=
remainCount
)
{
return
doubleList
;
}
public
abstract
List
<
String
>
buildMailReceivers
(
Project
project
);
double
[]
result
=
new
double
[
remainCount
];
int
startIndex
=
doubleList
.
length
-
remainCount
;
public
abstract
List
<
String
>
buildSMSReceivers
(
ProductLine
productLine
);
for
(
int
i
=
0
;
i
<
remainCount
;
i
++)
{
result
[
i
]
=
doubleList
[
startIndex
+
i
];
}
return
result
;
}
public
abstract
Pair
<
Boolean
,
String
>
checkData
(
double
[]
value
,
double
[]
baseline
,
MetricType
type
,
List
<
Config
>
configs
);
public
abstract
List
<
String
>
buildMailReceivers
(
ProductLine
productLine
);
public
abstract
List
<
String
>
buildMailReceivers
(
Project
project
);
public
String
buildMailTitle
(
ProductLine
productLine
,
MetricItemConfig
config
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -38,7 +47,12 @@ public abstract class BaseAlertConfig {
return
sb
.
toString
();
}
protected
Pair
<
Boolean
,
String
>
checkDataByConfig
(
double
[]
value
,
double
[]
baseline
,
MetricType
type
,
Config
con
)
{
public
abstract
List
<
String
>
buildSMSReceivers
(
ProductLine
productLine
);
public
abstract
Pair
<
Boolean
,
String
>
checkData
(
double
[]
value
,
double
[]
baseline
,
MetricType
type
,
List
<
Config
>
configs
);
protected
Pair
<
Boolean
,
String
>
checkDataByCondition
(
double
[]
value
,
double
[]
baseline
,
Condition
condition
)
{
int
length
=
value
.
length
;
StringBuilder
baselines
=
new
StringBuilder
();
StringBuilder
values
=
new
StringBuilder
();
...
...
@@ -53,14 +67,13 @@ public abstract class BaseAlertConfig {
if
(
baseline
[
i
]
<=
0
)
{
baseline
[
i
]
=
100
;
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
if
(
type
==
MetricType
.
COUNT
||
type
==
MetricType
.
SUM
)
{
if
(!
judgeByRule
(
con
,
value
[
i
],
baseline
[
i
],
i
,
length
))
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
if
(!
checkDataByMinute
(
condition
,
value
[
i
],
baseline
[
i
]))
{
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
}
double
percent
=
(
1
-
valueSum
/
baselineSum
)
*
100
;
StringBuilder
sb
=
new
StringBuilder
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -72,69 +85,62 @@ public abstract class BaseAlertConfig {
return
new
Pair
<
Boolean
,
String
>(
true
,
sb
.
toString
());
}
protected
Long
getMillsByString
(
String
time
)
throws
Exception
{
String
[]
times
=
time
.
split
(
":"
);
int
hour
=
Integer
.
parseInt
(
times
[
0
]);
int
minute
=
Integer
.
parseInt
(
times
[
1
]);
long
result
=
hour
*
60
*
60
*
1000
+
minute
*
60
*
1000
;
return
result
;
}
private
boolean
judgeByRule
(
Config
ruleConfig
,
double
value
,
double
baseline
,
int
index
,
int
length
)
{
boolean
isRuleTriggered
=
false
;
protected
Pair
<
Boolean
,
String
>
checkDataByConfig
(
double
[]
value
,
double
[]
baseline
,
MetricType
type
,
Config
config
)
{
long
ruleStartTime
;
long
ruleEndTime
;
long
nowTime
=
(
System
.
currentTimeMillis
()
+
8
*
60
*
60
*
1000
)
%
(
24
*
60
*
60
*
1000
);
try
{
ruleStartTime
=
getMillsByString
(
ruleC
onfig
.
getStarttime
());
ruleEndTime
=
getMillsByString
(
ruleC
onfig
.
getEndtime
())
+
ONE_MINUTE_MILLSEC
;
ruleStartTime
=
getMillsByString
(
c
onfig
.
getStarttime
());
ruleEndTime
=
getMillsByString
(
c
onfig
.
getEndtime
())
+
ONE_MINUTE_MILLSEC
;
}
catch
(
Exception
ex
)
{
ruleStartTime
=
0L
;
ruleEndTime
=
86400000L
;
}
if
(
nowTime
<
ruleStartTime
||
nowTime
>
ruleEndTime
)
{
return
false
;
return
new
Pair
<
Boolean
,
String
>(
false
,
""
)
;
}
for
(
Condition
condition
:
ruleC
onfig
.
getConditions
())
{
i
f
(
isRuleTriggered
)
{
break
;
}
for
(
Condition
condition
:
c
onfig
.
getConditions
())
{
i
nt
conditionMinute
=
condition
.
getMinute
();
double
[]
valueValid
=
buildLastMinutes
(
value
,
conditionMinute
)
;
double
[]
baselineValid
=
buildLastMinutes
(
baseline
,
conditionMinute
);
int
minute
=
condition
.
getMinute
(
);
Pair
<
Boolean
,
String
>
condResult
=
checkDataByCondition
(
valueValid
,
baselineValid
,
condition
);
if
(
index
<
length
-
minut
e
)
{
continue
;
if
(
condResult
.
getKey
()
==
tru
e
)
{
return
condResult
;
}
}
boolean
isSubRuleTriggered
=
true
;
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
for
(
Subcondition
subCondition
:
condition
.
getSubconditions
())
{
if
(!
isSubRuleTriggered
)
{
break
;
}
private
boolean
checkDataByMinute
(
Condition
condition
,
double
value
,
double
baseline
)
{
for
(
Subcondition
subCondition
:
condition
.
getSubconditions
())
{
String
ruleType
=
subCondition
.
getType
();
double
ruleValue
=
Double
.
parseDouble
(
subCondition
.
getText
());
RuleType
rule
=
RuleType
.
getByTypeId
(
ruleType
);
String
ruleType
=
subCondition
.
getType
();
double
ruleValue
=
Double
.
parseDouble
(
subCondition
.
getText
());
RuleType
rule
=
RuleType
.
getByTypeId
(
ruleType
);
if
(
rule
!=
null
)
{
boolean
isSubRuleTriggered
=
rule
.
executeRule
(
value
,
baseline
,
ruleValue
);
if
(
rule
==
null
)
{
continue
;
}
else
{
isSubRuleTriggered
=
rule
.
executeRule
(
value
,
baseline
,
ruleValue
);
if
(!
isSubRuleTriggered
)
{
return
false
;
}
}
if
(
isSubRuleTriggered
)
{
isRuleTriggered
=
true
;
}
}
return
true
;
}
protected
Long
getMillsByString
(
String
time
)
throws
Exception
{
String
[]
times
=
time
.
split
(
":"
);
int
hour
=
Integer
.
parseInt
(
times
[
0
]);
int
minute
=
Integer
.
parseInt
(
times
[
1
]);
long
result
=
hour
*
60
*
60
*
1000
+
minute
*
60
*
1000
;
return
isRuleTriggered
;
return
result
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/metric/SwitchAlertConfig.java
浏览文件 @
44797278
...
...
@@ -15,7 +15,7 @@ public class SwitchAlertConfig extends BaseAlertConfig {
public
List
<
String
>
buildExceptionSMSReceivers
(
ProductLine
productLine
)
{
List
<
String
>
phones
=
new
ArrayList
<
String
>();
phones
.
add
(
"18662513308"
);
//
phones.add("18662513308");
return
phones
;
}
...
...
@@ -41,7 +41,7 @@ public class SwitchAlertConfig extends BaseAlertConfig {
List
<
String
>
phones
=
new
ArrayList
<
String
>();
// String phonesList = productLine.getPhone();
phones
.
add
(
"18662513308"
);
//
phones.add("18662513308");
// phones.addAll(Splitters.by(",").noEmptyItem().split(phonesList));
return
phones
;
}
...
...
@@ -50,8 +50,8 @@ public class SwitchAlertConfig extends BaseAlertConfig {
for
(
Config
con
:
configs
)
{
int
dataLength
=
queryMaxMinute
(
con
);
double
[]
validVal
=
get
LastMinutes
(
value
,
dataLength
);
double
[]
validBase
=
get
LastMinutes
(
baseline
,
dataLength
);
double
[]
validVal
=
build
LastMinutes
(
value
,
dataLength
);
double
[]
validBase
=
build
LastMinutes
(
baseline
,
dataLength
);
Pair
<
Boolean
,
String
>
result
=
checkDataByConfig
(
validVal
,
validBase
,
type
,
con
);
if
(
result
.
getKey
()
==
true
)
{
...
...
@@ -61,15 +61,6 @@ public class SwitchAlertConfig extends BaseAlertConfig {
return
new
Pair
<
Boolean
,
String
>(
false
,
""
);
}
private
double
[]
getLastMinutes
(
double
[]
doubleList
,
int
remainCount
)
{
double
[]
result
=
new
double
[
remainCount
];
int
startIndex
=
doubleList
.
length
-
remainCount
;
for
(
int
i
=
0
;
i
<
remainCount
;
i
++)
{
result
[
i
]
=
doubleList
[
startIndex
+
i
];
}
return
result
;
}
private
int
queryMaxMinute
(
Config
con
)
{
int
maxMinute
=
0
;
...
...
cat-home/src/main/java/com/dianping/cat/system/page/config/Model.java
浏览文件 @
44797278
package
com.dianping.cat.system.page.config
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -33,7 +34,7 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
private
PatternItem
m_patternItem
;
private
List
<
PatternItem
>
m_patternItems
;
private
Collection
<
PatternItem
>
m_patternItems
;
private
ExceptionLimit
m_exceptionLimit
;
...
...
@@ -298,11 +299,11 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
m_patternItem
=
patternItem
;
}
public
List
<
PatternItem
>
getPatternItems
()
{
public
Collection
<
PatternItem
>
getPatternItems
()
{
return
m_patternItems
;
}
public
void
setPatternItems
(
List
<
PatternItem
>
patternItems
)
{
public
void
setPatternItems
(
Collection
<
PatternItem
>
patternItems
)
{
m_patternItems
=
patternItems
;
}
...
...
cat-home/src/main/webapp/jsp/system/urlPattern/urlPatternUpdate.jsp
浏览文件 @
44797278
...
...
@@ -22,17 +22,20 @@
<tr>
<td>
唯一ID
</td>
<td><input
type=
"text"
class=
"input-xlarge"
name=
"patternItem.name"
required
value=
"${model.patternItem.name}"
/></td>
<td><span
class=
"text-red"
>
不能有特殊字符,仅限于英文字母和-
</span></td>
</tr>
<tr>
<td>
所属组
</td>
<td><input
type=
"text"
class=
"input-xlarge"
name=
"patternItem.group"
required
value=
"${model.patternItem.group}"
/></td>
<td><span
class=
"text-red"
>
暂时不起作用,仅仅用作url的分组,用于展示目的
</span></td>
</tr>
<tr>
<td>
pattern
</td>
<td><input
type=
"text"
class=
"input-xlarge"
name=
"patternItem.pattern"
required
value=
"${model.patternItem.pattern}"
/></td>
<td><span
class=
"text-red"
>
支付完全匹配方式,和部分匹配,比如 http://www.dianping.com/{City}/food,{City}可以匹配任何字符串
</span></td>
</tr>
<tr>
<td
style=
'text-align:center'
colspan=
'
2
'
><input
class=
'btn btn-primary'
type=
"submit"
name=
"submit"
value=
"submit"
/></td>
<td
style=
'text-align:center'
colspan=
'
3
'
><input
class=
'btn btn-primary'
type=
"submit"
name=
"submit"
value=
"submit"
/></td>
</tr>
</table>
</form>
</div></div></div>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录