简体   繁体   English

从IIS日志中提取不同的RESTful MVC路由

[英]Extract Distinct restful MVC routes from IIS logs

My shop is using MVC3/FUBU on IIS 7. I recently put something into production and I wanted to gather metrics from the IIS logs using log parser. 我的商店在IIS 7上使用MVC3 / FUBU。我最近投入了一些工作,我想使用日志解析器从IIS日志中收集指标。 I've done this many times before but because the MVC3 routes are of the form /api/person//address/ the log saves /api/person/123/address/456 in the uristem column. 我以前做了很多次但是因为MVC3路由的形式是/ api / person //地址/日志保存/ api / person / 123 / address / 456在uristem列中。

Does anyone have any ideas on how to get data about specific routes from IIS logs? 有没有人对如何从IIS日志中获取有关特定路由的数据有任何想法?

As an exmaple: Log Like this: 作为一个例子:日志像这样:

cs-uri-stem
/api/person/123/address/456
/api/person/121/address/33
/api/person/1555/address/5555

Output like: Total Hits = 3 输出如:总命中数= 3

Ok the way that I end up dealing with this is to create a HttpModule that will pull the route pattern from the HttpContext and put into the server variables as URL_PATTERN. 好吧,我最终处理这个问题的方法是创建一个HttpModule,它将从HttpContext中提取路由模式,并将其作为URL_PATTERN放入服务器变量中。 Once its in server_variables IIS Advanced Logging can get ahold of it and save it. 一旦它在server_variables IIS高级日志记录可以得到它并保存它。 If the current request doesn't have a route it'll just use the normal local portion of the url (so it'll match cs-uri-stem in the logs). 如果当前请求没有路由,它将只使用url的正常本地部分(因此它将匹配日志中的cs-uri-stem)。

Now sql/log parser the query: select url_pattern,count(url_pattern) from (yourlogs) where timestamp between (start/end) group by url_pattern order by count(url_pattern) desc will give me back the number of hits for each endpoint in my app. 现在sql / log解析器查询:从(yourlogs)中选择url_pattern,count(url_pattern),其中(start / end)group by url_pattern order by count(url_pattern)desc之间的时间戳将返回我的每个端点的命中数应用程序。

This could obviously be done in a fubu behaviour, but we've got a bunch of classic asp and MVC3 running around (i know I know...) and this will handle all of them. 这显然可以用fubu行为来完成,但是我们有一堆经典的asp和MVC3在运行(我知道我知道......),这将处理所有这些。 Also you can apparently 'publish' a field from a module using RaiseTraceEvent that IIS Advanced Logging can then get ahold of, but it was giving me fits trying to figure it out so I just went with what I have. 你也可以使用RaiseTraceEvent从一个模块“发布”一个字段,然后IIS高级日志可以得到它,但是它让我适合尝试解决这个问题所以我只是选择了我所拥有的东西。

I've posted this question all over the place referencing fubu and MVC3 and I have gotten little to no interest, which really suprised me. 我已经在引用fubu和MVC3的地方发布了这个问题,我几乎没有兴趣,这让我很惊讶。 How do people poke about in their logs for info if you can't easily determine the routes being used. 如果您无法轻易确定所使用的路线,人们如何在日志中查询信息。

https://gist.github.com/2854760 https://gist.github.com/2854760

You can use the Regular Expression search feature of Notepad++. 您可以使用Notepad ++的正则表达式搜索功能。 This article might help. 文章可能的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM