]> git.vpit.fr Git - perl/modules/Linux-SysInfo.git/blob - lib/Linux/SysInfo.pm
Importing Linux-SysInfo-0.09.tar.gz
[perl/modules/Linux-SysInfo.git] / lib / Linux / SysInfo.pm
1 package Linux::SysInfo;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Linux::SysInfo - Perl interface to the sysinfo(2) Linux system call.
9
10 =head1 VERSION
11
12 Version 0.09
13
14 =cut
15
16 our $VERSION;
17 BEGIN {
18  $VERSION = '0.09';
19 }
20
21 =head1 SYNOPSIS
22
23     use Linux::SysInfo qw/sysinfo/;
24
25     my $si = sysinfo;
26     print "$_: $si->{$_}\n" for keys %$si;
27
28 =head1 DESCRIPTION
29
30 This module is a wrapper around the sysinfo(2) Linux system call. It gives information about the current uptime, load average, memory usage and processes running. Other systems have also this system call (e.g. Solaris), but in most cases the returned information is different.
31
32 =head1 CONSTANTS
33
34 =head2 C<LS_HAS_EXTENDED>
35
36 This constant is set to 1 if your kernel supports the three extended fields C<totalhigh>, C<freehigh> and C<mem_unit> ; and to 0 otherwise.
37
38 =head1 FUNCTIONS
39
40 =cut
41
42 BEGIN {
43  require XSLoader;
44  XSLoader::load(__PACKAGE__, $VERSION);
45 }
46
47 =head2 C<sysinfo>
48
49 This function takes no argument. It returns undef on failure or a hash reference whose keys are the members name of the struct sysinfo on success :
50
51 =over 4
52
53 =item C<uptime>
54
55 Seconds elapsed since the system booted.
56
57 =item C<load1>, C<load5>, C<load15>
58
59 1, 5 and 15 minutes load average.
60
61 =item C<totalram>
62
63 Total usable main memory size.
64
65 =item C<freeram>
66
67 Available memory size.
68
69 =item C<sharedram>
70
71 Amount of shared memory.
72
73 =item C<bufferram>
74
75 Memory used by buffers.
76
77 =item C<totalswap>
78
79 Total swap space size.
80
81 =item C<freeswap>
82
83 Swap space stil available.
84
85 =item C<procs>
86
87 Number of current processes.
88
89 =back
90
91 Prior to Linux 2.3.23 on i386 and 2.3.48 on all other architectures, the memory sizes were given in bytes. Since then, the following members are also available and all the memory sizes are given as multiples of mem_unit bytes :
92
93 =over 4
94
95 =item C<totalhigh>
96
97 Total high memory size.
98
99 =item C<freehigh>
100
101 Available high memory size.
102
103 =item C<mem_unit>
104
105 Memory unit size in bytes.
106
107 =back
108
109 =head1 EXPORT
110
111 The only function of this module, C<sysinfo>, and the constant C<LS_HAS_EXTENDED> are only exported on request. Functions are also exported by the C<:funcs> tag, and constants by C<:consts>.
112
113 =cut
114
115 use base qw/Exporter/;
116
117 our @EXPORT         = ();
118 our %EXPORT_TAGS    = (
119  'funcs'  => [ qw/sysinfo/ ],
120  'consts' => [ qw/LS_HAS_EXTENDED/ ]
121 );
122 our @EXPORT_OK      = map { @$_ } values %EXPORT_TAGS;
123 $EXPORT_TAGS{'all'} = [ @EXPORT_OK ];
124
125 =head1 BINARY COMPATIBILITY
126
127 If you upgrade your kernel to a greater version than 2.3.23 on i386 or 2.3.48 on any other platform, you will need to rebuild the module to access the extended fields.
128
129 Moreover, since the perl hash function has changed after the 5.6 version, you will also need to recompile the module if you upgrade your perl from a version earlier than 5.6.
130
131 =head1 SEE ALSO
132
133 The C<sysinfo(2)> man page.
134
135 L<Sys::Info> : Gather information about your system.
136
137 L<Sys::CpuLoad> : Try several different methods to retrieve the load average.
138
139 L<BSD::getloadavg> : Wrapper to the C<getloadavg(3)> BSD system call.
140
141 =head1 AUTHOR
142
143 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
144
145 You can contact me by mail or on #perl @ FreeNode (vincent or Prof_Vince).
146
147 =head1 BUGS
148
149 Please report any bugs or feature requests to
150 C<bug-linux-sysinfo at rt.cpan.org>, or through the web interface at
151 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Linux-SysInfo>.
152 I will be notified, and then you'll automatically be notified of progress on
153 your bug as I make changes.
154
155 =head1 SUPPORT
156
157 You can find documentation for this module with the perldoc command.
158
159     perldoc Linux::SysInfo
160
161 =head1 COPYRIGHT & LICENSE
162
163 Copyright 2007-2008 Vincent Pit, all rights reserved.
164
165 This program is free software; you can redistribute it and/or modify it
166 under the same terms as Perl itself.
167
168 =cut
169
170 1; # End of Linux::SysInfo