Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
2cb56a53
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,发现更多精彩内容 >>
提交
2cb56a53
编写于
6月 17, 2014
作者:
J
jialinsun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码风格完善
上级
8892ebf2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
306 deletion
+39
-306
cat-agent/src/main/java/com/dianping/cat/agent/monitor/puppet/Alteration.java
...ava/com/dianping/cat/agent/monitor/puppet/Alteration.java
+39
-45
cat-agent/src/test/java/com/dianping/cat/agent/puppet/HttpPostUtils.java
...est/java/com/dianping/cat/agent/puppet/HttpPostUtils.java
+0
-84
cat-agent/src/test/java/com/dianping/cat/agent/puppet/PuppetMonitorByLineNo.java
.../com/dianping/cat/agent/puppet/PuppetMonitorByLineNo.java
+0
-152
cat-agent/src/test/java/com/dianping/cat/agent/puppet/Test.java
...ent/src/test/java/com/dianping/cat/agent/puppet/Test.java
+0
-25
未找到文件。
cat-agent/src/main/java/com/dianping/cat/agent/monitor/puppet/Alteration.java
浏览文件 @
2cb56a53
package
com.dianping.cat.agent.monitor.puppet
;
public
class
Alteration
{
@Override
public
String
toString
()
{
return
"Alteration [type="
+
type
+
", ip="
+
ip
+
", hostname="
+
hostname
+
", user="
+
user
+
", url="
+
url
+
", op="
+
op
+
", date="
+
date
+
", title="
+
title
+
", content="
+
content
+
", domain="
+
domain
+
", group="
+
group
+
"]"
;
}
private
String
type
;
private
String
m_
type
;
private
String
ip
;
private
String
m_
ip
;
private
String
hostname
;
private
String
m_
hostname
;
private
String
user
;
private
String
m_
user
;
private
String
url
;
private
String
m_
url
;
private
String
op
;
private
String
m_
op
;
private
String
date
;
private
String
m_
date
;
private
String
title
;
private
String
m_
title
;
private
String
content
;
private
String
m_
content
;
private
String
domain
;
private
String
m_
domain
;
private
String
group
;
private
String
m_
group
;
public
String
getType
()
{
return
type
;
return
m_
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
m_
type
=
type
;
}
public
String
getIp
()
{
return
ip
;
return
m_
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
m_ip
=
ip
;
}
public
String
getHostname
()
{
return
m_hostname
;
}
public
void
setHostname
(
String
hostname
)
{
m_hostname
=
hostname
;
}
public
String
getUser
()
{
return
user
;
return
m_
user
;
}
public
void
setUser
(
String
user
)
{
this
.
user
=
user
;
m_
user
=
user
;
}
public
String
getUrl
()
{
return
url
;
return
m_
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
m_
url
=
url
;
}
public
String
getOp
()
{
return
op
;
return
m_
op
;
}
public
void
setOp
(
String
op
)
{
this
.
op
=
op
;
m_
op
=
op
;
}
public
String
getDate
()
{
return
date
;
return
m_
date
;
}
public
void
setDate
(
String
date
)
{
this
.
date
=
date
;
m_
date
=
date
;
}
public
String
getTitle
()
{
return
title
;
return
m_
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
m_
title
=
title
;
}
public
String
getContent
()
{
return
content
;
return
m_
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
m_
content
=
content
;
}
public
String
getDomain
()
{
return
domain
;
return
m_
domain
;
}
public
void
setDomain
(
String
domain
)
{
this
.
domain
=
domain
;
}
public
String
getHostname
()
{
return
hostname
;
}
public
void
setHostname
(
String
hostname
)
{
this
.
hostname
=
hostname
;
m_domain
=
domain
;
}
public
String
getGroup
()
{
return
group
;
return
m_
group
;
}
public
void
setGroup
(
String
group
)
{
this
.
group
=
group
;
m_
group
=
group
;
}
}
cat-agent/src/test/java/com/dianping/cat/agent/puppet/HttpPostUtils.java
已删除
100644 → 0
浏览文件 @
8892ebf2
package
com.dianping.cat.agent.puppet
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
HttpPostUtils
{
public
static
String
httpPost
(
String
urlAddress
,
Map
<
String
,
String
>
paramMap
){
if
(
paramMap
==
null
){
paramMap
=
new
HashMap
<
String
,
String
>();
}
String
[]
params
=
new
String
[
paramMap
.
size
()];
int
i
=
0
;
for
(
String
paramKey:
paramMap
.
keySet
()){
String
param
=
paramKey
+
"="
+
paramMap
.
get
(
paramMap
);
params
[
i
]
=
param
;
i
++;
}
return
httpPost
(
urlAddress
,
params
);
}
public
static
String
httpPost
(
String
urlAddress
,
List
<
String
>
paramList
){
if
(
paramList
==
null
){
paramList
=
new
ArrayList
<
String
>();
}
return
httpPost
(
urlAddress
,
paramList
.
toArray
(
new
String
[
0
]));
}
public
static
String
httpPost
(
String
urlAddress
,
String
[]
params
){
URL
url
=
null
;
HttpURLConnection
con
=
null
;
BufferedReader
in
=
null
;
StringBuffer
result
=
new
StringBuffer
();
try
{
url
=
new
URL
(
urlAddress
);
con
=
(
HttpURLConnection
)
url
.
openConnection
();
con
.
setUseCaches
(
false
);
con
.
setDoOutput
(
true
);
con
.
setRequestMethod
(
"POST"
);
String
paramsTemp
=
""
;
for
(
String
param:
params
){
if
(
param
!=
null
&&!
""
.
equals
(
param
.
trim
())){
paramsTemp
+=
"&"
+
param
;
}
}
byte
[]
b
=
paramsTemp
.
getBytes
();
con
.
getOutputStream
().
write
(
b
,
0
,
b
.
length
);
con
.
getOutputStream
().
flush
();
con
.
getOutputStream
().
close
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()));
while
(
true
)
{
String
line
=
in
.
readLine
();
if
(
line
==
null
)
{
break
;
}
else
{
result
.
append
(
line
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
in
!=
null
){
in
.
close
();
}
if
(
con
!=
null
){
con
.
disconnect
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
result
.
toString
();
}
}
cat-agent/src/test/java/com/dianping/cat/agent/puppet/PuppetMonitorByLineNo.java
已删除
100644 → 0
浏览文件 @
8892ebf2
package
com.dianping.cat.agent.puppet
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.BufferedInputStream
;
import
java.io.FileInputStream
;
import
java.util.regex.*
;
public
class
PuppetMonitorByLineNo
{
public
static
void
main
(
String
[]
args
)
{
String
log_file
=
"/var/log/messages"
;
String
line_file
=
"/var/log/currentPointer"
;
File
line_f
=
new
File
(
line_file
);
while
(
true
)
{
int
line_no_start
=
get_startline_no
(
line_file
,
log_file
);
int
line_reading_count
=
0
;
String
regEx
=
".*puppet-agent.*\\(\\/Stage"
;
System
.
out
.
println
(
"line_no_start="
+
Integer
.
toString
(
line_no_start
));
try
{
FileReader
reader
=
new
FileReader
(
log_file
);
BufferedReader
br
=
new
BufferedReader
(
reader
);
String
str
=
null
;
while
((
str
=
br
.
readLine
())
!=
null
)
{
line_reading_count
++;
if
(
line_reading_count
<
line_no_start
)
{
continue
;
}
else
{
Pattern
pattern1
=
Pattern
.
compile
(
".*?\\[(.*?)\\].*?"
);
if
(
Pattern
.
compile
(
regEx
).
matcher
(
str
).
find
())
{
// System.out.println(str+"/n");
String
[]
tmp_list
=
str
.
split
(
" "
);
String
action_time
=
tmp_list
[
0
]
+
tmp_list
[
1
]
+
" "
+
tmp_list
[
2
]
+
" "
+
tmp_list
[
3
];
String
hostname
=
tmp_list
[
4
];
String
change
=
str
.
split
(
"\\("
)[
1
];
String
file
=
change
.
split
(
"\\)"
)[
0
].
split
(
"Stage\\[main\\]"
)[
1
];
Matcher
matcher1
=
pattern1
.
matcher
(
file
);
if
(
matcher1
.
matches
())
{
System
.
out
.
println
(
matcher1
.
group
(
1
));
}
System
.
out
.
println
(
action_time
+
" "
+
hostname
+
" "
+
change
+
"/n"
);
}
}
}
br
.
close
();
reader
.
close
();
System
.
out
.
println
(
"本次读取到文件行数:"
+
line_reading_count
);
// 将上次读取的行,写入文件
BufferedWriter
output
=
new
BufferedWriter
(
new
FileWriter
(
line_f
));
output
.
write
(
Integer
.
toString
(
line_reading_count
));
output
.
close
();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// slee 5s
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
*
* @param line_file
* 记录上次读取文件的行数
* @param log_file
* 读取文件,用于分析内容,此处用来统计文件总行数
* @return 返回上次读取的文件的行数
*/
public
static
int
get_startline_no
(
String
line_file
,
String
log_file
)
{
int
line_no_start
=
0
;
String
str
=
""
;
try
{
FileReader
line_reader
=
new
FileReader
(
line_file
);
BufferedReader
line_br
=
new
BufferedReader
(
line_reader
);
try
{
if
((
str
=
line_br
.
readLine
())
!=
null
)
{
line_no_start
=
Integer
.
parseInt
(
str
);
line_br
.
close
();
line_reader
.
close
();
}
else
{
// file is empty
line_no_start
=
countFileLine
(
log_file
)
/
2
;
}
}
catch
(
NumberFormatException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
FileNotFoundException
e
)
{
line_no_start
=
countFileLine
(
log_file
)
/
2
;
File
f
=
new
File
(
line_file
);
try
{
if
(
f
.
createNewFile
())
{
BufferedWriter
output
=
new
BufferedWriter
(
new
FileWriter
(
f
));
output
.
write
(
Integer
.
toString
(
line_no_start
)
+
"\n"
);
output
.
close
();
}
else
{
System
.
out
.
println
(
"fail to create file : "
+
line_file
);
}
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
System
.
out
.
println
(
"上次读取的文件行数"
+
Integer
.
toString
(
line_no_start
));
return
line_no_start
;
}
/**
*
* @param file
* 文件
* @return 文件的总行数
*/
public
static
int
countFileLine
(
String
file
)
{
int
count
=
0
;
try
{
InputStream
is
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
byte
[]
c
=
new
byte
[
65536
];
int
readChars
=
0
;
while
((
readChars
=
is
.
read
(
c
))
!=
-
1
)
{
for
(
int
i
=
0
;
i
<
readChars
;
++
i
)
{
if
(
c
[
i
]
==
'\n'
)
++
count
;
}
}
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"文件总行数"
+
Integer
.
toString
(
count
));
return
count
;
}
}
cat-agent/src/test/java/com/dianping/cat/agent/puppet/Test.java
已删除
100644 → 0
浏览文件 @
8892ebf2
package
com.dianping.cat.agent.puppet
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.RandomAccessFile
;
public
class
Test
{
public
static
void
main
(
String
args
[]){
String
m_logFile
=
"/var/log/messages"
;
RandomAccessFile
reader
=
null
;
try
{
reader
=
new
RandomAccessFile
(
m_logFile
,
"r"
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
try
{
System
.
out
.
println
(
reader
.
length
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录