首页 > 代码库 > 分析APACHE NGINX的LOG
分析APACHE NGINX的LOG
1、查看当天有多少个IP访问:
awk ‘{print $1}‘ log_file|sort|uniq|wc -l
2、查看某一个页面被访问的次数:
grep "/index.php" log_file | wc -l
3、查看每一个IP访问了多少个页面:
awk ‘{++S[$1]} END {for (a in S) print a,S[a]}‘ log_file
4、将每个IP访问的页面数进行从小到大排序:
awk ‘{++S[$1]} END {for (a in S) print S[a],a}‘ log_file | sort -n
5、查看某一个IP访问了哪些页面:
grep ^111.111.111.111 log_file| awk ‘{print $1,$7}‘
6、去掉搜索引擎统计当天的页面:
awk ‘{print $12,$1}‘ log_file | grep ^\"Mozilla | awk ‘{print $2}‘ |sort | uniq | wc -l
7、查看2009年6月21日14时这一个小时内有多少IP访问:
awk ‘{print $4,$1}‘ log_file | grep 21/Jun/2009:14 | awk ‘{print $2}‘| sort | uniq | wc -l
8,查看apache进程:
ps aux | grep httpd | grep -v grep | wc -l
9,查看80端口的tcp连接:
netstat -tan | grep "ESTABLISHED" | grep ":80" | wc -l
10,通过日志查看当天ip连接数,过滤重复:
cat access_log | grep "20/Oct/2008" | awk ‘{print $2}‘ | sort | uniq -c | sort -nr
11,当天ip连接数最高的ip都在干些什么(原来是蜘蛛):
cat access_log | grep "20/Oct/2008:00" | grep "122.102.7.212" | awk ‘{print $8}‘ | sort | uniq -c | sort -nr | head -n 10
12,当天访问页面排前10的url:
cat access_log | grep "20/Oct/2008:00" | awk ‘{print $8}‘ | sort | uniq -c | sort -nr | head -n 10
13,用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." ‘{print $1"."$2"."$3"."$4}‘ | sort | uniq -c | sort -nr
接着从日志里查看该ip在干嘛:
cat access_log | grep 122.102.7.212| awk ‘{print $1"\t"$8}‘ | sort | uniq -c | sort -nr | less
14,查看某一时间段的ip连接数:
grep "2006:0[7-8]" www20060723.log | awk ‘{print $2}‘ | sort | uniq -c| sort -nr | wc -l
本文出自 “亮公子” 博客,请务必保留此出处http://iyull.blog.51cto.com/4664834/1864369
分析APACHE NGINX的LOG