| 1 | package Monitoring::Sneck::Checks::file_handles; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use parent 'Monitoring::Sneck::Checks::base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Monitoring::Sneck::Checks::file_handles - checks how many files are open against the limit | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Version 0.0.1 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | file_handles|perl:file_handles | ||||||||||||||||||||||||||||
| 23 | file_handles_tight|perl:file_handles -w 60 -c 80 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Checks the percent of the system wide limit on open files in use, as | ||||||||||||||||||||||||||||
| 28 | running out stops anything from opening a file or socket. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | On Linux it is from /proc/sys/fs/file-nr, and on FreeBSD from | ||||||||||||||||||||||||||||
| 31 | kern.openfiles and kern.maxfiles through L<BSD::Sysctl>. Other OSes are | ||||||||||||||||||||||||||||
| 32 | UNKNOWN. Newer Linux kernels may have a limit so high that this never | ||||||||||||||||||||||||||||
| 33 | alerts, in which case the limit per process is what matters. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | - -w, --warning :: Range of percent used. | ||||||||||||||||||||||||||||
| 38 | Default :: 80 | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | - -c, --critical :: Range of percent used. | ||||||||||||||||||||||||||||
| 41 | Default :: 90 | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | sub option_spec { return ( 'warning|w=s', 'critical|c=s' ) } | ||||||||||||||||||||||||||
|
Subroutine
option_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | sub defaults { return { warning => '80', critical => '90' } } | ||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 3 | ▶ | sub ranges { return ( 'warning', 'critical' ) } | ||||||||||||||||||||||||||
|
Subroutine
ranges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 METHODS | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head2 check | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | Does the check. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | my ( $open, $max ) = $self->handles; | |||||||||||||||||||||||||||
| 63 | 2 | ▶ | die("the limit is 0\n") if !$max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 2 | my $percent = sprintf( '%.1f', $open / $max * 100 ); | |||||||||||||||||||||||||||
| 65 | 2 | $self->perfdata( | |||||||||||||||||||||||||||
| 66 | label => 'used', | ||||||||||||||||||||||||||||
| 67 | value => $percent, | ||||||||||||||||||||||||||||
| 68 | uom => '%', | ||||||||||||||||||||||||||||
| 69 | warning => $self->opt('warning'), | ||||||||||||||||||||||||||||
| 70 | critical => $self->opt('critical'), | ||||||||||||||||||||||||||||
| 71 | min => 0, | ||||||||||||||||||||||||||||
| 72 | max => 100 | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | 2 | $self->perfdata( label => 'open', value => $open, min => 0, max => $max ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | return $self->finish( $self->threshold_status( $percent, $self->opt('warning'), $self->opt('critical') ), | |||||||||||||||||||||||||||
| 77 | $percent . '% used, ' . $open . ' of ' . $max . ' open' ); | ||||||||||||||||||||||||||||
| 78 | } ## end sub check | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head2 handles | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Returns the open files and the limit. Dies if they can not be found. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | ▶ | sub handles { | ||||||||||||||||||||||||||
|
Subroutine
handles: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | if ( $self->os eq 'linux' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # allocated, allocated but not used, which is 0 on newer kernels, and the limit | ||||||||||||||||||||||||||||
| 92 | 1 | my ( $allocated, $unused, $max ) = split( /\s+/, $self->proc_file('sys/fs/file-nr') ); | |||||||||||||||||||||||||||
| 93 | 1 | ▶ | die("can not make sense of /proc/sys/fs/file-nr\n") if !defined($max) || $max !~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $max and $max =~ /\A[0-9]+\z/u
MC/DC0%0/2
defined $max and $max =~ /\A[0-9]+\z/u
defined $max
$max =~ /\A[0-9]+\z/u
Truth table33%1/3
A and B
A= defined $maxB= $max =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||
| 94 | 1 | return ( $allocated - $unused, $max ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 2 | ▶ | if ( $self->os eq 'freebsd' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 1 | return ( $self->sysctl('kern.openfiles'), $self->sysctl('kern.maxfiles') ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | die( 'not supported on ' . $self->os . "\n" ); | |||||||||||||||||||||||||||
| 101 | } ## end sub handles | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | 1; | |||||||||||||||||||||||||||