sys-uptime 0.5.2-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,135 @@
1
+ == 0.5.2 - 13-Dec-2008
2
+ * Fixed a date/time issue in the Windows version caused by Ruby itself.
3
+ * Fixed the Uptime.seconds, Uptime.minutes and Uptime.hours methods on MS
4
+ Windows.
5
+ * Renamed the test file to 'test_sys_uptime.rb'.
6
+ * Some minor updates to the Rakefile.
7
+
8
+ == 0.5.1 - 26-Jul-2007
9
+ * Fixed bug in the MS Windows version caused by incorrect parsing of an
10
+ MS specific date format (caused by a bug in Ruby 1.8.6). Thanks go to
11
+ Robert H. for the spot.
12
+ * Inlined the Rake installation tasks, so the install.rb file has been
13
+ removed.
14
+ * Added an 'install_gem' Rake task, and updated the README installation
15
+ instructions.
16
+
17
+ == 0.5.0 - 30-Mar-2007
18
+ * For platforms that use C code, the code now always uses the sysctl()
19
+ function if supported by your system. This replaces the platform specific
20
+ checks I was doing for the various BSD flavors.
21
+ * Fix for OS X - the Uptime.boot_time method now works.
22
+ * UptimeError is now Uptime::Error.
23
+ * Improved RDoc in the uptime.c source code.
24
+ * Added a Rakefile - users should now use the 'test' and 'install' rake tasks.
25
+ * Updates to the MANIFEST, README and uptime.txt files.
26
+
27
+ == 0.4.5 - 19-Nov-2006
28
+ * Internal layout changes, minor doc updates and gemspec improvements.
29
+ * No code changes.
30
+
31
+ == 0.4.4 - 30-Jun-2006
32
+ * Added inline rdoc documentation to the source files.
33
+ * Added a gemspec.
34
+
35
+ == 0.4.3 - 18-Dec-2005
36
+ * Changed the Linux version to pure Ruby. The current method of determining
37
+ uptime in unix.c does not work in Linux kernel 2.6+. So, from now on it
38
+ reads out of /proc/uptime.
39
+
40
+ == 0.4.2 - 6-May-2005
41
+ * Fixed a potential boot_time bug.
42
+ * Removed the version.h file. It's no longer needed since the Windows
43
+ version is pure Ruby.
44
+ * NetBSD 2.x and FreeBSD 5.x now supported.
45
+ * Removed the INSTALL file. Installation instructions are now in
46
+ the README file.
47
+ * Removed the uptime.rd file. You can generate html documentation by
48
+ running rdoc over the uptime.txt file.
49
+ * Made most documents rdoc friendly.
50
+ * Moved project to RubyForge.
51
+
52
+ == 0.4.1 - 14-Dec-2004
53
+ * Moved freebsd code into unix.c file.
54
+ * Should now work past 249 days (2**31) on systems that have utmpx.h.
55
+ * Fixed a bug with regards to boot_time, where it was possible that it would
56
+ simply be empty.
57
+
58
+ == 0.4.0 - 8-Jul-2004
59
+ * Removed all reference to the CLK_TCK constant, as per documentation from
60
+ Richard Stevens that it is deprecated and that sysconf() should be used
61
+ instead (well, I knew about this, but ignored it until now).
62
+ * Scrapped the C version for Windows in favor of a pure Ruby version that
63
+ uses win32ole + WMI.
64
+ * Added a boot_time method for Unix systems (Windows already had this).
65
+ * Added an UptimeError class on Unix systems (and replaced UptimeException
66
+ on Windows).
67
+ * Modified an internal function to raise an UptimeError if the times()
68
+ function fails. Also, it now returns an unsigned long instead of a plain
69
+ long.
70
+ * Replaced the two different test suites with a single, unified test suite.
71
+ * Cleaned up the extconf.rb script. I now assume that TestUnit is installed.
72
+ * Removed the load_avg method (which was never advertised and which I hope
73
+ you weren't using). You can find a load_avg method in the sys-cpu package.
74
+ * Changed uptime.rd2 to uptime.rd to be consistent with my other packages.
75
+ * Removed the uptime.html file - you may generate that on your own.
76
+ * Added warranty and license info.
77
+
78
+ == 0.3.2 - 30-Dec-2003
79
+ * Cleaned up some warnings that showed up with -Wall on some unix platforms
80
+ (int vs long format, explicit include)
81
+ * Minor test suite and extconf.rb changes
82
+
83
+ == 0.3.1 - 25-Jun-2003
84
+ * Modified test files to handle HP-UX extensions
85
+ * Minor doc updates
86
+ * Added the dhms() method. Actually, this was in the 0.3.0
87
+ release, I just forgot to mention it in this file :)
88
+
89
+ == 0.3.0 - 22-Jun-2003
90
+ * Added OS X support - thanks go to Mike Hall for the patch
91
+ * Fixed incorrect values in FreeBSD (again Mike Hall)
92
+ * Modified tc_unix.rb test suite to handle OS X, along with a bit
93
+ * of minor cleanup
94
+ * Removed VERSION class method. Use the constant instead
95
+ * Separated FreeBSD/OS X source into its own file (freebsd.c).
96
+ The #ifdefs were starting to get too ugly for me
97
+
98
+ == 0.2.1 - 13-May-2003
99
+ * Fixed bug in extconf.rb file, and made some major changes
100
+ * Modified test.rb for those without TestUnit
101
+ * Modified TestUnit tests - some bogus tests were removed
102
+ * Added a README file with some additional info
103
+ * Created a version.h file, so that I can keep the VERSION number
104
+ in one place
105
+ * Docs automatically included in doc directory (i.e. no more interactive
106
+ document creation)
107
+
108
+ == 0.2.0 - 13-Mar-2003
109
+ * Added MS Windows support
110
+ * Added a VERSION constant
111
+ * Added a test suite (for those with TestUnit installed)
112
+ * Internal directory layout change
113
+ * uptime.c is now split into unix.c and windows.c (and linked appropriately)
114
+ * Changelog and Manifest are now CHANGES and MANIFEST, respectively
115
+ * Many changes to extconf.rb
116
+
117
+ == 0.1.3 - 6-Jan-2003
118
+ * Added a VERSION class method
119
+ * Added a copyright notice
120
+ * Fixed up the docs a bit and moved them to the doc directory
121
+ * Changed the tarball name to match the RAA package name
122
+ * Modified test.rb script to make it better
123
+ * Changed install instructions slightly
124
+
125
+ == 0.1.2 - 25-Aug-2002
126
+ * Slight change to preprocessor commands to avoid redefining CLK_TCK on
127
+ those systems that define it in time.h
128
+ * Added an INSTALL file
129
+
130
+ == 0.1.1 - 21-Jun-2002
131
+ * The CLK_TCK constant wasn't necessarily being set correctly, which could
132
+ lead to some odd results. This has been fixed.
133
+
134
+ == 0.1.0 - 17-Jun-2002
135
+ * Initial release
data/MANIFEST ADDED
@@ -0,0 +1,13 @@
1
+ * CHANGES
2
+ * MANIFEST
3
+ * Rakefile
4
+ * README
5
+ * install.rb
6
+ * sys-uptime.gemspec
7
+ * doc/uptime.txt
8
+ * examples/test.rb
9
+ * ext/extconf.rb
10
+ * ext/sys/uptime.c
11
+ * lib/sys/linux.rb
12
+ * lib/sys/windows.rb
13
+ * test/test_sys_uptime.rb
data/README ADDED
@@ -0,0 +1,14 @@
1
+ = Description
2
+ A Ruby interface for getting system uptime information.
3
+
4
+ = Prerequisites
5
+ Ruby 1.8.0 or later.
6
+ Ruby 1.8.2 or later is recommended on MS Windows.
7
+ A C compiler, except for MS Windows.
8
+
9
+ = Installation
10
+ rake test (optional)
11
+ rake install (non-gem) or rake install_gem (gem).
12
+
13
+ == Notes
14
+ For additional documentation see doc/uptime.txt.
data/doc/uptime.txt ADDED
@@ -0,0 +1,99 @@
1
+ == Synopsis
2
+ require 'sys/uptime'
3
+ include Sys
4
+
5
+ p Uptime.days
6
+ p Uptime.hours
7
+ p Uptime.minutes
8
+ p Uptime.seconds
9
+ p Uptime.dhms.join(', ')
10
+ p Uptime.uptime
11
+ p Uptime.boot_time
12
+
13
+ == Description
14
+ This package provides uptime and boot time information, similar to the
15
+ 'uptime' Unix command.
16
+
17
+ == Constants
18
+ VERSION
19
+ Returns the current version number of this package (as a string).
20
+
21
+ == Class Methods
22
+ Uptime.boot_time
23
+ Returns the boot time as a Time object.
24
+
25
+ Uptime.days
26
+ Returns the total number of days the system has been up.
27
+
28
+ Uptime.hours
29
+ Returns the total number of hours the system has been up.
30
+
31
+ Uptime.minutes
32
+ Returns the total number of minutes the system has been up.
33
+
34
+ Uptime.seconds
35
+ Returns the total number of seconds the system has been up.
36
+
37
+ Uptime.dhms
38
+ Calculates and returns the number of days, hours, minutes and
39
+ seconds the system has been running as a four-element Array.
40
+
41
+ Uptime.uptime
42
+ Calculates and returns the number of days, hours, minutes and
43
+ seconds the system has been running as a colon-separated string.
44
+
45
+ == Exceptions
46
+ Uptime::Error
47
+ Raised if something goes wrong. On Unix, this would likely mean a
48
+ failure of the times() function. That would be highly unusual.
49
+
50
+ On Windows, it probably means you failed to connect to WMI properly. The
51
+ mostly likely reason would be that the WMI service wasn't running.
52
+
53
+ == Notes
54
+ On MS Windows each of the class methods optionally takes a host name as
55
+ a single argument. The default is localhost (or whatever the result of
56
+ Socket.gethostname returns).
57
+
58
+ The current time, users and load average are NOT included in this
59
+ module, even though you may be used to seeing them with the command
60
+ line version of 'uptime'. This is because these things have
61
+ _absolutely nothing_ to do with uptime (at least, not as I
62
+ logically think of uptime).
63
+
64
+ This package was tested successfully on a Solaris system with over 1600
65
+ days of uptime.
66
+
67
+ == Known Bugs
68
+ None that I am aware of. Please log any bugs you find on the project
69
+ website at http://www.rubyforge.org/projects/sysutils.
70
+
71
+ == Questions
72
+ "Doesn't Struct::Tms do this?" - No.
73
+
74
+ == License
75
+ Ruby's
76
+
77
+ == Copyright
78
+ Copyright 2002-2008, Daniel J. Berger
79
+
80
+ All Rights Reserved. This module is free software. It may be used,
81
+ redistributed and/or modified under the same terms as Ruby itself.
82
+
83
+ == Warranty
84
+ This library is provided "as is" and without any express or
85
+ implied warranties, including, without limitation, the implied
86
+ warranties of merchantability and fitness for a particular purpose.
87
+
88
+ == Acknowledgements
89
+ Mike Hall for help with the BSD side of things.
90
+ Ola Eriksson, whose source code I shamelessly plagiarized to get a better
91
+ implementation for systems that have the utmpx.h header file.
92
+
93
+ == Author
94
+ Daniel J. Berger
95
+ djberg96 at nospam at gmail dot com
96
+ imperator on IRC (Freenode)
97
+
98
+ == See Also
99
+ uptime
data/lib/sys/uptime.rb ADDED
@@ -0,0 +1,158 @@
1
+ require 'win32ole'
2
+ require 'socket'
3
+ require 'date'
4
+ require 'time'
5
+
6
+ # The Sys module serves as a namespace only.
7
+ module Sys
8
+
9
+ # The Uptime class encapsulates various bits of information regarding your
10
+ # system's uptime, including boot time.
11
+ class Uptime
12
+
13
+ # Error typically raised in one of the Uptime methods should fail.
14
+ class Error < StandardError; end
15
+
16
+ # The version of this library.
17
+ VERSION = '0.5.2'
18
+
19
+ # Returns the boot time as a Time object.
20
+ #
21
+ # Example:
22
+ #
23
+ # Sys::Uptime.boot_time # => Fri Dec 12 20:18:58 -0700 2008
24
+ #
25
+ def self.boot_time(host=Socket.gethostname)
26
+ cs = "winmgmts://#{host}/root/cimv2"
27
+ begin
28
+ wmi = WIN32OLE.connect(cs)
29
+ rescue WIN32OLERuntimeError => e
30
+ raise Error, e
31
+ else
32
+ query = "select LastBootupTime from Win32_OperatingSystem"
33
+ results = wmi.ExecQuery(query)
34
+ results.each{ |ole|
35
+ time_array = parse_ms_date(ole.LastBootupTime)
36
+ return Time.mktime(*time_array)
37
+ }
38
+ end
39
+ end
40
+
41
+ # Calculates and returns the number of days, hours, minutes and
42
+ # seconds the +host+ has been running as a colon-separated string.
43
+ #
44
+ # The localhost is used if no +host+ is provided.
45
+ #
46
+ # Example:
47
+ #
48
+ # Sys::Uptime.uptime # => "1:9:55:11"
49
+ #
50
+ def self.uptime(host=Socket.gethostname)
51
+ get_dhms(host).join(':')
52
+ end
53
+
54
+ # Calculates and returns the number of days, hours, minutes and
55
+ # seconds the +host+ has been running as a four-element Array.
56
+ # The localhost is used if no +host+ is provided.
57
+ #
58
+ # Example:
59
+ #
60
+ # Sys::Uptime.dhms # => [1, 9, 55, 11]
61
+ #
62
+ def self.dhms(host=Socket.gethostname)
63
+ get_dhms(host)
64
+ end
65
+
66
+ # Returns the total number of days the system has been up on +host+,
67
+ # or the localhost if no host is provided.
68
+ #
69
+ # Example:
70
+ #
71
+ # Sys::Uptime.days # => 1
72
+ #
73
+ def self.days(host=Socket.gethostname)
74
+ hours(host) / 24
75
+ end
76
+
77
+ # Returns the total number of hours the system has been up on +host+,
78
+ # or the localhost if no host is provided.
79
+ #
80
+ # Example:
81
+ #
82
+ # Sys::Uptime.hours # => 33
83
+ #
84
+ def self.hours(host=Socket.gethostname)
85
+ minutes(host) / 60
86
+ end
87
+
88
+ # Returns the total number of minutes the system has been up on +host+,
89
+ # or the localhost if no host is provided.
90
+ #
91
+ # Example:
92
+ #
93
+ # Sys::Uptime.minutes # => 1980
94
+ #
95
+ def self.minutes(host=Socket.gethostname)
96
+ seconds(host) / 60
97
+ end
98
+
99
+ # Returns the total number of seconds the system has been up on +host+,
100
+ # or the localhost if no host is provided.
101
+ #
102
+ # Example:
103
+ #
104
+ # Sys::Uptime.seconds # => 118800
105
+ #
106
+ def self.seconds(host=Socket.gethostname)
107
+ get_seconds(host)
108
+ end
109
+
110
+ private
111
+
112
+ # Converts a string in the format '20040703074625.015625-360' into a
113
+ # Ruby Time object.
114
+ #
115
+ def self.parse_ms_date(str)
116
+ return if str.nil?
117
+ return Time.parse(str.split('.').first)
118
+ end
119
+
120
+ # Get the actual days, hours, minutes and seconds since boot using WMI.
121
+ #
122
+ def self.get_dhms(host)
123
+ seconds = get_seconds(host)
124
+
125
+ days = (seconds / 86400).to_i
126
+ seconds -= days * 86400
127
+ hours = seconds / 3600
128
+ seconds -= hours * 3600
129
+ minutes = seconds / 60
130
+ seconds -= minutes * 60
131
+
132
+ [days, hours, minutes, seconds]
133
+ end
134
+
135
+ # Returns the number of seconds since boot.
136
+ #
137
+ def self.get_seconds(host)
138
+ cs = "winmgmts://#{host}/root/cimv2"
139
+ begin
140
+ wmi = WIN32OLE.connect(cs)
141
+ rescue WIN32OLERuntimeError => e
142
+ raise Error, e
143
+ else
144
+ query = "select LastBootupTime from Win32_OperatingSystem"
145
+ results = wmi.ExecQuery(query)
146
+ now = Time.now
147
+
148
+ results.each{ |ole|
149
+ time_array = parse_ms_date(ole.LastBootupTime)
150
+ boot_time = Time.mktime(*time_array)
151
+ break
152
+ }
153
+ end
154
+
155
+ (now - boot_time).to_i
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,65 @@
1
+ #####################################################################
2
+ # tc_uptime.rb
3
+ #
4
+ # Test suite for sys-uptime. This should generally be run via the
5
+ # 'rake test' task, since it handles the pre-setup code for you.
6
+ #####################################################################
7
+ require 'sys/uptime'
8
+ require 'test/unit'
9
+ include Sys
10
+
11
+ class TC_Uptime < Test::Unit::TestCase
12
+ def test_version
13
+ assert_equal('0.5.2', Uptime::VERSION)
14
+ end
15
+
16
+ def test_seconds
17
+ assert_respond_to(Uptime, :seconds)
18
+ assert_nothing_raised{ Uptime.seconds }
19
+ assert_kind_of(Fixnum, Uptime.seconds)
20
+ assert_equal(true, Uptime.seconds > 0)
21
+ end
22
+
23
+ def test_minutes
24
+ assert_respond_to(Uptime, :minutes)
25
+ assert_nothing_raised{ Uptime.minutes }
26
+ assert_kind_of(Fixnum, Uptime.minutes)
27
+ end
28
+
29
+ def test_hours
30
+ assert_respond_to(Uptime, :hours)
31
+ assert_nothing_raised{ Uptime.hours }
32
+ assert_kind_of(Fixnum, Uptime.hours)
33
+ end
34
+
35
+ def test_days
36
+ assert_respond_to(Uptime,:days)
37
+ assert_nothing_raised{ Uptime.days }
38
+ assert_kind_of(Fixnum, Uptime.days)
39
+ end
40
+
41
+ def test_uptime
42
+ assert_respond_to(Uptime,:uptime)
43
+ assert_nothing_raised{ Uptime.uptime }
44
+ assert_kind_of(String, Uptime.uptime)
45
+ assert_equal(false, Uptime.uptime.empty?)
46
+ end
47
+
48
+ def test_dhms
49
+ assert_respond_to(Uptime,:dhms)
50
+ assert_nothing_raised{ Uptime.dhms }
51
+ assert_kind_of(Array, Uptime.dhms)
52
+ assert_equal(false, Uptime.dhms.empty?)
53
+ assert_equal(4, Uptime.dhms.length)
54
+ end
55
+
56
+ def test_boot_time
57
+ assert_respond_to(Uptime,:boot_time)
58
+ assert_nothing_raised{ Uptime.boot_time }
59
+ assert_kind_of(Time, Uptime.boot_time)
60
+ end
61
+
62
+ def test_uptime_error
63
+ assert_kind_of(StandardError, Uptime::Error.new)
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys-uptime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: x86-mswin32-60
6
+ authors:
7
+ - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A Ruby interface for getting system uptime information.
17
+ email: djberg96@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGES
24
+ - README
25
+ - MANIFEST
26
+ - doc/uptime.txt
27
+ files:
28
+ - doc/uptime.txt
29
+ - test/test_sys_uptime.rb
30
+ - CHANGES
31
+ - README
32
+ - MANIFEST
33
+ - lib/sys/uptime.rb
34
+ has_rdoc: true
35
+ homepage: http://www.rubyforge.org/projects/sysutils
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.2
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project: sysutils
56
+ rubygems_version: 1.3.1
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: A Ruby interface for getting system uptime information.
60
+ test_files:
61
+ - test/test_sys_uptime.rb