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 腳本,分析接口請求次數、平均耗時等操作