asp.net-mvc-3restfubumvciis-logs

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. 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.

Does anyone have any ideas on how to get data about specific routes from IIS logs?

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


Solution

  • 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. Once its in server_variables IIS Advanced Logging can get ahold of it and save it. 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).

    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.

    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. 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.

    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. 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