Class: OsCtl::Lib::Uptime
- Inherits:
-
Object
- Object
- OsCtl::Lib::Uptime
- Defined in:
- lib/libosctl/uptime.rb
Overview
Read ‘/proc/uptime`
Instance Attribute Summary collapse
-
#booted_at ⇒ Time
readonly
Time of boot.
-
#idle_time ⇒ Float
readonly
Idle time in seconds.
-
#uptime ⇒ Float
readonly
Uptime in seconds.
Instance Method Summary collapse
-
#initialize(path: '/proc/uptime') ⇒ Uptime
constructor
A new instance of Uptime.
- #parse(path) ⇒ Object protected
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_at ⇒ Time (readonly)
Returns time of boot.
11 12 13 |
# File 'lib/libosctl/uptime.rb', line 11 def booted_at @booted_at end |
#idle_time ⇒ Float (readonly)
Returns idle time in seconds.
8 9 10 |
# File 'lib/libosctl/uptime.rb', line 8 def idle_time @idle_time end |
#uptime ⇒ Float (readonly)
Returns 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 |