Skip to content

Instantly share code, notes, and snippets.

@richardc
Created November 18, 2014 10:19
Show Gist options
  • Save richardc/fc3a61ff93af7dca75b2 to your computer and use it in GitHub Desktop.
Save richardc/fc3a61ff93af7dca75b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# take a mcollective client log on stdin, summarises the requests and
# responses
@send_count = 0
@recv_count = 0
def summarize_and_reset
if @send_count > 0 || @recv_count > 0
puts "Sent #{@send_count} recv #{@recv_count}"
end
@send_count = 0
@recv_count = 0
end
# lines look like
# D, [2014-11-13T18:31:30.429267 #4559] DEBUG -- : runnerstats.rb:38:in `validated' Incrementing validated stat
line_pattern = /^[A-Z], \[(?<timestamp>.*?) #(?<pid>.*?)\] (?<level>.*?) -- : (?<filename>.*?):(?<lineno>.*):in `(?<method>.*?)' (?<message>.*)/
names = line_pattern.names.map(&:to_sym)
ARGF.each_line do |line|
match = line_pattern.match(line)
unless match
puts "Non matching line: #{line}"
next
end
record = Hash[names.zip(match.captures)]
if record.values_at(:filename, :method) == ['base.rb', 'create_request']
# this is approximately the start of the request
summarize_and_reset
agent, collective, request_id = /for agent '(.*?)' in collective (.*?) with request id (.*)/.match(record[:message]).captures
puts "#{record[:timestamp]} #{agent} #{request_id}"
end
if record.values_at(:filename, :method) == ['mc.rb', 'discover']
match = /Got discovery reply from (.*)/.match(record[:message])
if match
responder, = match.captures
puts " #{record[:timestamp]} discovered #{responder}"
end
end
if record.values_at(:filename, :method) == ['activemq.rb', 'publish']
match = /Sending a direct message .* "mc_identity"=>"(.*?)"/.match(record[:message])
if match
target, = match.captures
puts " #{record[:timestamp]} send to #{target}"
@send_count += 1
end
end
if record.values_at(:filename, :method) == ['runnerstats.rb', 'validated']
@recv_count += 1
end
end
summarize_and_reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment