Class: OsCtl::Lib::LoadAvg
- Inherits:
-
Object
- Object
- OsCtl::Lib::LoadAvg
- Defined in:
- lib/libosctl/loadavg.rb
Overview
Read system load average from /proc/loadavg, see man proc(5)
Instance Attribute Summary collapse
-
#avg ⇒ Hash<1, 5, 15>
readonly
Load averages.
- #last_pid ⇒ Integer readonly
- #runnable ⇒ Integer readonly
- #total ⇒ Integer readonly
Instance Method Summary collapse
-
#initialize(path: '/proc/loadavg') ⇒ LoadAvg
constructor
A new instance of LoadAvg.
- #parse(path) ⇒ Object protected
- #to_a ⇒ Object
Constructor Details
#initialize(path: '/proc/loadavg') ⇒ LoadAvg
Returns a new instance of LoadAvg.
17 18 19 |
# File 'lib/libosctl/loadavg.rb', line 17 def initialize(path: '/proc/loadavg') parse(path) end |
Instance Attribute Details
#avg ⇒ Hash<1, 5, 15> (readonly)
Returns load averages.
5 6 7 |
# File 'lib/libosctl/loadavg.rb', line 5 def avg @avg end |
#last_pid ⇒ Integer (readonly)
14 15 16 |
# File 'lib/libosctl/loadavg.rb', line 14 def last_pid @last_pid end |
#runnable ⇒ Integer (readonly)
8 9 10 |
# File 'lib/libosctl/loadavg.rb', line 8 def runnable @runnable end |
#total ⇒ Integer (readonly)
11 12 13 |
# File 'lib/libosctl/loadavg.rb', line 11 def total @total end |
Instance Method Details
#parse(path) ⇒ Object (protected)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/libosctl/loadavg.rb', line 31 def parse(path) parsed = File.read(path).strip.split @avg = { 1 => parsed[0].to_f, 5 => parsed[1].to_f, 15 => parsed[2].to_f } runnable, total = parsed[3].split('/') @runnable = runnable.to_i @total = total.to_i @last_pid = parsed[4].to_i end |
#to_a ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/libosctl/loadavg.rb', line 21 def to_a [ @avg[1], @avg[5], @avg[15] ] end |