I am supporting an application that is having occasional performance issues. The client wants to know how often a page is slow.
i.e. Total times a page took greater than x secs / Total number of requests for the page
I would like to write a single query to fetch the desired data.
Something like this in SQL would probably work but isn't working in IIS Log parser.
select URL, count(case when time > 100 then 1 else null end), count(*)
from table1
group by URL
The problem here is that you need two queries.
One to count the total number of requests per page regardless of time taken
SELECT cs-uri-stem, COUNT(*) AS all-requests
FROM ex*.log
GROUP BY cs-uri-stem
One to count the number of pages where time-taken > X seconds
SELECT cs-uri-stem, COUNT(*) as total-requests
FROM ex*.log
WHERE time-taken > 1000 <- time_taken is milliseconds
GROUP BY cs-uri-stem
The result you're after would require a JOIN:
SELECT a.cs-uri-stem, COUNT(*) as total-requests, b.all-requests
FROM ex*.log AS a
JOIN (
SELECT cs-uri-stem, COUNT(*) AS all-requests
FROM ex*.log
GROUP BY cs-uri-stem
) AS b ON b.cs-uri-stem = a.cs-uri-stem
WHERE a.time-taken >1000
GROUP BY a.cs-uri-stem
Unfortunately there is no support for JOIN's in LogParser.
What you could do is import the results of both queries into a SQL Database and run the query there:
SELECT a.cs-uri-stem, COUNT(*) as total-requests, b.all-requests
FROM long_running_pages AS a
JOIN all_pages_grouped b ON ( a.cs-uri-stem = b.cs-uri-stem)
GROUP BY a.cs-uri-stem