DevOps teams analyze application performance by parsing web server logs to identify slow endpoints. This drill teaches you to extract structured data from semi-structured log files using regular expressions with named groups. You'll parse Heroku router logs containing timestamps, HTTP methods, paths, service times, and status codes, then output the data to CSV for analysis in Excel or other tools.
Use regex with named groups: /(?<name>pattern)/ for cleaner extraction
Match the timestamp at line start: /^(?<timestamp>\S+)/
Extract method with word characters: /(?<method>\w+)/
Parse service time: /service=(?<service>\d+)ms/ then convert to integer
File.readlines reads all lines into an array
Use match[:group_name] to access named capture groups
Skip non-matching lines with 'next unless match'
parse_logs('server.log')
Parsed 3 requests, average service time: 72 ms
parse_logs('server.log')
Parsed 1 request, average service time: 5 ms
parse_logs('server.log')
Parsed 4 requests, average service time: 52 ms
Console output will appear here...
Are you sure?
You're making great progress