diff --git a/README.md b/README.md index 0175958..e974eb0 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ Shows the current date and/or time. #### CPU -Shows CPU load averaged across all cores. +**Requires mpstat from [sysstat](https://github.com/sysstat/sysstat)**. Shows CPU load averaged across all cores. `cpu = Barr::Blocks::CPU.new` diff --git a/barr.gemspec b/barr.gemspec index 0956a95..71ad2d8 100644 --- a/barr.gemspec +++ b/barr.gemspec @@ -44,4 +44,5 @@ Gem::Specification.new do |spec| spec.requirements << '(Optional) RhythmBox & rhythmbox-client' spec.requirements << '(Optional) FontAwesome font' spec.requirements << '(Optional) playerctl' + spec.requirements << '(Optional) mpstat from sysstat' end diff --git a/examples/all_in.rb b/examples/all_in.rb index 71c1221..bb42bee 100755 --- a/examples/all_in.rb +++ b/examples/all_in.rb @@ -34,7 +34,7 @@ icon: "\uf0c2 Birmingham: ", interval: 60) -cpu = Barr::Blocks::CPU.new icon: "\uf1fe", format: '${LOAD}% ${TEMP}' +cpu = Barr::Blocks::CPU.new icon: "\uf1fe", format: '${LOAD} ${TEMP}' mem = Barr::Blocks::Mem.new bgcolor: '#333333' diff --git a/lib/barr/blocks/cpu.rb b/lib/barr/blocks/cpu.rb index 804047e..2769309 100644 --- a/lib/barr/blocks/cpu.rb +++ b/lib/barr/blocks/cpu.rb @@ -20,11 +20,12 @@ def update! private def load_sys_cmd - `grep 'cpu ' /proc/stat | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'` + # courtesy of https://stackoverflow.com/a/9229907 + `mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12"%" }'` end def temp_sys_cmd - `cat /sys/class/thermal/thermal_zone0/temp` + `cat /sys/class/thermal/thermal_zone0/temp`.chomp end end