line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unix::Uptime; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
127954
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
303
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
1265
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION='0.3701'; |
7
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my %modules = ( |
10
|
|
|
|
|
|
|
freebsd => 'BSD', |
11
|
|
|
|
|
|
|
dragonfly => 'BSD', |
12
|
|
|
|
|
|
|
linux => 'Linux', |
13
|
|
|
|
|
|
|
openbsd => 'BSD', |
14
|
|
|
|
|
|
|
darwin => 'BSD', |
15
|
|
|
|
|
|
|
netbsd => 'BSD', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $module = $modules{$^O} |
19
|
|
|
|
|
|
|
or die "Operating system type $^O is currently unsupported"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
require "Unix/Uptime/$module.pm"; |
22
|
|
|
|
|
|
|
our @ISA = ("Unix::Uptime::$module"); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $hires; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _want_hires { |
27
|
2
|
|
|
2
|
|
5
|
my $class = shift; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
11
|
return $hires; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import { |
33
|
4
|
|
|
4
|
|
32
|
my $class = shift; |
34
|
4
|
100
|
|
|
|
5281
|
if (grep {$_ eq ':hires'} @_) { |
|
1
|
|
|
|
|
16
|
|
35
|
1
|
|
|
|
|
1
|
$hires = 1; |
36
|
1
|
|
|
|
|
3
|
$module = "Unix::Uptime::$module"; |
37
|
1
|
50
|
|
|
|
2118
|
$module->can('load_hires') |
38
|
|
|
|
|
|
|
and $module->load_hires(); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Unix::Uptime - Determine the current uptime, in seconds, and load |
47
|
|
|
|
|
|
|
averages, across different *NIX architectures |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Standard Usage |
52
|
|
|
|
|
|
|
use Unix::Uptime; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $uptime = Unix::Uptime->uptime(); # 2345 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# "HiRes" mode |
57
|
|
|
|
|
|
|
use Unix::Uptime qw(:hires); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $uptime = Unix::Uptime->uptime_hires(); # 2345.123593 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Load Average |
62
|
|
|
|
|
|
|
my ($load1, $load5, $load15) = Unix::Uptime->load(); # (1.0, 2.0, 0.0) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This is a rather simple module that abstracts the task of figuring out |
67
|
|
|
|
|
|
|
the current system uptime, in seconds. It was born out of a desire to do |
68
|
|
|
|
|
|
|
this on non-Linux systems, without SNMP. If you want to use SNMP, there |
69
|
|
|
|
|
|
|
are pleanty of modules on CPAN already. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Additionally, since version 0.33_02, it supports retrieving the load |
72
|
|
|
|
|
|
|
average. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Currently, this module just supports Linux, FreeBSD, Darwin (Mac OS X), |
75
|
|
|
|
|
|
|
OpenBSD, and NetBSD. It should be easy enough to add support for other |
76
|
|
|
|
|
|
|
operating systems, though. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 OPTIONS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
While this module doesn't provide any functions for exporting, if the |
81
|
|
|
|
|
|
|
tag C<:hires> is given, then uptime_hires static method will be |
82
|
|
|
|
|
|
|
available. It returns decimal numbers when possible, but on some systems |
83
|
|
|
|
|
|
|
it is simply an alias for C. This will likely |
84
|
|
|
|
|
|
|
require the Time::HiRes module to be available. Otherwise, they will |
85
|
|
|
|
|
|
|
simply be whole seconds. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The following static (class) methods are available: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 uptime |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This takes no arguments, and simply returns the number of seconds this |
94
|
|
|
|
|
|
|
system has been running. This will always be an integer. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 uptime_hires |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is only available if the C<:hires> import tag is used. It returns |
99
|
|
|
|
|
|
|
the system uptime with a greater resolution than one second on supported |
100
|
|
|
|
|
|
|
platforms. On some platforms, its results may not be any more precise |
101
|
|
|
|
|
|
|
than C, though. On different platforms, this requires |
102
|
|
|
|
|
|
|
different additional modules: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item Linux |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
No additional requirements. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item FreeBSD |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Requires Time::HiRes |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item Darwin, OpenBSD, NetBSD |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
No more precise than uptime() |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 load |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This returns an array of the load averages for the last 1, 5, and 15 |
123
|
|
|
|
|
|
|
minutes. The degree of precision varies from system to system. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L(3) and L(3) for Linux-specific implementations. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L for Win32. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 BUGS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This currently doesn't support more than Linux, FreeBSD, Darwin (Mac OS |
134
|
|
|
|
|
|
|
X), OpenBSD, and NetBSD. Contributions for other operating systems would |
135
|
|
|
|
|
|
|
be welcome. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 CAVEATS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
B This module is still a work in progress, under fairly heavy |
140
|
|
|
|
|
|
|
development. While I think the final API should be mostly finalized at |
141
|
|
|
|
|
|
|
this point, I won't commit to an API freeze until version 1.0. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 CONTRIBUTING |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This project is developed using git. The repository may be browsed at: |
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Patches in git-format-patch style are preferred. Either send them to me |
149
|
|
|
|
|
|
|
by email, or open an RT ticket |
150
|
|
|
|
|
|
|
L. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Mike Kelly |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Copyright (C) 2008-2009, Mike Kelly. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
161
|
|
|
|
|
|
|
under the same terms as Perl 5.10.0. For more details, see the full text |
162
|
|
|
|
|
|
|
of the licenses at , |
163
|
|
|
|
|
|
|
and . |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is distributed in the hope that it will be |
166
|
|
|
|
|
|
|
useful, but without any warranty; without even the implied |
167
|
|
|
|
|
|
|
warranty of merchantability or fitness for a particular purpose. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# vim: set ft=perl sw=4 sts=4 et : |