File Coverage

blib/lib/DBD/Sys/Plugin/Any/FileSysDf.pm
Criterion Covered Total %
statement 13 36 36.1
branch 0 8 0.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 3 3 100.0
total 21 56 37.5


line stmt bran cond sub pod time code
1             package DBD::Sys::Plugin::Any::FileSysDf;
2              
3 3     3   2442 use strict;
  3         7  
  3         100  
4 3     3   15 use warnings;
  3         5  
  3         105  
5              
6 3     3   14 use vars qw($VERSION @colNames);
  3         4  
  3         157  
7              
8 3     3   28 use base qw(DBD::Sys::Table);
  3         5  
  3         1194  
9              
10             =pod
11              
12             =head1 NAME
13              
14             DBD::Sys::Plugin::Any::FileSysDf - provides a table containing the free space of file systems
15              
16             =head1 SYNOPSIS
17              
18             $filesysdf = $dbh->selectall_hashref("select * from filesysdf", "mountpoint");
19              
20             =head1 ISA
21              
22             DBD::Sys::Plugin::Any::FileSysDf
23             ISA DBD::Sys::Table
24              
25             =cut
26              
27             my $haveFilesysDf;
28              
29             $VERSION = "0.102";
30             @colNames = qw(mountpoint blocks bfree bavail bused bper files ffree favail fused fper);
31              
32             =head1 DESCRIPTION
33              
34             This module provides the table which contains the free space
35             on file systems.
36              
37             =head2 COLUMNS
38              
39             =head3 mountpoint
40              
41             The friendly name of the filesystem. This will usually be the same
42             name as appears in the list returned by the filesystems() method.
43              
44             =head3 blocks
45              
46             Total blocks existing on the filesystem.
47              
48             =head3 bfree
49              
50             Total blocks free existing on the filesystem.
51              
52             =head3 bavail
53              
54             Total blocks available to the user executing the Perl application.
55             This can be different than C if you have per-user quotas on
56             the filesystem, or if the super user has a reserved amount.
57             C can also be a negative value because of this. For instance
58             if there is more space being used then you have available to you.
59              
60             =head3 bused
61              
62             Total blocks used existing on the filesystem.
63              
64             =head3 bper
65              
66             Percent of disk space used. This is based on the disk space available
67             to the user executing the application. In other words, if the filesystem
68             has 10% of its space reserved for the superuser, then the percent used
69             can go up to 110%.
70              
71             =head3 files
72              
73             Total inodes existing on the filesystem.
74              
75             =head3 ffree
76              
77             Total inodes free existing on the filesystem.
78              
79             =head3 favail
80              
81             Total inodes available to the user executing the application.
82             See the information for the C column.
83              
84             =head3 fused
85              
86             Total inodes used existing on the filesystem.
87              
88             =head3 fper
89              
90             Percent of inodes used on the filesystem.
91             See the information for the C column.
92              
93             =head1 METHODS
94              
95             =head2 get_col_names
96              
97             Returns the column names of the table as named in L
98              
99             =cut
100              
101 0     0 1 0 sub get_col_names() { return @colNames }
102              
103             =head2 get_attributes
104              
105             Return the attributes supported by this module:
106              
107             =head3 blocksize
108              
109             Allows to specify the blocksize of the returned free blocks.
110             This defaults to 1.
111              
112             $dbh->{sys_filesysdf_blocksize} = 512; # use UNIX typical blocksize for df
113              
114             =cut
115              
116 4     4 1 16 sub get_attributes() { return qw(blocksize) }
117              
118             =head2 collect_data
119              
120             Retrieves the mountpoints of mounted file systems from L
121             and determine the free space on their devices using L.
122             The mountpoint and the free space information are put in fetchable rows.
123              
124             =cut
125              
126             sub collect_data()
127             {
128 0     0 1   my $self = $_[0];
129 0           my @data;
130              
131 0 0         unless ( defined($haveFilesysDf) )
132             {
133 0           $haveFilesysDf = 0;
134 0           eval {
135 0           require Sys::Filesystem;
136 0           require Filesys::DfPortable;
137 0           $haveFilesysDf = 1;
138             };
139 0 0         Filesys::DfPortable->import() if ($haveFilesysDf);
140             }
141              
142 0 0         if ($haveFilesysDf)
143             {
144 0           my $fs = Sys::Filesystem->new();
145 0           my @filesystems = $fs->filesystems( mounted => 1 );
146 0   0       my $blocksize = $self->{meta}->{blocksize} || 1;
147              
148 0           foreach my $filesys (@filesystems)
149             {
150 0           my @row;
151 0           my $mountpt = $fs->mount_point($filesys);
152 0           my $df = dfportable( $mountpt, $blocksize );
153 0 0         if ( defined($df) )
154             {
155             @row = (
156             $fs->mount_point($filesys),
157             @$df{
158 0           'blocks', 'bfree', 'bavail', 'bused', 'per', 'files',
159             'ffree', 'favail', 'fused', 'fper'
160             }
161             );
162             }
163             else
164             {
165 0           @row = ( $fs->mount_point($filesys), (undef) x 10 );
166             }
167 0           push( @data, \@row );
168             }
169             }
170              
171 0           return \@data;
172             }
173              
174             =head1 PREREQUISITES
175              
176             L and L are required in order to
177             fill the table C with data.
178              
179             =head1 AUTHOR
180              
181             Jens Rehsack Alexander Breibach
182             CPAN ID: REHSACK
183             rehsack@cpan.org alexander.breibach@googlemail.com
184             http://www.rehsack.de/
185              
186             =head1 COPYRIGHT
187              
188             This program is free software; you can redistribute
189             it and/or modify it under the same terms as Perl itself.
190              
191             The full text of the license can be found in the
192             LICENSE file included with this module.
193              
194             =head1 SUPPORT
195              
196             Free support can be requested via regular CPAN bug-tracking system. There is
197             no guaranteed reaction time or solution time, but it's always tried to give
198             accept or reject a reported ticket within a week. It depends on business load.
199             That doesn't mean that ticket via rt aren't handles as soon as possible,
200             that means that soon depends on how much I have to do.
201              
202             Business and commercial support should be acquired from the authors via
203             preferred freelancer agencies.
204              
205             =cut
206              
207             1;