Commit 2dfe548e authored by huangcb's avatar huangcb

增加actuator端点监控

parent eb883ef5
...@@ -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>
......
...@@ -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";
/** /**
* 默认字符编码 * 默认字符编码
**/ **/
......
...@@ -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(requestWrapper, responseWrapper); 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(RestRequestWrapper requestWrapper, RestResponseWrapper 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
...@@ -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);
......
...@@ -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);
} }
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());
}
} }
...@@ -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:
......
...@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment