Skip to content

Instantly share code, notes, and snippets.

@h3h h3h/gist:1685499
Created Jan 26, 2012

Embed
What would you like to do?
Get Request per Second Stats from Tokyo Tyrant
irb(main):033:0> stats = lambda { TokyoTyrantHandle.connection.current_connection.stat.split("\n").map {|i| vs=i.split("\t"); [vs[0] => vs[1]] }.flatten.inject({}) { |a,s| a.merge(s.keys.first => s.values.first) }.values_at('cnt_get', 'cnt_fwmkeys', 'cnt_put', 'cnt_out').map(&:to_i) }; res = 10.times.map { sleep 10; stats.call }
=> [[1414054383, 267722854, 668732970, 113985517], [1414055664, 267724365, 668733951, 113986564], [1414057054, 267725847, 668734993, 113987897], [1414058401, 267727235, 668735983, 113988827], [1414059735, 267728810, 668736976, 113989342], [1414061000, 267730358, 668737930, 113989818], [1414062189, 267731965, 668738915, 113990122], [1414063283, 267733524, 668739810, 113990639], [1414064276, 267734965, 668740685, 113990822], [1414065384, 267736397, 668741558, 113991083]]
irb(main):038:0> pp res.each_cons(2).map {|set_a, set_b| (0..3).map {|i| (set_b[i] - set_a[i]) / 10.0}}[[128.1, 151.1, 98.1, 104.7], [139.0, 148.2, 104.2, 133.3],
[134.7, 138.8, 99.0, 93.0],
[133.4, 157.5, 99.3, 51.5],
[126.5, 154.8, 95.4, 47.6],
[118.9, 160.7, 98.5, 30.4],
[109.4, 155.9, 89.5, 51.7],
[99.3, 144.1, 87.5, 18.3],
[110.8, 143.2, 87.3, 26.1]]
=> nil
irb(main):042:0> res.each_cons(2).map {|set_a, set_b| (0..3).map {|i| (set_b[i] - set_a[i]) / 10.0}}.transpose.map {|a| (a.sum / a.size.to_f).round(2) }
=> [122.23, 150.48, 95.42, 61.84]
# get, fwmkeys, put, out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.