一、trace(跟蹤)經過配置 InMemoryHttpTraceRepository 來實現,setCapacity()方法設置保留的請求數html
Configweb
package com.gcz.config; import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author guocz * @date 20210712 * 監控配置 */ @Configuration public class ActuatorConfig { @ConditionalOnMissingBean(InMemoryHttpTraceRepository.class) @Bean public InMemoryHttpTraceRepository traceRepository() { InMemoryHttpTraceRepository httpTrace = new InMemoryHttpTraceRepository(); httpTrace.setCapacity(4); return httpTrace; } }
在monitor注入bean:httptracespring
效果:cookie
{ "traces": [ { "timestamp": "2021-07-12T03:56:57.428Z", "principal": null, "session": null, "request": { "method": "GET", "uri": "http://127.0.0.1:8080/act/test", "headers": { "sec-fetch-mode": [ "navigate" ], "sec-fetch-site": [ "none" ], "cookie": [ "KERPSESSIONIDkdtest02=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I; KERPSESSIONID=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I" ], "accept-language": [ "zh-CN,zh;q=0.9" ], "upgrade-insecure-requests": [ "1" ], "host": [ "127.0.0.1:8080" ], "connection": [ "keep-alive" ], "sec-fetch-user": [ "?1" ], "cache-control": [ "max-age=0" ], "accept-encoding": [ "gzip, deflate, br" ], "sec-fetch-dest": [ "document" ], "accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], "user-agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" ] }, "remoteAddress": null }, "response": { "status": 200, "headers": { "Keep-Alive": [ "timeout=60" ], "Connection": [ "keep-alive" ], "Content-Length": [ "7" ], "Date": [ "Mon, 12 Jul 2021 03:56:57 GMT" ], "Content-Type": [ "text/html;charset=UTF-8" ] } }, "timeTaken": 2 }, { "timestamp": "2021-07-12T03:56:56.745Z", "principal": null, "session": null, "request": { "method": "GET", "uri": "http://127.0.0.1:8080/act/test", "headers": { "sec-fetch-mode": [ "navigate" ], "sec-fetch-site": [ "none" ], "cookie": [ "KERPSESSIONIDkdtest02=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I; KERPSESSIONID=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I" ], "accept-language": [ "zh-CN,zh;q=0.9" ], "upgrade-insecure-requests": [ "1" ], "host": [ "127.0.0.1:8080" ], "connection": [ "keep-alive" ], "sec-fetch-user": [ "?1" ], "cache-control": [ "max-age=0" ], "accept-encoding": [ "gzip, deflate, br" ], "sec-fetch-dest": [ "document" ], "accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], "user-agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" ] }, "remoteAddress": null }, "response": { "status": 200, "headers": { "Keep-Alive": [ "timeout=60" ], "Connection": [ "keep-alive" ], "Content-Length": [ "7" ], "Date": [ "Mon, 12 Jul 2021 03:56:55 GMT" ], "Content-Type": [ "text/html;charset=UTF-8" ] } }, "timeTaken": 6 }, { "timestamp": "2021-07-12T03:56:55.842Z", "principal": null, "session": null, "request": { "method": "GET", "uri": "http://127.0.0.1:8080/act/test", "headers": { "sec-fetch-mode": [ "navigate" ], "sec-fetch-site": [ "none" ], "cookie": [ "KERPSESSIONIDkdtest02=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I; KERPSESSIONID=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I" ], "accept-language": [ "zh-CN,zh;q=0.9" ], "upgrade-insecure-requests": [ "1" ], "host": [ "127.0.0.1:8080" ], "connection": [ "keep-alive" ], "sec-fetch-user": [ "?1" ], "cache-control": [ "max-age=0" ], "accept-encoding": [ "gzip, deflate, br" ], "sec-fetch-dest": [ "document" ], "accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], "user-agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" ] }, "remoteAddress": null }, "response": { "status": 200, "headers": { "Keep-Alive": [ "timeout=60" ], "Connection": [ "keep-alive" ], "Content-Length": [ "7" ], "Date": [ "Mon, 12 Jul 2021 03:56:55 GMT" ], "Content-Type": [ "text/html;charset=UTF-8" ] } }, "timeTaken": 2 }, { "timestamp": "2021-07-12T03:56:55.131Z", "principal": null, "session": null, "request": { "method": "GET", "uri": "http://127.0.0.1:8080/act/test", "headers": { "sec-fetch-mode": [ "navigate" ], "sec-fetch-site": [ "none" ], "cookie": [ "KERPSESSIONIDkdtest02=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I; KERPSESSIONID=1038451043366600704_27hzrnp5Ksxt4HkJdN4b8HPx9jrNcRGOTpvGoWXyxtOYpUzJxZFDKFHO0Bb6i8D324uOz6Ob5Von26n4kGmA4bFehM1R4dmxV26I" ], "accept-language": [ "zh-CN,zh;q=0.9" ], "upgrade-insecure-requests": [ "1" ], "host": [ "127.0.0.1:8080" ], "connection": [ "keep-alive" ], "sec-fetch-user": [ "?1" ], "cache-control": [ "max-age=0" ], "accept-encoding": [ "gzip, deflate, br" ], "sec-fetch-dest": [ "document" ], "accept": [ "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" ], "user-agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" ] }, "remoteAddress": null }, "response": { "status": 200, "headers": { "Keep-Alive": [ "timeout=60" ], "Connection": [ "keep-alive" ], "Content-Length": [ "7" ], "Date": [ "Mon, 12 Jul 2021 03:56:54 GMT" ], "Content-Type": [ "text/html;charset=UTF-8" ] } }, "timeTaken": 7 } ] }