Skip to content

Instantly share code, notes, and snippets.

@elucid
Last active December 26, 2015 19:39
Show Gist options
  • Save elucid/7203416 to your computer and use it in GitHub Desktop.
Save elucid/7203416 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# usage:
# $ tail -5000 sidekiq.log | ./parse_sidekiq_logs.rb
class Averager
def initialize
@count = 0
@total = 0.0
end
def average
return @total if @count.zero?
@total / @count
end
def event(quantity)
@count += 1
@total += quantity
quantity
end
end
entries = Hash.new {|h, k| h[k] = Averager.new}
while line = $stdin.gets
line.chomp!
next unless line.match 'done:'
columns = line.split ' '
worker_class = columns[3]
job_time = columns[-2].to_f
entries[worker_class].event job_time
end
entries.keys.each do |worker_class|
average_job_time = entries[worker_class].average.round(2)
puts "#{worker_class}: #{average_job_time}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment