sys-uptime 0.7.4 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +40 -26
- data/Gemfile +2 -0
- data/{README.rdoc → README.md} +30 -26
- data/Rakefile +6 -10
- data/lib/sys/unix/sys/uptime.rb +25 -13
- data/lib/sys/uptime.rb +7 -1
- data/lib/sys/windows/sys/uptime.rb +12 -15
- data/lib/sys-uptime.rb +2 -0
- data/spec/sys_uptime_spec.rb +62 -54
- data/sys-uptime.gemspec +19 -9
- data.tar.gz.sig +0 -0
- metadata +65 -32
- metadata.gz.sig +0 -0
- /data/{MANIFEST.rdoc → MANIFEST.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09aa4c4ea6a68982ee2b7574e18041b0a476f06f3531e71736d83d54b3322b49'
|
4
|
+
data.tar.gz: 4aab0dd2a800aa78d4597876c1e7889e8970037e9493d1a0faf7780c81133b9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 222cc669eccbd1d04ea4d5410be8193b265dac268c4bb1e652d9e560a8d4c119225626abf103112988402d215d78ebab1ce317350e87cdd95af5c561ddd9b7c1
|
7
|
+
data.tar.gz: 599316932c555fb289ff1f9aa277e397f33764e474ce16d9e8244e0e3373d9a60fc355f688afe7f963f42c033c6c0df927d0295b8df42796023a813aa780b77f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{CHANGES.rdoc → CHANGES.md}
RENAMED
@@ -1,4 +1,18 @@
|
|
1
|
-
|
1
|
+
## 0.7.6 - 9-Apr-2023
|
2
|
+
* Constructor is now officially private, as are several constants that were
|
3
|
+
never meant to be public.
|
4
|
+
* Lots of rubocop suggested updates.
|
5
|
+
* Minor refactoring for Windows.
|
6
|
+
* Minor updates, including Rakefile and gemspec metadata.
|
7
|
+
|
8
|
+
## 0.7.5 - 29-Oct-2020
|
9
|
+
* Switched docs to markdown format.
|
10
|
+
* Added a Gemfile.
|
11
|
+
|
12
|
+
## 0.7.4 - 18-Mar-2020
|
13
|
+
* Added a LICENSE file as per the requirements of the Apache-2.0 license.
|
14
|
+
|
15
|
+
## 0.7.3 - 31-Dec-2019
|
2
16
|
* Attempting to call Sys::Uptime.new will now raise an error. I thought
|
3
17
|
this was already the case, but apparently one of the tests was bad.
|
4
18
|
* Added explicit .rdoc extensions to various text files so that github
|
@@ -7,48 +21,48 @@
|
|
7
21
|
* Updated the gemspec to reflect the filename updates, as well as the
|
8
22
|
added development dependency.
|
9
23
|
|
10
|
-
|
24
|
+
## 0.7.2 - 4-Nov-2018
|
11
25
|
* Added metadata to the gemspec.
|
12
26
|
* The VERSION constant is now frozen.
|
13
27
|
* Updated cert.
|
14
28
|
|
15
|
-
|
29
|
+
## 0.7.1 - 14-May-2016
|
16
30
|
* Altered internal layout, which also fixed a require bug. Thanks go
|
17
31
|
to jkburges for the spot.
|
18
32
|
* Moved the VERSION constant into a single file shared by all platforms.
|
19
33
|
|
20
|
-
|
34
|
+
## 0.7.0 - 3-Oct-2015
|
21
35
|
* Changed license to Apache 2.0.
|
22
36
|
* Added a cert. This gem is now signed.
|
23
37
|
* Added a sys-uptime.rb file for convenience.
|
24
38
|
* Gem related tasks in the Rakefile now assume Rubygems 2.x.
|
25
39
|
|
26
|
-
|
40
|
+
## 0.6.2 - 8-Nov-2014
|
27
41
|
* Minor updates to gemspec and Rakefile.
|
28
42
|
|
29
|
-
|
43
|
+
## 0.6.1 - 22-Oct-2012
|
30
44
|
* Refactored a private method in the MS Windows source.
|
31
45
|
* Minor fix for one private method test.
|
32
46
|
* Fixed an RbConfig vs Config warning. Thanks Pedro Carrico.
|
33
47
|
|
34
|
-
|
48
|
+
## 0.6.0 - 11-Dec-2011
|
35
49
|
* Switched Unix code to use FFI.
|
36
50
|
* Removed all of the C related tasks from the Rakefile and added the gem:build
|
37
51
|
and gem:install tasks.
|
38
52
|
* Internal directory layout changes, with appropriate changes to the gemspec.
|
39
53
|
|
40
|
-
|
54
|
+
## 0.5.3 - 7-May-2009
|
41
55
|
* Altered the Uptime.seconds implementation on Linux so that it works with
|
42
56
|
both Ruby 1.8.x and 1.9.x. Thanks go to Alexey Chebotar for the spot.
|
43
57
|
|
44
|
-
|
58
|
+
## 0.5.2 - 13-Dec-2008
|
45
59
|
* Fixed a date/time issue in the Windows version caused by Ruby itself.
|
46
60
|
* Fixed the Uptime.seconds, Uptime.minutes and Uptime.hours methods on MS
|
47
61
|
Windows.
|
48
62
|
* Renamed the test file to 'test_sys_uptime.rb'.
|
49
63
|
* Some minor updates to the Rakefile.
|
50
64
|
|
51
|
-
|
65
|
+
## 0.5.1 - 26-Jul-2007
|
52
66
|
* Fixed bug in the MS Windows version caused by incorrect parsing of an
|
53
67
|
MS specific date format (caused by a bug in Ruby 1.8.6). Thanks go to
|
54
68
|
Robert H. for the spot.
|
@@ -57,7 +71,7 @@
|
|
57
71
|
* Added an 'install_gem' Rake task, and updated the README installation
|
58
72
|
instructions.
|
59
73
|
|
60
|
-
|
74
|
+
## 0.5.0 - 30-Mar-2007
|
61
75
|
* For platforms that use C code, the code now always uses the sysctl()
|
62
76
|
function if supported by your system. This replaces the platform specific
|
63
77
|
checks I was doing for the various BSD flavors.
|
@@ -67,20 +81,20 @@
|
|
67
81
|
* Added a Rakefile - users should now use the 'test' and 'install' rake tasks.
|
68
82
|
* Updates to the MANIFEST, README and uptime.txt files.
|
69
83
|
|
70
|
-
|
84
|
+
## 0.4.5 - 19-Nov-2006
|
71
85
|
* Internal layout changes, minor doc updates and gemspec improvements.
|
72
86
|
* No code changes.
|
73
87
|
|
74
|
-
|
88
|
+
## 0.4.4 - 30-Jun-2006
|
75
89
|
* Added inline rdoc documentation to the source files.
|
76
90
|
* Added a gemspec.
|
77
91
|
|
78
|
-
|
92
|
+
## 0.4.3 - 18-Dec-2005
|
79
93
|
* Changed the Linux version to pure Ruby. The current method of determining
|
80
94
|
uptime in unix.c does not work in Linux kernel 2.6+. So, from now on it
|
81
95
|
reads out of /proc/uptime.
|
82
96
|
|
83
|
-
|
97
|
+
## 0.4.2 - 6-May-2005
|
84
98
|
* Fixed a potential boot_time bug.
|
85
99
|
* Removed the version.h file. It's no longer needed since the Windows
|
86
100
|
version is pure Ruby.
|
@@ -92,13 +106,13 @@
|
|
92
106
|
* Made most documents rdoc friendly.
|
93
107
|
* Moved project to RubyForge.
|
94
108
|
|
95
|
-
|
109
|
+
## 0.4.1 - 14-Dec-2004
|
96
110
|
* Moved freebsd code into unix.c file.
|
97
111
|
* Should now work past 249 days (2**31) on systems that have utmpx.h.
|
98
112
|
* Fixed a bug with regards to boot_time, where it was possible that it would
|
99
113
|
simply be empty.
|
100
114
|
|
101
|
-
|
115
|
+
## 0.4.0 - 8-Jul-2004
|
102
116
|
* Removed all reference to the CLK_TCK constant, as per documentation from
|
103
117
|
Richard Stevens that it is deprecated and that sysconf() should be used
|
104
118
|
instead (well, I knew about this, but ignored it until now).
|
@@ -118,18 +132,18 @@
|
|
118
132
|
* Removed the uptime.html file - you may generate that on your own.
|
119
133
|
* Added warranty and license info.
|
120
134
|
|
121
|
-
|
135
|
+
## 0.3.2 - 30-Dec-2003
|
122
136
|
* Cleaned up some warnings that showed up with -Wall on some unix platforms
|
123
137
|
(int vs long format, explicit include)
|
124
138
|
* Minor test suite and extconf.rb changes
|
125
139
|
|
126
|
-
|
140
|
+
## 0.3.1 - 25-Jun-2003
|
127
141
|
* Modified test files to handle HP-UX extensions
|
128
142
|
* Minor doc updates
|
129
143
|
* Added the dhms() method. Actually, this was in the 0.3.0
|
130
144
|
release, I just forgot to mention it in this file :)
|
131
145
|
|
132
|
-
|
146
|
+
## 0.3.0 - 22-Jun-2003
|
133
147
|
* Added OS X support - thanks go to Mike Hall for the patch
|
134
148
|
* Fixed incorrect values in FreeBSD (again Mike Hall)
|
135
149
|
* Modified tc_unix.rb test suite to handle OS X, along with a bit
|
@@ -138,7 +152,7 @@
|
|
138
152
|
* Separated FreeBSD/OS X source into its own file (freebsd.c).
|
139
153
|
The #ifdefs were starting to get too ugly for me
|
140
154
|
|
141
|
-
|
155
|
+
## 0.2.1 - 13-May-2003
|
142
156
|
* Fixed bug in extconf.rb file, and made some major changes
|
143
157
|
* Modified test.rb for those without TestUnit
|
144
158
|
* Modified TestUnit tests - some bogus tests were removed
|
@@ -148,7 +162,7 @@
|
|
148
162
|
* Docs automatically included in doc directory (i.e. no more interactive
|
149
163
|
document creation)
|
150
164
|
|
151
|
-
|
165
|
+
## 0.2.0 - 13-Mar-2003
|
152
166
|
* Added MS Windows support
|
153
167
|
* Added a VERSION constant
|
154
168
|
* Added a test suite (for those with TestUnit installed)
|
@@ -157,7 +171,7 @@
|
|
157
171
|
* Changelog and Manifest are now CHANGES and MANIFEST, respectively
|
158
172
|
* Many changes to extconf.rb
|
159
173
|
|
160
|
-
|
174
|
+
## 0.1.3 - 6-Jan-2003
|
161
175
|
* Added a VERSION class method
|
162
176
|
* Added a copyright notice
|
163
177
|
* Fixed up the docs a bit and moved them to the doc directory
|
@@ -165,14 +179,14 @@
|
|
165
179
|
* Modified test.rb script to make it better
|
166
180
|
* Changed install instructions slightly
|
167
181
|
|
168
|
-
|
182
|
+
## 0.1.2 - 25-Aug-2002
|
169
183
|
* Slight change to preprocessor commands to avoid redefining CLK_TCK on
|
170
184
|
those systems that define it in time.h
|
171
185
|
* Added an INSTALL file
|
172
186
|
|
173
|
-
|
187
|
+
## 0.1.1 - 21-Jun-2002
|
174
188
|
* The CLK_TCK constant wasn't necessarily being set correctly, which could
|
175
189
|
lead to some odd results. This has been fixed.
|
176
190
|
|
177
|
-
|
191
|
+
## 0.1.0 - 17-Jun-2002
|
178
192
|
* Initial release
|
data/Gemfile
ADDED
data/{README.rdoc → README.md}
RENAMED
@@ -1,31 +1,35 @@
|
|
1
|
-
|
1
|
+
[![Ruby](https://github.com/djberg96/sys-uptime/actions/workflows/ruby.yml/badge.svg)](https://github.com/djberg96/sys-uptime/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
## Description
|
2
4
|
A Ruby interface for getting system uptime information.
|
3
5
|
|
4
|
-
|
6
|
+
## Prerequisites
|
5
7
|
ffi 0.1.0 or later on Unixy platforms.
|
6
8
|
|
7
|
-
|
9
|
+
## Installation
|
8
10
|
|
9
|
-
gem install sys-uptime
|
11
|
+
`gem install sys-uptime`
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
## Synopsis
|
14
|
+
```ruby
|
15
|
+
require 'sys-uptime'
|
16
|
+
include Sys
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
# Get everything
|
19
|
+
p Uptime.uptime
|
20
|
+
p Uptime.dhms.join(', ')
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
# Get individual units
|
23
|
+
p Uptime.days
|
24
|
+
p Uptime.hours
|
25
|
+
p Uptime.minutes
|
26
|
+
p Uptime.seconds
|
24
27
|
|
25
|
-
|
26
|
-
|
28
|
+
# Get the boot time
|
29
|
+
p Uptime.boot_time
|
30
|
+
```
|
27
31
|
|
28
|
-
|
32
|
+
## Notes
|
29
33
|
On MS Windows the +Uptime.uptime+ and +Uptime.boot_time+ methods optionally
|
30
34
|
takes a host name as a single argument. The default is localhost.
|
31
35
|
|
@@ -33,28 +37,28 @@ The current time, users and load average are not included in this library
|
|
33
37
|
module, even though you may be used to seeing them with the command
|
34
38
|
line version of +uptime+.
|
35
39
|
|
36
|
-
|
40
|
+
## Known Bugs
|
37
41
|
None that I am aware of. Please log any bugs you find on the project
|
38
42
|
website at https://github.com/djberg96/sys-uptime.
|
39
43
|
|
40
|
-
|
44
|
+
## Questions
|
41
45
|
"Doesn't Struct::Tms do this?" - No.
|
42
46
|
|
43
|
-
|
47
|
+
## License
|
44
48
|
Apache-2.0
|
45
49
|
|
46
|
-
|
47
|
-
Copyright 2002-
|
50
|
+
## Copyright
|
51
|
+
Copyright 2002-2023, Daniel J. Berger
|
48
52
|
|
49
53
|
All Rights Reserved. This module is free software. It may be used,
|
50
54
|
redistributed and/or modified under the same terms as Ruby itself.
|
51
55
|
|
52
|
-
|
56
|
+
## Warranty
|
53
57
|
This library is provided "as is" and without any express or
|
54
58
|
implied warranties, including, without limitation, the implied
|
55
59
|
warranties of merchantability and fitness for a particular purpose.
|
56
60
|
|
57
|
-
|
61
|
+
## Acknowledgements
|
58
62
|
Andrea Fazzi for help with the FFI version.
|
59
63
|
|
60
64
|
Mike Hall for help with the BSD side of things for the original C code.
|
@@ -63,5 +67,5 @@ Ola Eriksson, whose source code I shamelessly plagiarized to get a better
|
|
63
67
|
implementation for systems that have the utmpx.h header file for the
|
64
68
|
original C code.
|
65
69
|
|
66
|
-
|
70
|
+
## Author
|
67
71
|
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -2,23 +2,17 @@ require 'rake'
|
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
5
6
|
|
6
|
-
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc")
|
7
|
+
CLEAN.include("**/*.gem", "**/*.rbx", "**/*.rbc", "**/*.lock")
|
7
8
|
|
8
9
|
namespace 'gem' do
|
9
10
|
desc 'Build the sys-uptime gem'
|
10
11
|
task :create => [:clean] do
|
11
12
|
require 'rubygems/package'
|
12
|
-
spec =
|
13
|
+
spec = Gem::Specification.load('sys-uptime.gemspec')
|
13
14
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
14
|
-
|
15
|
-
if File::ALT_SEPARATOR
|
16
|
-
spec.platform = Gem::Platform.new(['universal','mingw32'])
|
17
|
-
else
|
18
|
-
spec.add_dependency('ffi', '>= 1.0.0')
|
19
|
-
end
|
20
|
-
|
21
|
-
Gem::Package.build(spec, true)
|
15
|
+
Gem::Package.build(spec)
|
22
16
|
end
|
23
17
|
|
24
18
|
desc 'Install the sys-uptime gem'
|
@@ -28,6 +22,8 @@ namespace 'gem' do
|
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
25
|
+
RuboCop::RakeTask.new
|
26
|
+
|
31
27
|
desc "Run the test suite"
|
32
28
|
RSpec::Core::RakeTask.new(:spec)
|
33
29
|
|
data/lib/sys/unix/sys/uptime.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ffi'
|
2
4
|
|
3
5
|
# The Sys module serves as a namespace only.
|
4
6
|
module Sys
|
5
|
-
|
6
7
|
# The Uptime class encapsulates various bits of information regarding your
|
7
8
|
# system's uptime, including boot time.
|
8
9
|
class Uptime
|
@@ -12,8 +13,6 @@ module Sys
|
|
12
13
|
# Error typically raised in one of the Uptime methods should fail.
|
13
14
|
class Error < StandardError; end
|
14
15
|
|
15
|
-
private
|
16
|
-
|
17
16
|
# Hit this issue on Linux, not sure why
|
18
17
|
begin
|
19
18
|
find_type(:clock_t)
|
@@ -29,7 +28,7 @@ module Sys
|
|
29
28
|
private_class_method :strerror, :sysconf, :time, :times, :new
|
30
29
|
|
31
30
|
begin
|
32
|
-
attach_function :sysctl, [
|
31
|
+
attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int
|
33
32
|
private_class_method :sysctl
|
34
33
|
rescue FFI::NotFoundError
|
35
34
|
attach_function :setutxent, [], :void
|
@@ -43,6 +42,11 @@ module Sys
|
|
43
42
|
TICKS = 100 # Ticks per second (TODO: use sysconf)
|
44
43
|
BOOT_TIME = 2 # Boot time
|
45
44
|
|
45
|
+
private_constant :CTL_KERN
|
46
|
+
private_constant :KERN_BOOTTIME
|
47
|
+
private_constant :TICKS
|
48
|
+
private_constant :BOOT_TIME
|
49
|
+
|
46
50
|
class Tms < FFI::Struct
|
47
51
|
layout(
|
48
52
|
:tms_utime, :clock_t,
|
@@ -52,6 +56,8 @@ module Sys
|
|
52
56
|
)
|
53
57
|
end
|
54
58
|
|
59
|
+
private_constant :Tms
|
60
|
+
|
55
61
|
class Timeval < FFI::Struct
|
56
62
|
layout(
|
57
63
|
:tv_sec, :long,
|
@@ -59,6 +65,8 @@ module Sys
|
|
59
65
|
)
|
60
66
|
end
|
61
67
|
|
68
|
+
private_constant :Timeval
|
69
|
+
|
62
70
|
class ExitStatus < FFI::Struct
|
63
71
|
layout(
|
64
72
|
:e_termination, :short,
|
@@ -66,6 +74,8 @@ module Sys
|
|
66
74
|
)
|
67
75
|
end
|
68
76
|
|
77
|
+
private_constant :ExitStatus
|
78
|
+
|
69
79
|
class Utmpx < FFI::Struct
|
70
80
|
layout(
|
71
81
|
:ut_user, [:char, 32],
|
@@ -81,7 +91,7 @@ module Sys
|
|
81
91
|
)
|
82
92
|
end
|
83
93
|
|
84
|
-
|
94
|
+
private_constant :Utmpx
|
85
95
|
|
86
96
|
# Returns a Time object indicating the time the system was last booted.
|
87
97
|
#
|
@@ -91,14 +101,14 @@ module Sys
|
|
91
101
|
#
|
92
102
|
def self.boot_time
|
93
103
|
if RbConfig::CONFIG['host_os'] =~ /linux/i
|
94
|
-
Time.now -
|
104
|
+
Time.now - seconds
|
95
105
|
elsif respond_to?(:sysctl, true)
|
96
106
|
tv = Timeval.new
|
97
107
|
mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_KERN, KERN_BOOTTIME])
|
98
108
|
size = FFI::MemoryPointer.new(:long, 1).write_int(tv.size)
|
99
109
|
|
100
110
|
if sysctl(mib, 2, tv, size, nil, 0) != 0
|
101
|
-
raise SystemCallError,
|
111
|
+
raise SystemCallError, "sysctl function failed: #{strerror(FFI.errno)}"
|
102
112
|
end
|
103
113
|
|
104
114
|
Time.at(tv[:tv_sec], tv[:tv_usec])
|
@@ -126,18 +136,20 @@ module Sys
|
|
126
136
|
#
|
127
137
|
def self.seconds
|
128
138
|
if RbConfig::CONFIG['host_os'] =~ /linux/i
|
139
|
+
# rubocop:disable Lint/RescueException
|
129
140
|
begin
|
130
|
-
|
141
|
+
File.read('/proc/uptime').split.first.to_i
|
131
142
|
rescue Exception => err
|
132
143
|
raise Error, err
|
133
144
|
end
|
145
|
+
# rubocop:enable Lint/RescueException
|
134
146
|
elsif respond_to?(:sysctl, true)
|
135
147
|
tv = Timeval.new
|
136
148
|
mib = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_KERN, KERN_BOOTTIME])
|
137
149
|
size = FFI::MemoryPointer.new(:long, 1).write_int(tv.size)
|
138
150
|
|
139
151
|
if sysctl(mib, 2, tv, size, nil, 0) != 0
|
140
|
-
raise SystemCallError,
|
152
|
+
raise SystemCallError, "sysctl function failed: #{strerror(FFI.errno)}"
|
141
153
|
end
|
142
154
|
|
143
155
|
time(nil) - tv[:tv_sec]
|
@@ -187,11 +199,11 @@ module Sys
|
|
187
199
|
def self.uptime
|
188
200
|
secs = seconds
|
189
201
|
days = secs / 86400
|
190
|
-
secs
|
202
|
+
secs -= days * 86400
|
191
203
|
hours = secs / 3600
|
192
|
-
secs
|
193
|
-
mins
|
194
|
-
secs
|
204
|
+
secs -= hours * 3600
|
205
|
+
mins = secs / 60
|
206
|
+
secs -= mins * 60
|
195
207
|
|
196
208
|
"#{days}:#{hours}:#{mins}:#{secs}"
|
197
209
|
end
|
data/lib/sys/uptime.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if File::ALT_SEPARATOR
|
2
4
|
require_relative 'windows/sys/uptime'
|
3
5
|
else
|
4
6
|
require_relative 'unix/sys/uptime'
|
5
7
|
end
|
6
8
|
|
9
|
+
# The Sys module serves as a namespace only.
|
7
10
|
module Sys
|
11
|
+
# The Uptime class serves as a base singleton class to hang uptime related methods on.
|
8
12
|
class Uptime
|
9
13
|
# The version of the sys-uptime library
|
10
|
-
VERSION = '0.7.
|
14
|
+
VERSION = '0.7.6'
|
15
|
+
|
16
|
+
private_class_method :new
|
11
17
|
end
|
12
18
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'win32ole'
|
2
4
|
require 'socket'
|
3
5
|
require 'date'
|
@@ -5,11 +7,9 @@ require 'time'
|
|
5
7
|
|
6
8
|
# The Sys module serves as a namespace only.
|
7
9
|
module Sys
|
8
|
-
|
9
10
|
# The Uptime class encapsulates various bits of information regarding your
|
10
11
|
# system's uptime, including boot time.
|
11
12
|
class Uptime
|
12
|
-
|
13
13
|
# Error typically raised in one of the Uptime methods should fail.
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
@@ -26,15 +26,12 @@ module Sys
|
|
26
26
|
cs = "winmgmts://#{host}/root/cimv2"
|
27
27
|
begin
|
28
28
|
wmi = WIN32OLE.connect(cs)
|
29
|
-
rescue WIN32OLERuntimeError =>
|
30
|
-
raise Error,
|
29
|
+
rescue WIN32OLERuntimeError => err
|
30
|
+
raise Error, err
|
31
31
|
else
|
32
|
-
query =
|
33
|
-
|
34
|
-
|
35
|
-
time_array = parse_ms_date(ole.LastBootupTime)
|
36
|
-
return Time.mktime(*time_array)
|
37
|
-
}
|
32
|
+
query = 'select LastBootupTime from Win32_OperatingSystem'
|
33
|
+
result = wmi.ExecQuery(query).itemIndex(0).LastBootupTime
|
34
|
+
Time.parse(result.split('.').first)
|
38
35
|
end
|
39
36
|
end
|
40
37
|
|
@@ -81,7 +78,7 @@ module Sys
|
|
81
78
|
#
|
82
79
|
# Sys::Uptime.hours # => 33
|
83
80
|
#
|
84
|
-
def self.hours(host=Socket.gethostname)
|
81
|
+
def self.hours(host = Socket.gethostname)
|
85
82
|
minutes(host) / 60
|
86
83
|
end
|
87
84
|
|
@@ -92,7 +89,7 @@ module Sys
|
|
92
89
|
#
|
93
90
|
# Sys::Uptime.minutes # => 1980
|
94
91
|
#
|
95
|
-
def self.minutes(host=Socket.gethostname)
|
92
|
+
def self.minutes(host = Socket.gethostname)
|
96
93
|
seconds(host) / 60
|
97
94
|
end
|
98
95
|
|
@@ -103,7 +100,7 @@ module Sys
|
|
103
100
|
#
|
104
101
|
# Sys::Uptime.seconds # => 118800
|
105
102
|
#
|
106
|
-
def self.seconds(host=Socket.gethostname)
|
103
|
+
def self.seconds(host = Socket.gethostname)
|
107
104
|
get_seconds(host)
|
108
105
|
end
|
109
106
|
|
@@ -114,7 +111,7 @@ module Sys
|
|
114
111
|
#
|
115
112
|
def self.parse_ms_date(str)
|
116
113
|
return if str.nil?
|
117
|
-
|
114
|
+
Time.parse(str.split('.').first)
|
118
115
|
end
|
119
116
|
|
120
117
|
private_class_method :parse_ms_date
|
@@ -139,7 +136,7 @@ module Sys
|
|
139
136
|
# Returns the number of seconds since boot.
|
140
137
|
#
|
141
138
|
def self.get_seconds(host)
|
142
|
-
(Time.now - boot_time).to_i
|
139
|
+
(Time.now - boot_time(host)).to_i
|
143
140
|
end
|
144
141
|
|
145
142
|
private_class_method :get_seconds
|
data/lib/sys-uptime.rb
CHANGED
data/spec/sys_uptime_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#####################################################################
|
2
4
|
# sys_uptime_spec.rb
|
3
5
|
#
|
@@ -5,99 +7,105 @@
|
|
5
7
|
# 'rake test' task, since it handles the pre-setup code for you.
|
6
8
|
#####################################################################
|
7
9
|
require 'sys/uptime'
|
8
|
-
require '
|
10
|
+
require 'rspec'
|
9
11
|
require 'socket'
|
10
12
|
|
11
|
-
describe Sys::Uptime do
|
12
|
-
|
13
|
-
|
13
|
+
RSpec.describe Sys::Uptime do
|
14
|
+
let(:plausible_seconds) { ENV['CI'] ? 30 : 120 }
|
15
|
+
|
16
|
+
example 'version is set to expected value' do
|
17
|
+
expect(Sys::Uptime::VERSION).to eql('0.7.6')
|
14
18
|
expect(Sys::Uptime::VERSION.frozen?).to be(true)
|
15
19
|
end
|
16
20
|
|
17
|
-
example
|
18
|
-
expect
|
19
|
-
|
21
|
+
example 'constructor is private' do
|
22
|
+
expect{ described_class.new }.to raise_error(NoMethodError)
|
23
|
+
end
|
24
|
+
|
25
|
+
example 'seconds method basic functionality' do
|
26
|
+
expect(described_class).to respond_to(:seconds)
|
27
|
+
expect{ described_class.seconds }.not_to raise_error
|
20
28
|
end
|
21
29
|
|
22
|
-
example
|
23
|
-
expect(
|
24
|
-
expect(
|
30
|
+
example 'seconds method returns a plausible value' do
|
31
|
+
expect(described_class.seconds).to be_a(Integer)
|
32
|
+
expect(described_class.seconds).to be > plausible_seconds
|
25
33
|
end
|
26
34
|
|
27
|
-
example
|
28
|
-
expect(
|
29
|
-
expect{
|
35
|
+
example 'minutes method basic functionality' do
|
36
|
+
expect(described_class).to respond_to(:minutes)
|
37
|
+
expect{ described_class.minutes }.not_to raise_error
|
30
38
|
end
|
31
39
|
|
32
|
-
example
|
33
|
-
expect(
|
34
|
-
expect(
|
40
|
+
example 'minutes method returns a plausible value', :unless => ENV.fetch('CI', nil) do
|
41
|
+
expect(described_class.minutes).to be_a(Integer)
|
42
|
+
expect(described_class.minutes).to be > 3
|
35
43
|
end
|
36
44
|
|
37
|
-
example
|
38
|
-
expect(
|
39
|
-
expect{
|
45
|
+
example 'hours method basic functionality' do
|
46
|
+
expect(described_class).to respond_to(:hours)
|
47
|
+
expect{ described_class.hours }.not_to raise_error
|
40
48
|
end
|
41
49
|
|
42
|
-
example
|
43
|
-
expect(
|
44
|
-
expect(
|
50
|
+
example 'hours method returns a plausible value' do
|
51
|
+
expect(described_class.hours).to be_a(Integer)
|
52
|
+
expect(described_class.hours).to be >= 0
|
45
53
|
end
|
46
54
|
|
47
|
-
example
|
48
|
-
expect(
|
49
|
-
expect{
|
55
|
+
example 'days method basic functionality' do
|
56
|
+
expect(described_class).to respond_to(:days)
|
57
|
+
expect{ described_class.days }.not_to raise_error
|
50
58
|
end
|
51
59
|
|
52
|
-
example
|
53
|
-
expect(
|
54
|
-
expect(
|
60
|
+
example 'days method returns a plausible value' do
|
61
|
+
expect(described_class.days).to be_a(Integer)
|
62
|
+
expect(described_class.days).to be >= 0
|
55
63
|
end
|
56
64
|
|
57
|
-
example
|
58
|
-
expect(
|
59
|
-
expect{
|
65
|
+
example 'uptime method basic functionality' do
|
66
|
+
expect(described_class).to respond_to(:uptime)
|
67
|
+
expect{ described_class.uptime }.not_to raise_error
|
60
68
|
end
|
61
69
|
|
62
|
-
example
|
63
|
-
expect(
|
64
|
-
expect(
|
70
|
+
example 'uptime method returns a non-empty string' do
|
71
|
+
expect(described_class.uptime).to be_a(String)
|
72
|
+
expect(described_class.uptime.empty?).to be(false)
|
65
73
|
end
|
66
74
|
|
67
|
-
example
|
68
|
-
expect{
|
75
|
+
example 'uptime method does not accept any arguments', :unless => File::ALT_SEPARATOR do
|
76
|
+
expect{ described_class.uptime(1) }.to raise_error(ArgumentError)
|
69
77
|
end
|
70
78
|
|
71
|
-
example
|
72
|
-
expect{
|
79
|
+
example 'uptime accepts a host name on Windows', :if => File::ALT_SEPARATOR do
|
80
|
+
expect{ described_class.uptime(Socket.gethostname) }.not_to raise_error
|
73
81
|
end
|
74
82
|
|
75
|
-
example
|
76
|
-
expect(
|
77
|
-
expect{
|
78
|
-
expect(
|
83
|
+
example 'dhms method basic functionality' do
|
84
|
+
expect(described_class).to respond_to(:dhms)
|
85
|
+
expect{ described_class.dhms }.not_to raise_error
|
86
|
+
expect(described_class.dhms).to be_a(Array)
|
79
87
|
end
|
80
88
|
|
81
|
-
example
|
82
|
-
expect(
|
83
|
-
expect(
|
89
|
+
example 'dhms method returns an array of four elements' do
|
90
|
+
expect(described_class.dhms).not_to be_empty
|
91
|
+
expect(described_class.dhms.length).to eq(4)
|
84
92
|
end
|
85
93
|
|
86
|
-
example
|
87
|
-
expect(
|
88
|
-
expect{
|
94
|
+
example 'boot_time method basic functionality' do
|
95
|
+
expect(described_class).to respond_to(:boot_time)
|
96
|
+
expect{ described_class.boot_time }.not_to raise_error
|
89
97
|
end
|
90
98
|
|
91
|
-
example
|
92
|
-
expect(
|
99
|
+
example 'boot_time method returns a Time object' do
|
100
|
+
expect(described_class.boot_time).to be_a(Time)
|
93
101
|
end
|
94
102
|
|
95
|
-
example
|
96
|
-
expect{
|
103
|
+
example 'Uptime class cannot be instantiated' do
|
104
|
+
expect{ described_class.new }.to raise_error(StandardError)
|
97
105
|
end
|
98
106
|
|
99
|
-
example
|
100
|
-
methods =
|
107
|
+
example 'Ensure that ffi functions are private' do
|
108
|
+
methods = described_class.methods(false).map(&:to_s)
|
101
109
|
expect(methods).not_to include('time', 'times')
|
102
110
|
end
|
103
111
|
end
|
data/sys-uptime.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'sys-uptime'
|
5
|
-
spec.version = '0.7.
|
5
|
+
spec.version = '0.7.6'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.license = 'Apache-2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
@@ -12,16 +12,26 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.files = Dir["**/*"].reject{ |f| f.include?('git') }
|
13
13
|
spec.cert_chain = ['certs/djberg96_pub.pem']
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
if File::ALT_SEPARATOR
|
16
|
+
spec.platform = Gem::Platform.new(['universal', 'mingw32'])
|
17
|
+
else
|
18
|
+
spec.add_dependency('ffi', '~> 1.1')
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.add_development_dependency('rake')
|
22
|
+
spec.add_development_dependency('rspec', '~> 3.9')
|
23
|
+
spec.add_development_dependency('rubocop')
|
24
|
+
spec.add_development_dependency('rubocop-rspec')
|
17
25
|
|
18
26
|
spec.metadata = {
|
19
|
-
'homepage_uri'
|
20
|
-
'bug_tracker_uri'
|
21
|
-
'changelog_uri'
|
22
|
-
'documentation_uri'
|
23
|
-
'source_code_uri'
|
24
|
-
'wiki_uri'
|
27
|
+
'homepage_uri' => 'https://github.com/djberg96/sys-uptime',
|
28
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/sys-uptime/issues',
|
29
|
+
'changelog_uri' => 'https://github.com/djberg96/sys-uptime/blob/main/CHANGES.md',
|
30
|
+
'documentation_uri' => 'https://github.com/djberg96/sys-uptime/wiki',
|
31
|
+
'source_code_uri' => 'https://github.com/djberg96/sys-uptime',
|
32
|
+
'wiki_uri' => 'https://github.com/djberg96/sys-uptime/wiki',
|
33
|
+
'rubygems_mfa_required' => 'true',
|
34
|
+
'github_repo' => 'https://github.com/djberg96/sys-uptime'
|
25
35
|
}
|
26
36
|
|
27
37
|
spec.description = <<-EOF
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-uptime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- |
|
@@ -35,36 +35,78 @@ cert_chain:
|
|
35
35
|
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
36
|
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: ffi
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.1'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.1'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rake
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
40
68
|
- !ruby/object:Gem::Dependency
|
41
69
|
name: rspec
|
42
70
|
requirement: !ruby/object:Gem::Requirement
|
43
71
|
requirements:
|
44
72
|
- - "~>"
|
45
73
|
- !ruby/object:Gem::Version
|
46
|
-
version: '3'
|
74
|
+
version: '3.9'
|
47
75
|
type: :development
|
48
76
|
prerelease: false
|
49
77
|
version_requirements: !ruby/object:Gem::Requirement
|
50
78
|
requirements:
|
51
79
|
- - "~>"
|
52
80
|
- !ruby/object:Gem::Version
|
53
|
-
version: '3'
|
81
|
+
version: '3.9'
|
54
82
|
- !ruby/object:Gem::Dependency
|
55
|
-
name:
|
83
|
+
name: rubocop
|
56
84
|
requirement: !ruby/object:Gem::Requirement
|
57
85
|
requirements:
|
58
86
|
- - ">="
|
59
87
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
type: :
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rubocop-rspec
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
62
104
|
prerelease: false
|
63
105
|
version_requirements: !ruby/object:Gem::Requirement
|
64
106
|
requirements:
|
65
107
|
- - ">="
|
66
108
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
109
|
+
version: '0'
|
68
110
|
description: |2
|
69
111
|
The sys-uptime library is a simple interface for gathering uptime
|
70
112
|
information. You can retrieve data in seconds, minutes, days, hours,
|
@@ -72,44 +114,35 @@ description: |2
|
|
72
114
|
email: djberg96@gmail.com
|
73
115
|
executables: []
|
74
116
|
extensions: []
|
75
|
-
extra_rdoc_files:
|
76
|
-
- CHANGES.rdoc
|
77
|
-
- MANIFEST.rdoc
|
78
|
-
- README.rdoc
|
117
|
+
extra_rdoc_files: []
|
79
118
|
files:
|
119
|
+
- CHANGES.md
|
120
|
+
- Gemfile
|
80
121
|
- LICENSE
|
81
|
-
-
|
82
|
-
-
|
83
|
-
- spec/sys_uptime_spec.rb
|
122
|
+
- MANIFEST.md
|
123
|
+
- README.md
|
84
124
|
- Rakefile
|
85
|
-
- certs
|
86
125
|
- certs/djberg96_pub.pem
|
87
|
-
- examples
|
88
126
|
- examples/uptime_test.rb
|
89
|
-
- lib
|
90
127
|
- lib/sys-uptime.rb
|
91
|
-
- lib/sys
|
92
|
-
- lib/sys/uptime.rb
|
93
|
-
- lib/sys/unix
|
94
|
-
- lib/sys/unix/sys
|
95
128
|
- lib/sys/unix/sys/uptime.rb
|
96
|
-
- lib/sys/
|
97
|
-
- lib/sys/windows/sys
|
129
|
+
- lib/sys/uptime.rb
|
98
130
|
- lib/sys/windows/sys/uptime.rb
|
99
|
-
-
|
100
|
-
-
|
101
|
-
- README.rdoc
|
131
|
+
- spec/sys_uptime_spec.rb
|
132
|
+
- sys-uptime.gemspec
|
102
133
|
homepage: https://github.com/djberg96/sys-uptime
|
103
134
|
licenses:
|
104
135
|
- Apache-2.0
|
105
136
|
metadata:
|
106
137
|
homepage_uri: https://github.com/djberg96/sys-uptime
|
107
138
|
bug_tracker_uri: https://github.com/djberg96/sys-uptime/issues
|
108
|
-
changelog_uri: https://github.com/djberg96/sys-uptime/blob/
|
139
|
+
changelog_uri: https://github.com/djberg96/sys-uptime/blob/main/CHANGES.md
|
109
140
|
documentation_uri: https://github.com/djberg96/sys-uptime/wiki
|
110
141
|
source_code_uri: https://github.com/djberg96/sys-uptime
|
111
142
|
wiki_uri: https://github.com/djberg96/sys-uptime/wiki
|
112
|
-
|
143
|
+
rubygems_mfa_required: 'true'
|
144
|
+
github_repo: https://github.com/djberg96/sys-uptime
|
145
|
+
post_install_message:
|
113
146
|
rdoc_options: []
|
114
147
|
require_paths:
|
115
148
|
- lib
|
@@ -124,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
157
|
- !ruby/object:Gem::Version
|
125
158
|
version: '0'
|
126
159
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
128
|
-
signing_key:
|
160
|
+
rubygems_version: 3.3.26
|
161
|
+
signing_key:
|
129
162
|
specification_version: 4
|
130
163
|
summary: A Ruby interface for getting system uptime information.
|
131
164
|
test_files:
|
metadata.gz.sig
CHANGED
Binary file
|
File without changes
|