Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
134686fd
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,发现更多精彩内容 >>
提交
134686fd
编写于
4月 27, 2015
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'broker' of code.dianpingoa.com:arch/cat into broker
上级
e42e7784
bc043bab
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
103 addition
and
11 deletion
+103
-11
cat-broker/src/main/java/com/dianping/cat/broker/api/log/AppLogManager.java
...n/java/com/dianping/cat/broker/api/log/AppLogManager.java
+90
-2
cat-broker/src/main/java/com/dianping/cat/broker/api/log/ErrorLogManager.java
...java/com/dianping/cat/broker/api/log/ErrorLogManager.java
+11
-7
cat-broker/src/main/java/com/dianping/cat/broker/api/page/batch/Handler.java
.../java/com/dianping/cat/broker/api/page/batch/Handler.java
+2
-2
未找到文件。
cat-broker/src/main/java/com/dianping/cat/broker/api/log/AppLogManager.java
浏览文件 @
134686fd
package
com.dianping.cat.broker.api.log
;
package
com.dianping.cat.broker.api.log
;
import
java.io.File
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
...
@@ -13,7 +15,10 @@ import org.unidal.helper.Threads;
...
@@ -13,7 +15,10 @@ import org.unidal.helper.Threads;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.helper.Threads.Task
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.Constants
;
import
com.dianping.cat.broker.api.app.proto.AppDataProto
;
import
com.dianping.cat.broker.api.app.proto.AppDataProto
;
import
com.dianping.cat.helper.TimeHelper
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.data.warehouse.IMarinLog
;
import
com.dianping.data.warehouse.IMarinLog
;
import
com.dianping.data.warehouse.LogTypeEnum
;
import
com.dianping.data.warehouse.LogTypeEnum
;
import
com.dianping.data.warehouse.MarinLog
;
import
com.dianping.data.warehouse.MarinLog
;
...
@@ -26,15 +31,18 @@ public class AppLogManager implements Initializable {
...
@@ -26,15 +31,18 @@ public class AppLogManager implements Initializable {
private
MarinPrinter
m_marinPrinter
;
private
MarinPrinter
m_marinPrinter
;
private
final
static
String
FILE_NAME_PREFIX
=
Constants
.
APP
;
@Override
@Override
public
void
initialize
()
throws
InitializationException
{
public
void
initialize
()
throws
InitializationException
{
m_marinPrinter
=
new
MarinPrinter
();
m_marinPrinter
=
new
MarinPrinter
();
m_marinPrinter
.
setFileName
(
"app"
);
m_marinPrinter
.
setFileName
(
FILE_NAME_PREFIX
);
m_marinPrinter
.
setBusiness
(
"broker-service"
);
m_marinPrinter
.
setBusiness
(
Constants
.
BROKER_SERVICE
);
m_marinPrinter
.
setType
(
LogTypeEnum
.
FILE
);
m_marinPrinter
.
setType
(
LogTypeEnum
.
FILE
);
m_marinPrinter
.
init
();
m_marinPrinter
.
init
();
Threads
.
forGroup
(
"cat"
).
start
(
new
StoreManager
());
Threads
.
forGroup
(
"cat"
).
start
(
new
StoreManager
());
Threads
.
forGroup
(
"cat"
).
start
(
new
LogPruner
());
}
}
public
boolean
offer
(
AppDataProto
proto
)
{
public
boolean
offer
(
AppDataProto
proto
)
{
...
@@ -101,4 +109,84 @@ public class AppLogManager implements Initializable {
...
@@ -101,4 +109,84 @@ public class AppLogManager implements Initializable {
}
}
}
}
private
class
LogPruner
implements
Task
{
private
final
static
long
DURATION
=
TimeHelper
.
ONE_HOUR
;
private
final
static
String
LOG_BASE_PATH
=
"/data/applogs/broker-service/logs/"
;
private
final
static
String
FILENAME
=
FILE_NAME_PREFIX
+
".log"
;
private
SimpleDateFormat
m_sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd.HH"
);
@Override
public
String
getName
()
{
return
"app-log-pruner"
;
}
public
Date
queryPeriod
(
int
days
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
days
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
cal
.
add
(
Calendar
.
MONTH
,
0
);
return
cal
.
getTime
();
}
@Override
public
void
run
()
{
boolean
active
=
true
;
while
(
active
)
{
long
current
=
System
.
currentTimeMillis
();
Date
period
=
queryPeriod
(-
1
);
String
hourStr
=
m_sdf
.
format
(
TimeHelper
.
getCurrentHour
());
Transaction
t
=
Cat
.
newTransaction
(
"AppLogPrune"
,
hourStr
);
try
{
File
dir
=
new
File
(
LOG_BASE_PATH
);
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
try
{
String
name
=
file
.
getName
();
String
[]
fields
=
name
.
split
(
FILENAME
+
"."
);
if
(
fields
.
length
>
1
)
{
String
dateStr
=
fields
[
1
];
Date
date
=
m_sdf
.
parse
(
dateStr
);
if
(
date
.
before
(
period
))
{
file
.
delete
();
}
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
t
.
setStatus
(
Transaction
.
SUCCESS
);
}
catch
(
Exception
e
)
{
t
.
setStatus
(
e
);
}
finally
{
t
.
complete
();
}
long
duration
=
System
.
currentTimeMillis
()
-
current
;
try
{
if
(
duration
<
DURATION
)
{
Thread
.
sleep
(
DURATION
-
duration
);
}
}
catch
(
InterruptedException
e
)
{
active
=
false
;
}
}
}
@Override
public
void
shutdown
()
{
}
}
}
}
cat-broker/src/main/java/com/dianping/cat/broker/api/log/ErrorLogManager.java
浏览文件 @
134686fd
...
@@ -93,7 +93,7 @@ public class ErrorLogManager {
...
@@ -93,7 +93,7 @@ public class ErrorLogManager {
@Override
@Override
public
String
getName
()
{
public
String
getName
()
{
return
"log-pruner"
;
return
"
error-
log-pruner"
;
}
}
public
Date
queryPeriod
(
int
months
)
{
public
Date
queryPeriod
(
int
months
)
{
...
@@ -114,18 +114,22 @@ public class ErrorLogManager {
...
@@ -114,18 +114,22 @@ public class ErrorLogManager {
long
current
=
System
.
currentTimeMillis
();
long
current
=
System
.
currentTimeMillis
();
Date
period
=
queryPeriod
(-
1
);
Date
period
=
queryPeriod
(-
1
);
String
dayStr
=
m_sdf
.
format
(
TimeHelper
.
getCurrentDay
());
String
dayStr
=
m_sdf
.
format
(
TimeHelper
.
getCurrentDay
());
Transaction
t
=
Cat
.
newTransaction
(
"LogPrune"
,
dayStr
);
Transaction
t
=
Cat
.
newTransaction
(
"
Error
LogPrune"
,
dayStr
);
try
{
try
{
File
dir
=
new
File
(
LOG_BASE_PATH
);
File
dir
=
new
File
(
LOG_BASE_PATH
);
File
[]
files
=
dir
.
listFiles
();
File
[]
files
=
dir
.
listFiles
();
for
(
File
file
:
files
)
{
for
(
File
file
:
files
)
{
try
{
Date
date
=
m_sdf
.
parse
(
file
.
getName
());
Date
date
=
m_sdf
.
parse
(
file
.
getName
());
if
(
date
.
before
(
period
))
{
if
(
date
.
before
(
period
))
{
file
.
delete
();
file
.
delete
();
}
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
}
t
.
setStatus
(
Transaction
.
SUCCESS
);
t
.
setStatus
(
Transaction
.
SUCCESS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
cat-broker/src/main/java/com/dianping/cat/broker/api/page/batch/Handler.java
浏览文件 @
134686fd
...
@@ -48,7 +48,7 @@ public class Handler implements PageHandler<Context>, LogEnabled {
...
@@ -48,7 +48,7 @@ public class Handler implements PageHandler<Context>, LogEnabled {
private
UrlParser
m_parser
;
private
UrlParser
m_parser
;
@Inject
@Inject
private
AppLogManager
m_logManager
1
;
private
AppLogManager
m_logManager
;
private
Logger
m_logger
;
private
Logger
m_logger
;
...
@@ -194,7 +194,7 @@ public class Handler implements PageHandler<Context>, LogEnabled {
...
@@ -194,7 +194,7 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
}
appData
.
setCount
(
1
);
appData
.
setCount
(
1
);
boolean
success
=
m_logManager
1
.
offer
(
appData
);
boolean
success
=
m_logManager
.
offer
(
appData
);
if
(!
success
)
{
if
(!
success
)
{
m_logError
++;
m_logError
++;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录