IIS日志分析

原文地址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

相关文章
相关标签/搜索