Object
The Uptime class encapsulates various bits of information regarding your system's uptime, including boot time.
The Uptime class encapsulates various bits of information regarding your system's uptime, including boot time.
The version of the sys-uptime library.
Returns the boot time as a Time object.
Example:
Sys::Uptime.boot_time # => Fri Dec 12 20:18:58 -0700 2008
# File lib/windows/sys/uptime.rb, line 25 def self.boot_time(host = Socket.gethostname) cs = "winmgmts://#{host}/root/cimv2" begin wmi = WIN32OLE.connect(cs) rescue WIN32OLERuntimeError => e raise Error, e else query = "select LastBootupTime from Win32_OperatingSystem" results = wmi.ExecQuery(query) results.each{ |ole| time_array = parse_ms_date(ole.LastBootupTime) return Time.mktime(*time_array) } end end
Returns the total number of days the system has been up on host, or the localhost if no host is provided.
Example:
Sys::Uptime.days # => 1
# File lib/windows/sys/uptime.rb, line 73 def self.days(host = Socket.gethostname) hours(host) / 24 end
Calculates and returns the number of days, hours, minutes and seconds the host has been running as a four-element Array. The localhost is used if no host is provided.
Example:
Sys::Uptime.dhms # => [1, 9, 55, 11]
# File lib/windows/sys/uptime.rb, line 62 def self.dhms(host = Socket.gethostname) get_dhms(host) end
Returns the total number of hours the system has been up on host, or the localhost if no host is provided.
Example:
Sys::Uptime.hours # => 33
# File lib/windows/sys/uptime.rb, line 84 def self.hours(host=Socket.gethostname) minutes(host) / 60 end
Returns the total number of minutes the system has been up on host, or the localhost if no host is provided.
Example:
Sys::Uptime.minutes # => 1980
# File lib/windows/sys/uptime.rb, line 95 def self.minutes(host=Socket.gethostname) seconds(host) / 60 end
Returns the total number of seconds the system has been up on host, or the localhost if no host is provided.
Example:
Sys::Uptime.seconds # => 118800
# File lib/windows/sys/uptime.rb, line 106 def self.seconds(host=Socket.gethostname) get_seconds(host) end
Calculates and returns the number of days, hours, minutes and seconds the host has been running as a colon-separated string.
The localhost is used if no host is provided.
Example:
Sys::Uptime.uptime # => "1:9:55:11"
# File lib/windows/sys/uptime.rb, line 50 def self.uptime(host = Socket.gethostname) get_dhms(host).join(':') end
Generated with the Darkfish Rdoc Generator 2.