Celluloid actors require 'redis' require 'celluloid' class RedisAdapter include Celluloid def initialize(redis) @redis = redis end def record(path) redis.incr("stats:#{path}") end def fetch(path) redis.get("stats:#{path}") end protected attr_reader :redis end
2. Convert to CSV #!/usr/bin/env ruby require 'csv' columns = %w{name time mean_rate 95th_percentile} out = CSV.generate do |csv| csv << columns.to_a ARGF.each_line do |l| fields = l.split next if fields[0] != 'I,' metrics = fields.slice(7..-1).inject({}) do |hsh, str| name, value = str.split('=') hsh.update(name => value) end csv << columns.inject([]) { |row, name| row << metrics[name] } end end puts out
More reading •Metrics, the original library - http:// metrics.codahale.com •Metrics everywhere, the slides - http:// codahale.com/codeconf-2011-04-09-metrics- metrics-everywhere.pdf •Metrics everywhere, the talk - http:// www.youtube.com/watch?v=czes-oa0yik