1,統(tǒng)計(jì)PV和IP
統(tǒng)計(jì)當(dāng)天的PV(Page View)
cat access.log | sed -n /`date "+%d//%b//%Y"`/p |wc -l
統(tǒng)計(jì)某一天的PV
cat access.log | sed -n '/20//Sep//2018/p' | wc -l
查看日志中訪問次數(shù)最多的前10個(gè)IP
cat access.log.1 |cut -d ' ' -f 1 | sort |uniq -c | sort -nr | awk '{print $0 }' | head -n 10
查看日志中訪問次數(shù)超過(guò)1000次的前10個(gè)IP
cat access.log.1 |cut -d ' ' -f 1 | sort |uniq -c | sort -nr | awk '{if($1>1000) print $0 }' | head -n 10
2,curl發(fā)送數(shù)據(jù)
使用curl發(fā)送GET請(qǐng)求
curl http://127.0.0.1:8080/login?admin&passwd=12345678
使用curl發(fā)送POST請(qǐng)求
curl -d "user=admin&passwd=12345678" http://127.0.0.1:8080/login
使用curl發(fā)送POST的JSON數(shù)據(jù)
curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' http://127.0.0.1:8000/login
使用curl發(fā)送動(dòng)態(tài)參數(shù)POST請(qǐng)求
curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $urlcurl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'${atime}'","BTime":"'{$btime}'"}' ${url}
3,shell腳本統(tǒng)計(jì)并發(fā)送
#!/bin/bashlog_path=/var/log/nginx/access.logdomain="http://127.0.0.1:8080/data/count"log_date=`date "+%d/%b/%Y"`echo ${log_date}total_visit=`cat ${log_path} | grep $log_date|wc -l`curl -d "count=${total_visit}" ${domain}echo $total_visit
4,服務(wù)器端接受并保存到數(shù)據(jù)庫(kù)
@RequestMapping(value = "/count") public void count(String count){ //業(yè)務(wù)代碼 }
總結(jié)
以上所述是小編給大家介紹的shell腳本定時(shí)統(tǒng)計(jì)Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫(kù),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)之家網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選