Class: OsCtl::Lib::Uptime

Inherits:
Object
  • Object
show all
Defined in:
lib/libosctl/uptime.rb

Overview

Read ‘/proc/uptime`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: '/proc/uptime') ⇒ Uptime

Returns a new instance of Uptime.



13
14
15
# File 'lib/libosctl/uptime.rb', line 13

def initialize(path: '/proc/uptime')
  parse(path)
end

Instance Attribute Details

#booted_atTime (readonly)

Returns time of boot.

Returns:

  • (Time)

    time of boot



11
12
13
# File 'lib/libosctl/uptime.rb', line 11

def booted_at
  @booted_at
end

#idle_timeFloat (readonly)

Returns idle time in seconds.

Returns:

  • (Float)

    idle time in seconds



8
9
10
# File 'lib/libosctl/uptime.rb', line 8

def idle_time
  @idle_time
end

#uptimeFloat (readonly)

Returns uptime in seconds.

Returns:

  • (Float)

    uptime in seconds



5
6
7
# File 'lib/libosctl/uptime.rb', line 5

def uptime
  @uptime
end

Instance Method Details

#parse(path) ⇒ Object (protected)



19
20
21
22
23
24
25
# File 'lib/libosctl/uptime.rb', line 19

def parse(path)
  values = File.read(path).strip.split

  @uptime = values[0].to_f
  @idle_time = values[1].to_f
  @booted_at = Time.now - @uptime
end