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