Tomcat 中有個日志 loca_access.log 可以記錄每個接口的請求耗時,用於做性能等分析比較有用,SpringBoot里,默認不記錄這個日志,可以在 yml里做如下配置,開啟這樣的日志,
server:
tomcat:
#basedir: /var/tmp
background-processor-delay: 30
redirect-context-root: true
uri-encoding: UTF-8
accesslog:
enabled: true #為true時,上面的日期格式才有意義,否則就是寫在一個文件里了
buffered: true
directory: ./logs #記錄在 jar 運行的同級目錄中的 logs 目錄下,可以與 logback 記錄目錄配置一致
file-date-format: .yyyy-MM-dd
#pattern: '%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %D ms'
pattern: '%t %a %m %U %s %b %D ms' #%D 請求耗時N毫秒
prefix: access_log
rename-on-rotate: false
request-attributes-enabled: false
rotate: true
suffix: .log
結合 Python 腳本,分析接口請求次數、平均耗時等操作
對於具體配置類ServerProperties,我們可以看到對於tomcat的配置有很多,可以根據自己的需要進行選擇配置