Skip to content

Instantly share code, notes, and snippets.

@rgaufman
Created May 21, 2018 15:28
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 rgaufman/85a1d98dc7365f04b5049a49a6cf71c9 to your computer and use it in GitHub Desktop.
Save rgaufman/85a1d98dc7365f04b5049a49a6cf71c9 to your computer and use it in GitHub Desktop.
irb(main):001:0> `sudo top -bn2 | sed -n '/Cpu/p' | tail -n 1`.strip.split(/,\s/).map do |i|
irb(main):002:1* i.match(/([0-9]*(\.|\,)[0-9]*)/).captures[0].to_f
irb(main):003:1> end
=> [0.2, 1.8, 11.5, 86.4, 0.0, 0.0, 0.1, 0.0]
irb(main):004:0> `sudo top -bn2 | sed -n '/Cpu/p' | tail -n 1`.strip.split(/,\s*/).map do |i|
irb(main):005:1* i.match(/([0-9]*\.[0-9]*)/).captures[0].to_f
irb(main):006:1> end
=> [0.1, 1.8, 11.8, 85.6, 0.8, 0.0, 0.1, 0.0]
irb(main):007:0> `cat /etc/issue`
=> "Ubuntu 16.04 LTS \\n \\l\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment