IIS日志格式为windows 2008 IIS的默认格式
1 创建空数据库
2.创建一个空表
CREATE TABLE [dbo].[tablename](
[date] [datetime] NULL,
[time] [datetime] NULL,
[s-ip] [varchar](50) NULL,
[cs-method] [varchar](50) NULL,
[cs-uri-stem] [varchar](255) NULL,
[cs-uri-query] [varchar](4096) NULL,
[s-port] [int] NULL,
[cs-username] [varchar](50) NULL,
[c-ip] [varchar](50) NULL,
[cs(User-Agent)] [varchar](1024) NULL,
[sc-status] [int] NULL,
[sc-substatus] [nchar](10) NULL,
[sc-win32-status] [int] NULL,
[time-taken] [int] NULL
)
3. 处理日志文件
用editplus打开日志文件,使用正则表达式替换,将^#.*$ 替换为空,从而去掉以#开始的行(注释行)
4.导入日志文件
BULK INSERT [dbo].[tablename] FROM 'c:\logpath.log'
WITH (
FIELDTERMINATOR = ' ',
ROWTERMINATOR = '\n'
)
5. 进行分析,如查询访问量最大的文件:
SELECT cs-uri-stem, count(1)
FROM [tablename]
group by cs-uri-stem
order by count(1)