打开Tomcat的访问日志
cd apache-tomcat/conf/server.xml
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t %r" %s %b" />
生产的访问日志文件在 apache-tomcat/logs/localhost_access_log.2018-03-22.txt
如何使用Tomcat的访问日志
分析日志格式

shell语句
获取QPS
sudo cat ./localhost_access_log.2019-12-21.txt | cut -d ' ' -f4 | uniq -c | sort -n -r -o ./temp_sorted.log
获取每分钟访问请求
sudo cat ./localhost_access_log.2020-02-19.txt |cut -d ' ' -f4| cut -d [ -f2| cut -c1-17 |uniq -c| sort -n -r -o ./temp_sorted_19.log
注:cat为打开一个文件。
cut是对文件做切割,-d为指定分割符。
uniq为去重
sort为排序,-o为输出到文件。
本文详细介绍如何配置和解析Tomcat的访问日志,包括设置日志格式、使用Shell命令获取QPS和每分钟访问请求等关键指标。适用于希望深入了解Tomcat日志管理的开发者。
10万+

被折叠的 条评论
为什么被折叠?



