Method: Duffy::System.cpu_percent
- Defined in:
- lib/duffy/system.rb
.cpu_percent ⇒ Object
The system’s current CPU utilization. Darwin: Get a list of all processes’ CPU percentage and add them up. Linux: Read /proc/stat twice and take the difference to give cpu time used in that interval.
62 63 64 65 66 67 68 69 70 |
# File 'lib/duffy/system.rb', line 62 def cpu_percent case RUBY_PLATFORM when /darwin/ then `ps -A -o %cpu`.lines.map(&:to_f).inject(:+) / threads when /linux/ then proc_diff else 0 end rescue 0 end |