您的位置:首页 > 其它

IIS日志分析

2016-02-18 11:47 411 查看
原文地址http://www.cnblogs.com/fish-li/p/3139366.html
使用Log Parser将IIS日志导入SQL Server

"C:\Program Files\Log Parser 2.2\logparser.exe"
"SELECT * FROM 'D:\Temp\u_ex130615.log' to tbname" -i:IISW3C -o:SQL

-oConnString:"Driver={SQL Server};server=localhost\sqlexpress;database=dbname;uid=sa;pwd=123456;"

-createtable:ON
注意:
1.IIS日志在将结果导出到SQLSERVER时,字段名中不符合标识符规范的字符将会删除。
例如:c-ip 会变成 cip, s-port 会变成 sport 。
2.IIS日志中记录的时间是UTC时间,而且把日期和时间分开了,导出到SQLSERVER时,会生成二个字段date和time:
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日志分析 IIS