added base pod to all probes
[scpubgit/System-Introspector.git] / lib / System / Introspector / FileHandles.pm
1 package System::Introspector::FileHandles;
2 use Moo;
3
4 sub gather {
5     my ($self) = @_;
6     my $pipe = $self->_open_lsof_pipe;
7     my @handles;
8     while (defined( my $line = <$pipe> )) {
9         chomp $line;
10         my @fields = split m{\0}, $line;
11         push @handles, { map {
12             m{^(.)(.*)$};
13             ($1, $2);
14         } @fields };
15     }
16     return \@handles;
17 }
18
19 sub _open_lsof_pipe {
20     my ($self) = @_;
21     my $command = 'lsof -F0';
22     open my $pipe, '-|', $command
23         or die "Unable to open pipe to '$command': $!\n";
24     return $pipe;
25 }
26
27 1;
28
29 __END__
30
31 =head1 NAME
32
33 System::Introspector::FileHandles - Gather opened filehandles
34
35 =head1 DESCRIPTION
36
37 Uses C<lsof> to build a list of open filehandles.
38
39 =head1 SEE ALSO
40
41 =over
42
43 =item L<System::Introspector>
44
45 =back
46
47 =cut
48