原文地址http://www.cnblogs.com/fish-li/p/3139366.htmlhtml
使用Log Parser將IIS日誌導入SQL Server
sql
"C:\Program Files\Log Parser 2.2\logparser.exe" express
"SELECT * FROM 'D:\Temp\u_ex130615.log' to tbname" -i:IISW3C -o:SQL ide
-oConnString:"Driver={SQL Server};server=localhost\sqlexpress;database=dbname;uid=sa;pwd=123456;"
ui
-createtable:ONspa
注意:日誌
1.IIS日誌在將結果導出到SQLSERVER時,字段名中不符合標識符規範的字符將會刪除。server
例如:c-ip 會變成 cip, s-port 會變成 sport 。htm
2.IIS日誌中記錄的時間是UTC時間,並且把日期和時間分開了,導出到SQLSERVER時,會生成二個字段date和time:blog
1.在SQLSERVER中增長一列,而後把UTC時間換成本地時區的時間,T-SQL腳本以下:
alter table tbname add RequestTime datetime
go
update tbname set RequestTime=dateadd(hh,8,convert(varchar(10),date,120)
+ ' ' + convert(varchar(13),time,114))
2.直接在導出IIS日誌時,把時間轉換過來,此時要修改命令:
"C:\Program Files\Log Parser 2.2\logparser.exe"
"SELECT TO_LOCALTIME(TO_TIMESTAMP(ADD(TO_STRING(date, 'yyyy-MM-dd '), TO_STRING(time, 'hh:mm:ss')),'yyyy-MM-dd hh:mm:ss')) AS RequestTime, * FROM 'D:\Temp\u_ex130615.log' to tbname"
-i:IISW3C -o:SQL
-oConnString:"Driver={SQL Server};server=localhost\sqlexpress;database=tbname;uid=;pwd=;"
-createtable:ON
查詢訪問量最大的IP
select cip,count(*) from tbname group by cip order by count(*) desc