sys-uptime 0.5.4-x86-mingw32 → 0.6.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +145 -144
- data/MANIFEST +13 -12
- data/README +67 -14
- data/Rakefile +44 -87
- data/examples/{sys_uptime_example.rb → uptime_test.rb} +21 -21
- data/lib/unix/sys/uptime.rb +213 -0
- data/lib/windows/sys/uptime.rb +164 -158
- data/sys-uptime.gemspec +23 -21
- data/test/test_sys_uptime.rb +109 -65
- metadata +29 -50
- data/doc/uptime.txt +0 -98
- data/ext/extconf.rb +0 -28
- data/ext/sys/uptime.c +0 -250
- data/lib/linux/sys/uptime.rb +0 -101
data/lib/linux/sys/uptime.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# The Sys module serves as a namespace only.
|
2
|
-
module Sys
|
3
|
-
|
4
|
-
# The Uptime class encapsulates various bits of information regarding your
|
5
|
-
# system's uptime, including boot time.
|
6
|
-
class Uptime
|
7
|
-
|
8
|
-
# Error typically raised in one of the Uptime methods should fail.
|
9
|
-
class Error < StandardError; end
|
10
|
-
|
11
|
-
# The version of the sys-uptime library.
|
12
|
-
VERSION = '0.5.4'
|
13
|
-
|
14
|
-
# The file to read uptime information from.
|
15
|
-
UPTIME_FILE = '/proc/uptime'
|
16
|
-
|
17
|
-
# Returns the total number of seconds of uptime.
|
18
|
-
#
|
19
|
-
# Example:
|
20
|
-
#
|
21
|
-
# Sys::Uptime.seconds # => 118800
|
22
|
-
#
|
23
|
-
def self.seconds
|
24
|
-
begin
|
25
|
-
IO.read(UPTIME_FILE).split.first.to_i
|
26
|
-
rescue Exception => err
|
27
|
-
raise Error, err
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Returns the total number of minutes of uptime.
|
32
|
-
#
|
33
|
-
# Example:
|
34
|
-
#
|
35
|
-
# Sys::Uptime.minutes # => 678
|
36
|
-
#
|
37
|
-
def self.minutes
|
38
|
-
self.seconds / 60
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns the total number of hours of uptime.
|
42
|
-
#
|
43
|
-
# Example:
|
44
|
-
#
|
45
|
-
# Sys::Uptime.hours # => 31
|
46
|
-
#
|
47
|
-
def self.hours
|
48
|
-
self.minutes / 60
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns the total number of days of uptime.
|
52
|
-
#
|
53
|
-
# Example:
|
54
|
-
#
|
55
|
-
# Sys::Uptime.days # => 2
|
56
|
-
#
|
57
|
-
def self.days
|
58
|
-
self.hours / 24
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns the uptime as a colon separated string, including days,
|
62
|
-
# hours, minutes and seconds.
|
63
|
-
#
|
64
|
-
# Example:
|
65
|
-
#
|
66
|
-
# Sys::Uptime.uptime # => "1:9:24:57"
|
67
|
-
#
|
68
|
-
def self.uptime
|
69
|
-
seconds = self.seconds
|
70
|
-
days = seconds / 86400
|
71
|
-
seconds -= days * 86400
|
72
|
-
hours = seconds / 3600
|
73
|
-
seconds -= hours * 3600
|
74
|
-
minutes = seconds / 60
|
75
|
-
seconds -= minutes * 60
|
76
|
-
|
77
|
-
"#{days}:#{hours}:#{minutes}:#{seconds}"
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns the uptime as a four element array, including days, hours,
|
81
|
-
# minutes and seconds.
|
82
|
-
#
|
83
|
-
# Example:
|
84
|
-
#
|
85
|
-
# Sys::Uptime.dhms # => [1,9,24,57]
|
86
|
-
#
|
87
|
-
def self.dhms
|
88
|
-
self.uptime.split(":")
|
89
|
-
end
|
90
|
-
|
91
|
-
# Returns the time the system was booted as a Time object.
|
92
|
-
#
|
93
|
-
# Example:
|
94
|
-
#
|
95
|
-
# Sys::Uptime.boot_time
|
96
|
-
#
|
97
|
-
def self.boot_time
|
98
|
-
Time.now - self.seconds
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|