Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
java-devop-sentry
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhouzihao
java-devop-sentry
Commits
0decc262
Commit
0decc262
authored
Mar 17, 2020
by
zhouzihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev-添加数据收集器
parent
f75cf751
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
146 additions
and
5 deletions
+146
-5
src/main/java/com/vandyo/sentry/core/Tmp.java
src/main/java/com/vandyo/sentry/core/Tmp.java
+20
-4
src/main/java/com/vandyo/sentry/core/cases/CarInfoDecorator.java
...n/java/com/vandyo/sentry/core/cases/CarInfoDecorator.java
+2
-0
src/main/java/com/vandyo/sentry/core/cases/CarListDecorator.java
...n/java/com/vandyo/sentry/core/cases/CarListDecorator.java
+4
-1
src/main/java/com/vandyo/sentry/core/cases/CarStatusDecorator.java
...java/com/vandyo/sentry/core/cases/CarStatusDecorator.java
+2
-0
src/main/java/com/vandyo/sentry/core/cases/EmptyCase.java
src/main/java/com/vandyo/sentry/core/cases/EmptyCase.java
+2
-0
src/main/java/com/vandyo/sentry/core/cases/LoginCase.java
src/main/java/com/vandyo/sentry/core/cases/LoginCase.java
+2
-0
src/main/java/com/vandyo/sentry/core/cases/TestCase.java
src/main/java/com/vandyo/sentry/core/cases/TestCase.java
+21
-0
src/main/java/com/vandyo/sentry/core/collectionMachine/CollectionMachine.java
...ndyo/sentry/core/collectionMachine/CollectionMachine.java
+93
-0
No files found.
src/main/java/com/vandyo/sentry/core/Tmp.java
View file @
0decc262
package
com
.
vandyo
.
sentry
.
core
;
package
com
.
vandyo
.
sentry
.
core
;
import
cn.hutool.json.JSONUtil
;
import
com.vandyo.sentry.core.cases.*
;
import
com.vandyo.sentry.core.cases.*
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
@Component
@Component
public
class
Tmp
{
public
class
Tmp
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
Tmp
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
Tmp
.
class
);
...
@@ -21,16 +26,27 @@ public class Tmp {
...
@@ -21,16 +26,27 @@ public class Tmp {
@Value
(
"${vandyo.pwd}"
)
@Value
(
"${vandyo.pwd}"
)
public
String
pwd
;
public
String
pwd
;
@Scheduled
(
fixedRate
=
5
000
)
@Scheduled
(
fixedRate
=
1
000
)
public
void
test
(){
public
void
test
()
{
log
.
info
(
"we run it {} times"
,++
times
);
log
.
info
(
"we run it {} times"
,
++
times
);
Case
case1
=
null
;
Case
case1
=
null
;
case1
=
new
LoginCase
(
mobile
,
pwd
);
case1
=
new
LoginCase
(
mobile
,
pwd
);
case1
=
new
CarListDecorator
(
case1
);
case1
=
new
CarListDecorator
(
case1
);
case1
=
new
CarInfoDecorator
(
case1
);
case1
=
new
CarInfoDecorator
(
case1
);
case1
=
new
CarDetectDecorator
(
case1
);
case1
=
new
CarDetectDecorator
(
case1
);
case1
=
new
CarStatusDecorator
(
case1
);
case1
=
new
CarStatusDecorator
(
case1
);
case1
.
check
();
case1
.
check
();
Case
case2
=
null
;
case2
=
new
TestCase
();
case2
.
check
();
log
.
info
(
"over!"
);
}
@Scheduled
(
fixedRate
=
5000
)
public
void
check
()
{
Map
<
String
,
Map
<
ErrStatus
,
Long
>>
data
=
CollectionMachine
.
checkRule
(
5
);
String
info
=
JSONUtil
.
parseFromMap
(
data
).
toStringPretty
();
log
.
warn
(
info
);
}
}
}
}
src/main/java/com/vandyo/sentry/core/cases/CarInfoDecorator.java
View file @
0decc262
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.tools.Signature
;
import
com.vandyo.sentry.core.tools.Signature
;
...
@@ -56,6 +57,7 @@ public class CarInfoDecorator extends CaseDecorator {
...
@@ -56,6 +57,7 @@ public class CarInfoDecorator extends CaseDecorator {
newRes
.
setSuccess
(
false
);
newRes
.
setSuccess
(
false
);
}
}
}
}
CollectionMachine
.
post
(
newRes
);
return
newRes
;
return
newRes
;
}
else
{
}
else
{
return
oldRes
;
return
oldRes
;
...
...
src/main/java/com/vandyo/sentry/core/cases/CarListDecorator.java
View file @
0decc262
...
@@ -5,12 +5,14 @@ import cn.hutool.http.HttpResponse;
...
@@ -5,12 +5,14 @@ import cn.hutool.http.HttpResponse;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.tools.Signature
;
import
com.vandyo.sentry.core.tools.Signature
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
public
class
CarListDecorator
extends
CaseDecorator
{
public
class
CarListDecorator
extends
CaseDecorator
{
...
@@ -36,7 +38,7 @@ public class CarListDecorator extends CaseDecorator {
...
@@ -36,7 +38,7 @@ public class CarListDecorator extends CaseDecorator {
if
(
response
.
isOk
()){
if
(
response
.
isOk
()){
JSONObject
json
=
JSONUtil
.
parseObj
(
response
.
body
());
JSONObject
json
=
JSONUtil
.
parseObj
(
response
.
body
());
JSONArray
list
=
json
.
getJSONArray
(
"result"
);
JSONArray
list
=
json
.
getJSONArray
(
"result"
);
if
(
list
.
size
()
<
1
){
if
(
Objects
.
isNull
(
list
)
||
list
.
size
()
<
1
){
newRes
.
setSuccess
(
false
);
newRes
.
setSuccess
(
false
);
newRes
.
setStatus
(
ErrStatus
.
ErrUnexpected
);
newRes
.
setStatus
(
ErrStatus
.
ErrUnexpected
);
}
else
{
}
else
{
...
@@ -50,6 +52,7 @@ public class CarListDecorator extends CaseDecorator {
...
@@ -50,6 +52,7 @@ public class CarListDecorator extends CaseDecorator {
newRes
.
setStatus
(
Signature
.
matchStatus
(
response
.
getStatus
()));
newRes
.
setStatus
(
Signature
.
matchStatus
(
response
.
getStatus
()));
newRes
.
setSuccess
(
false
);
newRes
.
setSuccess
(
false
);
}
}
CollectionMachine
.
post
(
newRes
);
return
newRes
;
return
newRes
;
}
else
{
}
else
{
return
oldRes
;
return
oldRes
;
...
...
src/main/java/com/vandyo/sentry/core/cases/CarStatusDecorator.java
View file @
0decc262
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.tools.Signature
;
import
com.vandyo.sentry.core.tools.Signature
;
...
@@ -57,6 +58,7 @@ public class CarStatusDecorator extends CaseDecorator{
...
@@ -57,6 +58,7 @@ public class CarStatusDecorator extends CaseDecorator{
newRes
.
setSuccess
(
false
);
newRes
.
setSuccess
(
false
);
}
}
}
}
CollectionMachine
.
post
(
newRes
);
return
newRes
;
return
newRes
;
}
else
{
}
else
{
return
oldRes
;
return
oldRes
;
...
...
src/main/java/com/vandyo/sentry/core/cases/EmptyCase.java
View file @
0decc262
package
com
.
vandyo
.
sentry
.
core
.
cases
;
package
com
.
vandyo
.
sentry
.
core
.
cases
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.dto.Res
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -23,6 +24,7 @@ public class EmptyCase extends Case {
...
@@ -23,6 +24,7 @@ public class EmptyCase extends Case {
res
.
setSId
(
sId
);
res
.
setSId
(
sId
);
res
.
setUId
(
uid
);
res
.
setUId
(
uid
);
res
.
setSuccess
(
true
);
res
.
setSuccess
(
true
);
CollectionMachine
.
post
(
res
);
return
res
;
return
res
;
}
}
}
}
src/main/java/com/vandyo/sentry/core/cases/LoginCase.java
View file @
0decc262
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
...
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.dto.Res
;
import
com.vandyo.sentry.core.tools.Signature
;
import
com.vandyo.sentry.core.tools.Signature
;
...
@@ -44,6 +45,7 @@ public class LoginCase extends Case {
...
@@ -44,6 +45,7 @@ public class LoginCase extends Case {
res
.
setSuccess
(
false
);
res
.
setSuccess
(
false
);
res
.
setStatus
(
Signature
.
matchStatus
(
response
.
getStatus
()));
res
.
setStatus
(
Signature
.
matchStatus
(
response
.
getStatus
()));
}
}
CollectionMachine
.
post
(
res
);
return
res
;
return
res
;
}
}
}
}
src/main/java/com/vandyo/sentry/core/cases/TestCase.java
0 → 100644
View file @
0decc262
package
com
.
vandyo
.
sentry
.
core
.
cases
;
import
com.vandyo.sentry.core.collectionMachine.CollectionMachine
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.Res
;
import
java.util.Map
;
public
class
TestCase
extends
Case
{
@Override
public
Res
<
Map
<
String
,
String
>>
check
()
{
Res
<
Map
<
String
,
String
>>
res
=
new
Res
<>();
res
.
setSuccess
(
false
);
res
.
setStatus
(
ErrStatus
.
ErrUnexpected
);
res
.
setKey
(
"test"
);
CollectionMachine
.
post
(
res
);
return
res
;
}
}
src/main/java/com/vandyo/sentry/core/collectionMachine/CollectionMachine.java
0 → 100644
View file @
0decc262
package
com
.
vandyo
.
sentry
.
core
.
collectionMachine
;
import
com.vandyo.sentry.core.Tmp
;
import
com.vandyo.sentry.core.dto.ErrStatus
;
import
com.vandyo.sentry.core.dto.Res
;
import
lombok.Data
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.stream.Collectors
;
@Component
public
class
CollectionMachine
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Tmp
.
class
);
// 收集进来的数据 进到存储 相当于一个临时的日志
private
static
Map
<
Long
,
Res
>
temp
=
new
ConcurrentHashMap
<>(
124
);
public
static
void
post
(
Res
<
Map
<
String
,
String
>>
log
)
{
// 应该对于不同的请求统一管理 还是 每个单独管理呢?
logger
.
info
(
"temp long is {}"
,
temp
.
size
());
if
(
log
.
getIgnore
()
||
log
.
getSuccess
())
{
//pass
}
else
{
if
(
temp
.
size
()
>
100
)
{
logger
.
info
(
"try to put data"
);
checkSize
(
1
);
}
try
{
temp
.
put
(
System
.
currentTimeMillis
(),
log
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getLocalizedMessage
());
}
}
if
(
temp
.
size
()
==
100
)
{
System
.
out
.
println
(
"Warning!"
);
}
}
/**
* 对数据进行归纳
*
* @param min 分钟
* @return
*/
public
static
Map
<
String
,
Map
<
ErrStatus
,
Long
>>
checkRule
(
int
min
)
{
@Data
class
ErrBox
{
private
ErrStatus
errStatus
;
private
Integer
count
;
}
Map
<
String
,
List
<
ErrBox
>>
map
=
temp
.
keySet
().
stream
()
.
filter
(
x
->
x
>
System
.
currentTimeMillis
()
-
1000
*
60
*
min
)
.
map
(
x
->
temp
.
get
(
x
))
.
collect
(
Collectors
.
toMap
(
Res:
:
getKey
,
x
->
{
List
<
ErrBox
>
res
=
new
ArrayList
<>();
ErrBox
box
=
new
ErrBox
();
box
.
setCount
(
1
);
box
.
setErrStatus
(
x
.
getStatus
());
res
.
add
(
box
);
return
res
;
},
(
errStatus
,
errStatus2
)
->
{
errStatus
.
addAll
(
errStatus2
);
return
errStatus
;
}));
Map
<
String
,
Map
<
ErrStatus
,
Long
>>
data
=
new
HashMap
<>();
for
(
Map
.
Entry
<
String
,
List
<
ErrBox
>>
entry
:
map
.
entrySet
())
{
data
.
put
(
entry
.
getKey
(),
entry
.
getValue
().
stream
().
collect
(
Collectors
.
groupingBy
(
ErrBox:
:
getErrStatus
,
Collectors
.
counting
())));
}
logger
.
info
(
"Get All Err Over!"
);
return
data
;
}
public
static
void
checkSize
(
int
min
)
{
// 对于超过了时间限制的数据进行删除
Iterator
<
Long
>
iterator
=
temp
.
keySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
Long
key
=
iterator
.
next
();
if
(
key
<
System
.
currentTimeMillis
()
-
1000
*
60
*
min
)
{
logger
.
error
(
"remove key {}"
,
key
);
iterator
.
remove
();
temp
.
remove
(
key
);
}
else
{
return
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment