Reputation: 4539
I'm setting up a logging script with Ruby and am having some difficulties with getting the load averages as a variable. I'm using:
uptime | awk '{print $10}'
to get the current 1 minute time stamp, but I'm having trouble getting it without a trailing comma. I could edit the string later, but that seems less efficient. Is there an edit that will simply remove the ,
from the return?
Upvotes: 0
Views: 1305
Reputation: 1477
In the end, it also works through /proc/loadavg
, but the usage is a little more idiomatic, so I thought I'd mention the sys-cpu Gem (which existed even in 2013 :)) as well:
gem install sys-cpu
require 'sys-cpu'
puts Sys::CPU.load_avg
... which will give you a nice array: [0.72, 1.14, 1.11]
.
Upvotes: 2
Reputation: 182743
How about:
cut -f 1 -d " " /proc/loadavg
The uptime
command reads /proc/loadavg
and then adds the commas.
Upvotes: 3