Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Forked from anonymous/gist:4346624
Last active December 9, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdgaag/4346633 to your computer and use it in GitHub Desktop.
Save avdgaag/4346633 to your computer and use it in GitHub Desktop.
Shell one-liner using Ruby to create a histogram from a log file.
export COL=$COLUMNS ; grep '\[CatalogItem\] Retrieved' production.log | awk '{ print $6 $7 }' | ruby -ne 'BEGIN { puts ENV.inspect;$columns = ENV["COL"].to_i; $all = Hash.new { |h,k| h[k] = 0 } }; a, b = $_.split("(").map(&:to_f); next if a < 1; $all[((b/a/100).floor)] += a.to_i; END { max_value = $all.values.max; puts "\e[2J\e[f"; puts "Average request time".center($columns); print "\033[37m" ; puts "ms/req ±50ms".center($columns); print "\033[0m" ; puts ("─" * $columns); $all.keys.sort.each { |k| puts "#{(k * 100 + 50).to_s.rjust(6)}: \033[31m#{"▓" * ($all[k].to_f / max_value * ($columns - 8))}\033[0m"; }; puts "─" * $columns; print "\033[5m\033[35m" ; puts "(╯°□°)╯︵ ┻━┻ © Arjan & Ariejan".center($columns); print "\033[0m" }'
@avdgaag
Copy link
Author

avdgaag commented Dec 30, 2012

Also see the Ruby-less version using Awk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment