Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
customer-service
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
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
customer-service
Commits
2dfe548e
Commit
2dfe548e
authored
Jun 23, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加actuator端点监控
parent
eb883ef5
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
48 additions
and
47 deletions
+48
-47
pom.xml
pom.xml
+4
-0
CommonConstants.java
...sv/freight/customer/common/constants/CommonConstants.java
+0
-11
RestLogFilter.java
...com/esv/freight/customer/common/filter/RestLogFilter.java
+4
-21
FeignUtils.java
...java/com/esv/freight/customer/common/util/FeignUtils.java
+0
-3
FeignBaseService.java
...java/com/esv/freight/customer/feign/FeignBaseService.java
+10
-0
TestController.java
...eight/customer/module/test/controller/TestController.java
+10
-12
application-dev.yml
src/main/resources/application-dev.yml
+10
-0
application-test.yml
src/main/resources/application-test.yml
+10
-0
No files found.
pom.xml
View file @
2dfe548e
...
@@ -64,6 +64,10 @@
...
@@ -64,6 +64,10 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<!--lettuce pool连接池-->
<!--lettuce pool连接池-->
<dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<groupId>
org.apache.commons
</groupId>
...
...
src/main/java/com/esv/freight/customer/common/constants/CommonConstants.java
View file @
2dfe548e
...
@@ -38,17 +38,6 @@ public class CommonConstants {
...
@@ -38,17 +38,6 @@ public class CommonConstants {
**/
**/
public
static
final
String
UNKNOWN_STRING
=
"unknown"
;
public
static
final
String
UNKNOWN_STRING
=
"unknown"
;
/**
* log日志输出的最大长度及截取输出的长度
**/
public
static
final
int
LOG_MAX_LENGTH
=
5000
;
public
static
final
int
LOG_CUT_LENGTH
=
1000
;
/**
* Spring Boot Admin监控url前缀
**/
public
static
final
String
SPRING_BOOT_ADMIN_PREFIX_URL
=
"/actuator"
;
/**
/**
* 默认字符编码
* 默认字符编码
**/
**/
...
...
src/main/java/com/esv/freight/customer/common/filter/RestLogFilter.java
View file @
2dfe548e
...
@@ -50,7 +50,7 @@ public class RestLogFilter implements Filter {
...
@@ -50,7 +50,7 @@ public class RestLogFilter implements Filter {
filterChain
.
doFilter
(
requestWrapper
,
responseWrapper
);
filterChain
.
doFilter
(
requestWrapper
,
responseWrapper
);
// 日志输出返回体
// 日志输出返回体
this
.
logRes
(
re
questWrapper
,
re
sponseWrapper
);
this
.
logRes
(
responseWrapper
);
}
}
/**
/**
...
@@ -74,18 +74,9 @@ public class RestLogFilter implements Filter {
...
@@ -74,18 +74,9 @@ public class RestLogFilter implements Filter {
reqBody
=
ReqUtils
.
getPostBody
(
requestWrapper
);
reqBody
=
ReqUtils
.
getPostBody
(
requestWrapper
);
}
}
// 请求体日志截取
if
(
CommonConstants
.
LOG_MAX_LENGTH
<
reqBody
.
length
())
{
reqBody
=
reqBody
.
substring
(
0
,
CommonConstants
.
LOG_CUT_LENGTH
)
+
"……"
;
}
// 日志输出请求体
// 日志输出请求体
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
log
.
debug
(
"[IP={}]收到{}请求,url:{},params:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
}
else
{
log
.
info
(
"[IP={}]收到{}请求,url:{},body:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
log
.
info
(
"[IP={}]收到{}请求,url:{},body:{}"
,
ReqUtils
.
getHttpClientIp
(
requestWrapper
),
method
,
url
,
reqBody
);
}
}
}
/**
/**
* 日志输出请求头
* 日志输出请求头
...
@@ -103,7 +94,7 @@ public class RestLogFilter implements Filter {
...
@@ -103,7 +94,7 @@ public class RestLogFilter implements Filter {
/**
/**
* 日志输出返回体
* 日志输出返回体
**/
**/
private
void
logRes
(
RestRe
questWrapper
requestWrapper
,
RestRe
sponseWrapper
responseWrapper
)
{
private
void
logRes
(
RestResponseWrapper
responseWrapper
)
{
byte
[]
bytes
=
responseWrapper
.
getBody
();
byte
[]
bytes
=
responseWrapper
.
getBody
();
String
resBody
=
null
;
String
resBody
=
null
;
try
{
try
{
...
@@ -111,14 +102,6 @@ public class RestLogFilter implements Filter {
...
@@ -111,14 +102,6 @@ public class RestLogFilter implements Filter {
}
catch
(
UnsupportedEncodingException
e
)
{
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
String
url
=
requestWrapper
.
getRequestURI
();
if
(
CommonConstants
.
LOG_MAX_LENGTH
<
resBody
.
length
())
{
resBody
=
resBody
.
substring
(
0
,
CommonConstants
.
LOG_CUT_LENGTH
)
+
"……"
;
}
if
(
url
.
startsWith
(
CommonConstants
.
SPRING_BOOT_ADMIN_PREFIX_URL
))
{
log
.
debug
(
"请求响应:{}"
,
resBody
);
}
else
{
log
.
info
(
"请求响应:{}"
,
resBody
);
log
.
info
(
"请求响应:{}"
,
resBody
);
}
}
}
}
}
\ No newline at end of file
src/main/java/com/esv/freight/customer/common/util/FeignUtils.java
View file @
2dfe548e
...
@@ -26,9 +26,6 @@ public class FeignUtils {
...
@@ -26,9 +26,6 @@ public class FeignUtils {
**/
**/
public
static
JSONObject
getFeignResultData
(
JSONObject
resultJson
)
throws
EException
{
public
static
JSONObject
getFeignResultData
(
JSONObject
resultJson
)
throws
EException
{
String
result
=
resultJson
.
toJSONString
();
String
result
=
resultJson
.
toJSONString
();
if
(
CommonConstants
.
LOG_MAX_LENGTH
<
result
.
length
())
{
result
=
result
.
substring
(
0
,
CommonConstants
.
LOG_CUT_LENGTH
)
+
"……"
;
}
log
.
info
(
result
);
log
.
info
(
result
);
if
(
CommonConstants
.
FEIGN_RESULT_SUCCESS
==
resultJson
.
getIntValue
(
CommonConstants
.
FEIGN_RESULT_CODE
))
{
if
(
CommonConstants
.
FEIGN_RESULT_SUCCESS
==
resultJson
.
getIntValue
(
CommonConstants
.
FEIGN_RESULT_CODE
))
{
return
resultJson
.
getJSONObject
(
CommonConstants
.
FEIGN_RESULT_DATA
);
return
resultJson
.
getJSONObject
(
CommonConstants
.
FEIGN_RESULT_DATA
);
...
...
src/main/java/com/esv/freight/customer/feign/FeignBaseService.java
View file @
2dfe548e
...
@@ -47,4 +47,14 @@ public interface FeignBaseService {
...
@@ -47,4 +47,14 @@ public interface FeignBaseService {
@PostMapping
(
value
=
"/base/geo/city/getAllRegionMap"
)
@PostMapping
(
value
=
"/base/geo/city/getAllRegionMap"
)
JSONObject
getAllRegionMap
(
JSONObject
bodyJson
);
JSONObject
getAllRegionMap
(
JSONObject
bodyJson
);
/**
* description 获取图片验证码
* param [bodyJson]
* return com.alibaba.fastjson.JSONObject
* author HuangChaobin
* createTime 2020/06/19 13:10
**/
@PostMapping
(
value
=
"/base/captcha/get"
)
JSONObject
getDefaultCaptcha
(
JSONObject
bodyJson
);
}
}
src/main/java/com/esv/freight/customer/module/test/controller/TestController.java
View file @
2dfe548e
package
com
.
esv
.
freight
.
customer
.
module
.
test
.
controller
;
package
com
.
esv
.
freight
.
customer
.
module
.
test
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.esv.freight.customer.common.response.EResponse
;
import
com.esv.freight.customer.common.response.EResponse
;
import
com.esv.freight.customer.
common.util.ThreadLocalCacheUtils
;
import
com.esv.freight.customer.
feign.FeignBaseService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -21,22 +23,18 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -21,22 +23,18 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Slf4j
public
class
TestController
{
public
class
TestController
{
@Autowired
private
FeignBaseService
feignBaseService
;
@GetMapping
(
"/ping"
)
@GetMapping
(
"/ping"
)
public
EResponse
ping
()
{
public
EResponse
ping
()
{
return
EResponse
.
ok
();
return
EResponse
.
ok
();
}
}
@GetMapping
(
"/test1"
)
@GetMapping
(
"/getDefaultCaptcha"
)
public
EResponse
test1
()
{
public
EResponse
getDefaultCaptcha
()
{
ThreadLocalCacheUtils
.
setByKey
(
"thread"
,
"test1"
);
JSONObject
result
=
feignBaseService
.
getDefaultCaptcha
(
new
JSONObject
());
log
.
info
(
ThreadLocalCacheUtils
.
getByKey
(
"thread"
).
toString
());
return
EResponse
.
ok
(
result
);
return
EResponse
.
ok
(
ThreadLocalCacheUtils
.
getByKey
(
"thread"
).
toString
());
}
}
@GetMapping
(
"/test2"
)
public
EResponse
test2
()
{
ThreadLocalCacheUtils
.
setByKey
(
"thread"
,
"test2"
);
log
.
info
(
ThreadLocalCacheUtils
.
getByKey
(
"thread"
).
toString
());
return
EResponse
.
ok
(
ThreadLocalCacheUtils
.
getByKey
(
"thread"
).
toString
());
}
}
}
src/main/resources/application-dev.yml
View file @
2dfe548e
...
@@ -53,6 +53,16 @@ mybatis-plus:
...
@@ -53,6 +53,16 @@ mybatis-plus:
id-type
:
AUTO
id-type
:
AUTO
logic-delete-value
:
1
logic-delete-value
:
1
logic-not-delete-value
:
0
logic-not-delete-value
:
0
management
:
endpoints
:
web
:
exposure
:
# "*"开放所有监控端点,指定监控端点,用逗号分隔
include
:
health
base-path
:
/esvActuator
endpoint
:
health
:
show-details
:
always
hystrix
:
hystrix
:
command
:
command
:
default
:
default
:
...
...
src/main/resources/application-test.yml
View file @
2dfe548e
...
@@ -53,6 +53,16 @@ mybatis-plus:
...
@@ -53,6 +53,16 @@ mybatis-plus:
id-type
:
AUTO
id-type
:
AUTO
logic-delete-value
:
1
logic-delete-value
:
1
logic-not-delete-value
:
0
logic-not-delete-value
:
0
management
:
endpoints
:
web
:
exposure
:
# "*"开放所有监控端点,指定监控端点,用逗号分隔
include
:
health
base-path
:
/esvActuator
endpoint
:
health
:
show-details
:
always
hystrix
:
hystrix
:
command
:
command
:
default
:
default
:
...
...
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