Nginx Log日誌統計分析常用命令

2022-08-20 09:33:11 字數 4447 閱讀 8855

統計ip訪問量(獨立ip訪問數量)

awk '' access.log | sort -n | uniq | wc -l

檢視某一時間段的ip訪問量(4-5點)

grep "07/apr/2017:0[4-5]" access.log | awk '' | sort | uniq -c| sort -nr | wc -l

檢視訪問最頻繁的前100個ip

awk '' access.log | sort -n |uniq -c | sort -rn | head -n 100

檢視訪問100次以上的ip

awk '' access.log | sort -n |uniq -c |awk ''|sort -rn

查詢某個ip的詳細訪問情況,按訪問頻率排序

grep '127.0.01' access.log |awk ''|sort |uniq -c |sort -rn |head -n 100

檢視訪問最頻的頁面(top100)

awk '' access.log | sort |uniq -c | sort -rn | head -n 100

檢視訪問最頻的頁面([排除php頁面】(top100)

grep -v ".php"  access.log | awk '' | sort |uniq -c | sort -rn | head -n 100

檢視頁面訪問次數超過100次的頁面

cat access.log | cut -d ' ' -f 7 | sort |uniq -c | awk '' | less

檢視最近1000條記錄,訪問量最高的頁面

tail -1000 access.log |awk ''|sort|uniq -c|sort -nr|less

統計每秒的請求數,top100的時間點(精確到秒)

awk '' access.log |cut -c 14-21|sort|uniq -c|sort -nr|head -n 100

統計每分鐘的請求數,top100的時間點(精確到分鐘)

awk '' access.log |cut -c 14-18|sort|uniq -c|sort -nr|head -n 100

統計每小時的請求數,top100的時間點(精確到小時)

awk '' access.log |cut -c 14-15|sort|uniq -c|sort -nr|head -n 100

在nginx log中最後乙個字段加入$request_time

列出傳輸時間超過 3 秒的頁面,顯示前20條

cat access.log|awk '($nf > 3)'|sort -n|uniq -c|sort -nr|head -20

列出php頁面請求時間超過3秒的頁面,並統計其出現的次數,顯示前100條

cat access.log|awk '($nf > 1 &&  $7~/\.php/)'|sort -n|uniq -c|sort -nr|head -100

統計蜘蛛抓取次數

統計蜘蛛抓取404的次數

檢視當前tcp連線數

netstat -tan | grep "established" | grep ":80" | wc -l

用tcpdump嗅探80埠的訪問看看誰最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -f"." '' | sort | uniq -c | sort -nr

統計ip訪問量(獨立ip訪問數量)

awk '' access.log | sort -n | uniq | wc -l

檢視某一時間段的ip訪問量(4-5點)

grep "07/apr/2017:0[4-5]" access.log | awk '' | sort | uniq -c| sort -nr | wc -l

檢視訪問最頻繁的前100個ip

awk '' access.log | sort -n |uniq -c | sort -rn | head -n 100

檢視訪問100次以上的ip

awk '' access.log | sort -n |uniq -c |awk ''|sort -rn

查詢某個ip的詳細訪問情況,按訪問頻率排序

grep '127.0.01' access.log |awk ''|sort |uniq -c |sort -rn |head -n 100

檢視訪問最頻的頁面(top100)

awk '' access.log | sort |uniq -c | sort -rn | head -n 100

檢視訪問最頻的頁面([排除php頁面】(top100)

grep -v ".php"  access.log | awk '' | sort |uniq -c | sort -rn | head -n 100

檢視頁面訪問次數超過100次的頁面

cat access.log | cut -d ' ' -f 7 | sort |uniq -c | awk '' | less

檢視最近1000條記錄,訪問量最高的頁面

tail -1000 access.log |awk ''|sort|uniq -c|sort -nr|less

統計每秒的請求數,top100的時間點(精確到秒)

awk '' access.log |cut -c 14-21|sort|uniq -c|sort -nr|head -n 100

統計每分鐘的請求數,top100的時間點(精確到分鐘)

awk '' access.log |cut -c 14-18|sort|uniq -c|sort -nr|head -n 100

統計每小時的請求數,top100的時間點(精確到小時)

awk '' access.log |cut -c 14-15|sort|uniq -c|sort -nr|head -n 100

在nginx log中最後乙個字段加入$request_time

列出傳輸時間超過 3 秒的頁面,顯示前20條

cat access.log|awk '($nf > 3)'|sort -n|uniq -c|sort -nr|head -20

列出php頁面請求時間超過3秒的頁面,並統計其出現的次數,顯示前100條

cat access.log|awk '($nf > 1 &&  $7~/\.php/)'|sort -n|uniq -c|sort -nr|head -100

統計蜘蛛抓取次數

統計蜘蛛抓取404的次數

檢視當前tcp連線數

netstat -tan | grep "established" | grep ":80" | wc -l

用tcpdump嗅探80埠的訪問看看誰最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -f"." '' | sort | uniq -c | sort -nr

Nginx Log日誌統計分析常用命令

cat access.log awk sort nr uniq c sort nr more 2761 183.185.117.4 1828 221.205.161.114 1672 223.12.67.104 1106 223.12.161.30 951183.185.112.241 876223...

統計分析的體會

客戶給了一張基本的資料表,然後讓我做大量的計算,並且動態 靜態的做統計分析報表,經過了長達兩個月的苦戰,終於作完了。體會如下 1 一張存放中間統計結果的表是必要的,如果能夠將客戶的統計分析需要經過計算才能顯示的字段囊括在內是最好不過了,畢竟在查詢的過程中作計算是一件很討厭的事,雖然有資料冗餘,但是簡...

資料的統計分析

資料預處理之後,我們要做一些統計分析,來觀察我們的資料,這其中包括 描述性分析 統計推斷。描述性分析 主要是統計指標 圖表。1 集中趨勢分析 除了分位數,我們還可以結合 中位數 眾數 平均數三者的關係。具體地 眾數在中位數左側,平均數在中位數右側,則此時資料呈正偏態分布,又叫右偏,存在極大異常值。是...