Method: LinuxStat::OS.uptime
- Defined in:
- lib/linux_stat/os.rb
.uptime ⇒ Object
Reads /proc/uptime and returns the system uptime:
LinuxStat::OS.uptime
=> {:hour=>10, :minute=>34, :second=>12.59}
Using uptime is 10x slower than using uptime_i
If the stat isn’t available, an empty hash is returned.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/linux_stat/os.rb', line 146 def uptime _uptime = LinuxStat::ProcFS.uptime_f return {} unless _uptime uptime_i = _uptime.to_i h = uptime_i / 3600 m = uptime_i % 3600 / 60 s = _uptime.%(3600).%(60).round(2) { hour: h, minute: m, second: s } end |