IIS Log 欄位說明
常用 Log MEMO
- 取得執行時間長度超過 10 秒的 Request,並依照執行時間長短排序
LogParser.exe -i:IISW3C -rtp:50 "select date, time, s-ip, cs-method, cs-uri-stem, cs-username, sc-status, time-taken from 'C:\Logs\*.log' where sc-status <> 101 and time-taken > 10000 order by time-taken desc"
- 依照執行時間長短,出特定 Request 的執行時間
LogParser.exe -i:IISW3C -rtp:50 "select date, time, s-ip, cs-method, cs-uri-stem, cs-username, sc-status, time-taken from 'C:\Logs\*.log' WHERE cs-uri-stem = '/xxx/yyy/zzz' order by time-taken desc"
- 以每分鐘群組,取得以分鐘為單位的 Request 最大值、最小值、平均值,以及每分鐘 Request 數量
logparser -i:IISW3C -rtp:50 "select QUANTIZE(TO_LOCALTIME(TO_TIMESTAMP(date, time)), 60) AS Minute, MAX(time-taken) As Max, MIN(time-taken) As Min, Avg(time-taken) As Average, Count(*) as RequestCount from 'C:\Logs\*.log' where sc-status <> 101 and cs-uri-stem not like '/xxx/yyy/%' and time-taken <> 0 Group By Minute"
- 以 Reqest 群組,取得 Request 最大值、最小值、平均值,以及 Request 數量
logparser -i:IISW3C -rtp:50 "select cs-uri-stem, Max(time-taken) As Max, Min(time-taken) As Min, Avg(time-taken) As Avg, Count(*) As RequestCount from 'C:\Logs\*.log' where time-taken <> 0 group by cs-uri-stem"
- 取得特定帳號在特定時間的操作軌跡
logparser -i:IISW3C -rtp:50 "select date, time, s-ip, cs-method, cs-uri-stem, cs-username, sc-status, time-taken from 'C:\Logs\*.log' where sc-status <> 101 and cs-uri-stem not like '/xxx/yyy/%' and time > '01:00:00' and time < '01:30:00' and cs-username = 'JohnDoe' order by date, time desc"
- 取得特定帳號每分鐘點擊特定 URL 的次數
logparser -i:iisw3c -o:csv "select QUANTIZE(TO_LOCALTIME(TO_TIMESTAMP(date, time)), 60) AS Minute, cs-uri-stem, cs-username, count(*) as hitCount from *.log group by Minute, cs-uri-stem, cs-username"
- 將特定欄位組合成一個欄位來輸出
logparser -i:iisw3c "select STRCAT('[', STRCAT( cs-method,STRCAT(']', cs-uri-stem))) from *.log"
example: [GET]/HOME/Index
- 查 Event Log
logparser -i:evt "select top 2 TimeGenerated, EventID, EventType, SourceName, SUBSTR(Message,0,100) As Message from Application"
REF
https://gist.github.com/dejanstojanovic/30c757f0b093a9e24314e82a8abe98d2 http://dog0416.blogspot.com/2019/05/log-parser-log-parser-queries-note.html
https://logparserplus.com/functions/ https://logparserplus.com/examples/ https://hackmd.io/@Not/LogParserStudio_with_IISLog