Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
1 change: 1 addition & 0 deletions barr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/all_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 3 additions & 2 deletions lib/barr/blocks/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down