日志分析 取出访问最多的IP,URL,以及五分钟内的访问流量
2016-05-06 14:27
393 查看
日志分析!
对最近五分钟的日志进行分析,取出访问最多的IP,URL,以及五分钟内的访问流量
对最近五分钟的日志进行分析,取出访问最多的IP,URL,以及五分钟内的访问流量
#!/bin/sh name=`cat /etc/salt/minion | grep "^id" | awk '{print $2}'` ipaddr=`/sbin/ifconfig | grep "inet addr" | egrep -v "10\.|127\." | awk -F'[: ]+' '{print $4}'` #LogPath='/usr/local/tengine/logs/' ##日志的时间格式。 function Time(){ FileTime=`head -1 $Logfile |awk -F"[[ / :]" '{print "["$5"/"$6"/"$7}'` start_time=${FileTime}:`date -d "6 mins ago" +%H:%M` #now_time=${FileTime}:`date +%H:%M` } ##取得指定最新时间内的日志,并进行分析 function IpUrlFlow(){ Time path="/tmp/backup/log" [ ! -d $path/flow/ ] && mkdir -p $path/flow file="$path/${Logfile}.time.log" FileIp="$path/${Logfile}.IP.log" FileUri="$path/${Logfile}.uri.sort.log" FileIpStat="$path/${Logfile}.flow.sort.log" FileStat="$path/flow/${Logfile}.flow.log" #取出直接时间内的日志 #awk -v start_time=$start_time -v now_time=$now_time '{if ($4>start_time && $4<now_time) print $0 }' ${Logfile} > $file awk -v start_time=$start_time -v now_time=$now_time '{if ($4>start_time) print $0 }' ${Logfile} > $file if [ -s $file ] then #对取出的日志进行统计,取出访问次数最多的ip以及次数 awk '{S[$1]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 > ${FileIp} #awk '{S[$1]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 > ${FileIpStat} #对取出的日志进行统计,取出访问次数最多的URI以及次数 awk '{S[$7]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 > ${FileUri} #awk '{S[$7]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 >> ${FileIpStat} #对取出的日志进行统计,取出访问流量最多的ip以及流量大小,单位M awk '{S[$1]=+$10}END{for(n in S) print S " "n }' $file |sort -rn|head -20 |awk '{a=$1/1024/1014}{print a " M "$2}' >${FileIpStat} #awk '{S[$1]=+$10}END{for(n in S) print S " "n }' $file |sort -rn|head -20 |awk '{a=$1/1024/1014}{print a " M "$2}' >>${FileIpStat} #整合到一个文件! echo -e "IP_start" > ${FileStat} cat ${FileIp} >> ${FileStat} echo -e "IP_end\n" >> ${FileStat} echo -e "URL_start" >> ${FileStat} cat ${FileUri} >> ${FileStat} echo -e "URL_end\n" >> ${FileStat} echo -e "Flow_star" >> ${FileStat} cat ${FileIpStat} >> ${FileStat} echo -e "Flow_end\n" >> ${FileStat} fi } #Ip function main(){ cd ${LogPath} for Logfile in `ls acce*` do if [ ! -s ${Logfile} ] then echo ${Logfile} else Ip fi done } main ############################################################################### ############################################################################### ############################################################################### #!/bin/sh name=`cat /etc/salt/minion | grep "^id" | awk '{print $2}'` ipaddr=`/sbin/ifconfig | grep "inet addr" | egrep -v "10\.|127\." | awk -F'[: ]+' '{print $4}'` LogPath='/usr/local/tengine/logs/' #filelog='access_www.log' #Logfile="${LogPath}${filelog}" function Time(){ FileTime=`head -1 $Logfile |awk -F"[[ / :]" '{print "["$5"/"$6"/"$7}'` start_time=${FileTime}:`date -d "6 mins ago" +%H:%M` now_time=${FileTime}:`date +%H:%M` #echo $FileTime $start_time $now_time } function Ip(){ Time path="/script/shell/gaogd/LogAnalyze/log" [ ! -d $path/flow ] && mkdir -p $path/flow file="$path/${Logfile}.time.log" #FileIp="$path/${Logfile}.IP.log" #FileUri="$path/${Logfile}.uri.sort.log" #FileIpStat="$path/${Logfile}.stat.sort.log" FileStat="$path/flow/${Logfile}.Statistics.log" awk -v start_time=$start_time -v now_time=$now_time '{if ($4>start_time && $4<now_time) print $0 }' ${Logfile} > $file if [ -s $file ] then echo -e "IP_start" > ${FileStat} awk '{S[$1]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 >> ${FileStat} echo -e "IP_end\n" >> ${FileStat} echo -e "URL_start" >> ${FileStat} awk '{S[$7]++}END{for(n in S) print S " "n }' $file |sort -rn |head -20 >> ${FileStat} echo -e "URL_end\n" >> ${FileStat} echo -e "Flow_star" >> ${FileStat} awk '{S[$1]=+$10}END{for(n in S) print S " "n }' $file |sort -rn|head -20 |awk '{a=$1/1024/1014}{print a " M "$2}' >>${FileStat} echo -e "Flow_end\n" >> ${FileStat} else if [ -s ${FileStat} ] then mv ${FileStat} /tmp fi fi } #Ip function main(){ cd ${LogPath} for Logfile in `ls acce*` do if [ ! -s ${Logfile} ] then echo ${Logfile} else Ip fi done } main
相关文章推荐
- java-用HttpURLConnection发送Http请求.
- VBScript 剪贴板抓取URL并在浏览器中打开
- 用vbs 实现从剪贴板中抓取一个 URL 然后在浏览器中打开该 Web 站点
- asp获取URL参数的几种方法分析总结[原创]_应用技巧_脚本之家
- Shell日志分析常用命令和例子
- C#实现在网页中根据url截图并输出到网页的方法
- zend framework框架中url大小写问题解决方法
- url decode problem 解决方法
- php url地址栏传中文乱码解决方法集合
- 探讨:parse url解析URL,返回其组成部分
- C#实现自动识别URL网址的方法
- C#自定义针对URL地址的处理类实例
- JavaScritp添加url参数并将参数加入到url中及更改url参数的方法
- ASP让url的中文显示为编码
- JS使用ajax方法获取指定url的head信息中指定字段值的方法
- 关于URL中的特殊符号使用介绍
- JS来动态的修改url实现对url的增删查改
- js url传值中文乱码之解决之道
- js获取url传值的方法
- JavaScript操作URL的相关内容集锦