blib/lib/Monitoring/Sneck/Checks/pressure.pm

filter: Statementstmt 100% 53 / 53 Branchbran 81.2% 13 / 16 Conditioncond 80.9% 17 / 21 MC/DCmcdc 58.3% 7 / 12 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 89.6% 104 / 116 CC 19 SCAR 20.7
CC
19
Cov
92%
check
11.4
validate
9.0
BEGIN
1.0
CRAP 7.9
« blib/lib/Monitoring/Sneck/Checks/sshd_config.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/pid_file.pm »
1 package Monitoring::Sneck::Checks::pressure;
2  
3 12 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use parent 'Monitoring::Sneck::Checks::base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Monitoring::Sneck::Checks::pressure - checks Linux pressure stall information
11  
12 =head1 VERSION
13  
14 Version 0.0.1
15  
16 =cut
17  
18 12 our $VERSION = '0.0.1';
19  
20 # What may be checked.
21 12 our @RESOURCES = ( 'cpu', 'memory', 'io' );
22  
23 =head1 SYNOPSIS
24  
25 pressure|perl:pressure
26 memory_pressure|perl:pressure -r memory -k full -w 5 -c 20
27 io_pressure|perl:pressure -r io --io-warning 30 --io-critical 60 -a 300
28  
29 =head1 DESCRIPTION
30  
31 Checks the percent of time tasks were stalled waiting on CPU, memory,
32 or IO, from /proc/pressure. This tells being short of each apart in a
33 way load does not.
34  
35 Each resource has some, the time at least one task was stalled, and
36 full, the time all were at once, which is the worse. Each is averaged
37 over 10, 60, and 300 seconds. full for CPU is always 0 for the system
38 as a whole, so it is left out.
39  
40 Only Linux 4.20 and later have this, and only if not turned off with
41 psi=0. Others are UNKNOWN.
42  
43 =head1 OPTIONS
44  
45 - -r, --resource :: cpu, memory, or io. May be given more than once.
46 Default :: all three
47  
48 - -k, --kind :: some or full.
49 Default :: some
50  
51 - -a, --average :: 10, 60, or 300 seconds.
52 Default :: 60
53  
54 - -w, --warning :: Range of percent stalled.
55 Default :: 20
56  
57 - -c, --critical :: Range of percent stalled.
58 Default :: 50
59  
60 - --cpu-warning, --cpu-critical, --memory-warning, --memory-critical,
61 --io-warning, --io-critical :: The same, for only that resource.
62  
63 =cut
64  
65 80 ▶sub option_spec {
Subroutine option_spec: called CC=1 SCAR=0.0
Pod documented
66 return ( 'resource|r=s@', 'kind|k=s', 'average|a=i', 'warning|w=s', 'critical|c=s',
67 80 map { ( $_ . '-warning=s', $_ . '-critical=s' ) } @RESOURCES );
68 }
69  
70 80 ▶sub defaults { return { kind => 'some', average => 60, warning => '20', critical => '50' } }
Subroutine defaults: called CC=1 SCAR=0.0
Pod documented
71  
72 80 ▶sub ranges {
Subroutine ranges: called CC=1 SCAR=0.0
Pod documented
73 80 return ( 'warning', 'critical', map { ( $_ . '-warning', $_ . '-critical' ) } @RESOURCES );
74 }
75  
76 80 ▶sub validate {
Subroutine validate: called CC=9 SCAR=22.0
Pod documented
77 80 my ( $self, $options ) = @_;
78  
79 80 my @problems;
80 80 my %known = map { $_ => 1 } @RESOURCES;
81 80 ▶ foreach my $resource ( @{ $options->{resource} // [] } ) {
Condition100%2/2
$options->{"resource"} // []
l!l
4040
MC/DC100%1/1
$options->{"resource"} // []
$options->{"resource"}
Truth table100%2/2
A
A= $options->{"resource"}
Aresult
11
00
82 50 ▶ push( @problems, '--resource "' . $resource . '" must be cpu, memory, or io' ) if !$known{$resource};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$resource} 10 40 50
83 }
84 80 ▶ push( @problems, '--kind must be some or full' ) if $options->{kind} !~ /\A(?:some|full)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"kind"} =~ /\A(?:some|full)\z/u 0 80 80
85 80 ▶ push( @problems, '--average must be 10, 60, or 300' ) if $options->{average} !~ /\A(?:10|60|300)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"average"} =~ /\A(?:10|60|300)\z/u 10 70 80
86 push( @problems, 'nothing to check, as full is left out for cpu' )
87 if $options->{kind} eq 'full'
88 && defined( $options->{resource} )
89 80 ▶ && !grep { $_ ne 'cpu' } @{ $options->{resource} };
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"kind"} eq "full" and defined $options->{"resource"} and not grep({$_ ne "cpu";} @{$$options{"resource"};}) 10 70 80
Condition100%6/6
$options->{"kind"} eq "full" and defined $options->{"resource"} and not grep({$_ ne "cpu";} @{$$options{"resource"};})
!ll&&!rl&&r
601010
$options->{"kind"} eq "full" and defined $options->{"resource"}
!ll&&!rl&&r
501020
MC/DC100%3/3
$options->{"kind"} eq "full" and defined $options->{"resource"} and not grep({$_ ne "cpu";} @{$$options{"resource"};})
$options->{"kind"} eq "full" defined $options->{"resource"} not grep({$_ ne "cpu";} @{$$options{"resource"};})
Truth table100%4/4
A and B and not(C)
A= $options->{"kind"} eq "full"B= defined $options->{"resource"}C= not grep({$_ ne "cpu";} @{$$options{"resource"};})
ABCresult
0XX0
10X0
1100
1111
90  
91 80 return @problems;
92 } ## end sub validate
93  
94 =head1 METHODS
95  
96 =head2 check
97  
98 Does the check.
99  
100 =cut
101  
102 50 ▶sub check {
Subroutine check: called CC=11 SCAR=24.3
Pod documented
103 50 my ($self) = @_;
104  
105 50 ▶ die( 'not supported on ' . $self->os . "\n" ) if $self->os ne 'linux';
Branch: 1 branch
BranchTrueFalseTotal
if $self->os ne "linux" 0 50 50
106 50 my $kind = $self->opt('kind');
107 50 my $average = 'avg' . $self->opt('average');
108 50 my @codes;
109 my @parts;
110 50 ▶ foreach my $resource ( @{ $self->opt('resource') // \@RESOURCES } ) {
Condition100%2/2
$self->opt("resource") // \@Monitoring::Sneck::Checks::pressure::RESOURCES
l!l
2030
MC/DC100%1/1
$self->opt("resource") // \@Monitoring::Sneck::Checks::pressure::RESOURCES
$self->opt("resource")
Truth table100%2/2
A
A= $self->opt("resource")
Aresult
11
00
111 120 ▶ next if $resource eq 'cpu' && $kind eq 'full';
Branch: 1 branch
BranchTrueFalseTotal
if $resource eq "cpu" and $kind eq "full" 20 100 120
Condition100%3/3
$resource eq "cpu" and $kind eq "full"
!ll&&!rl&&r
802020
MC/DC100%2/2
$resource eq "cpu" and $kind eq "full"
$resource eq "cpu" $kind eq "full"
Truth table100%3/3
A and B
A= $resource eq "cpu"B= $kind eq "full"
ABresult
0X0
100
111
112 100 my $content = eval { $self->proc_file( 'pressure/' . $resource ) };
113 100 ▶ die("this kernel has no pressure stall information\n") if !defined($content);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $content 10 90 100
114 90 my ($line) = $content =~ /^\Q$kind\E (.*)$/m;
115 90 ▶ my %values = ( $line // '' ) =~ /(\w+)=([0-9.]+)/g;
Condition50%1/2
$line // ""
l!l
900
MC/DC0%0/1
$line // ""
$line
Truth table50%1/2
A
A= $line
Aresult
11
00
116 90 ▶ die( 'can not make sense of /proc/pressure/' . $resource . "\n" ) if !defined( $values{$average} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values{$average} 0 90 90
117  
118 90 ▶ my $warning = $self->opt( $resource . '-warning' ) // $self->opt('warning');
Condition66%2/3
$self->opt($resource . '-warning') // $self->opt("warning")
l!l&&r!l&&!r
10800
MC/DC0%0/2
$self->opt($resource . '-warning') // $self->opt("warning")
$self->opt($resource . '-warning') $self->opt("warning")
Truth table66%2/3
A // B
A= $self->opt($resource . '-warning')B= $self->opt("warning")
ABresult
1X1
011
000
119 90 ▶ my $critical = $self->opt( $resource . '-critical' ) // $self->opt('critical');
Condition33%1/3
$self->opt($resource . '-critical') // $self->opt("critical")
l!l&&r!l&&!r
0900
MC/DC0%0/2
$self->opt($resource . '-critical') // $self->opt("critical")
$self->opt($resource . '-critical') $self->opt("critical")
Truth table33%1/3
A // B
A= $self->opt($resource . '-critical')B= $self->opt("critical")
ABresult
1X1
011
000
120 90 my $code = $self->threshold_status( $values{$average}, $warning, $critical );
121 90 push( @codes, $code );
122 90 push( @parts, $resource . ' ' . $values{$average} . '%' );
123 $self->perfdata(
124 label => $resource . '_' . $kind,
125 90 value => $values{$average},
126 uom => '%',
127 warning => $warning,
128 critical => $critical,
129 min => 0,
130 max => 100
131 );
132 } ## end foreach my $resource ( @{ $self->opt('resource'...)})
133  
134 40 return $self->finish( $self->worst(@codes),
135 $kind . ' stalled over ' . $self->opt('average') . ' seconds, ' . join( ', ', @parts ) );
136 } ## end sub check
137  
138 12 1;
« blib/lib/Monitoring/Sneck/Checks/sshd_config.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/pid_file.pm »