主頁 > 知識庫 > shell腳本定時統(tǒng)計Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫

shell腳本定時統(tǒng)計Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫

熱門標(biāo)簽:使用U盤裝系統(tǒng) 百度競價點擊價格的計算公式 網(wǎng)站建設(shè) 檢查注冊表項 美圖手機(jī) 硅谷的囚徒呼叫中心 智能手機(jī) 阿里云

1,統(tǒng)計PV和IP

統(tǒng)計當(dāng)天的PV(Page View)

cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l

統(tǒng)計某一天的PV

cat access.log | sed -n '/20\/Sep\/2018/p' | wc -l

查看日志中訪問次數(shù)最多的前10個IP

cat access.log.1 |cut -d ' ' -f 1 | sort |uniq -c | sort -nr | awk '{print $0 }' | head -n 10

查看日志中訪問次數(shù)超過1000次的前10個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請求

curl http://127.0.0.1:8080/login?admin&passwd=12345678

使用curl發(fā)送POST請求

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ā)送動態(tài)參數(shù)POST請求

curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'$atime'","BTime":"'$btime'"}' $url
curl -i -X POST -H "'Content-type':'application/json'" -d '{"ATime":"'${atime}'","BTime":"'{$btime}'"}' ${url}

3,shell腳本統(tǒng)計并發(fā)送

#!/bin/bash
log_path=/var/log/nginx/access.log
domain="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ù)庫

@RequestMapping(value = "/count")
  public void count(String count){
  //業(yè)務(wù)代碼 
}

總結(jié)

以上所述是小編給大家介紹的shell腳本定時統(tǒng)計Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

標(biāo)簽:煙臺 懷化 通遼 湖北 賀州 山南 黃山 湘潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《shell腳本定時統(tǒng)計Nginx下access.log的PV并發(fā)送給API保存到數(shù)據(jù)庫》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266