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

filter: Statementstmt 100% 69 / 69 Branchbran 93.3% 28 / 30 Conditioncond 73.3% 22 / 30 MC/DCmcdc 50.0% 8 / 16 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 88.8% 143 / 161 CC 30 SCAR 29.3
CC
30
Cov
92%
check
27.6
__ANON__
3.0
__ANON__
2.0
CRAP 18.7
« blib/lib/Monitoring/Sneck/Checks/vrrp.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/apparmor.pm »
1 package Monitoring::Sneck::Checks::edac;
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 3 ▶use File::Slurp qw(read_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Monitoring::Sneck::Checks::edac - checks for memory errors Linux's EDAC has counted
12  
13 =head1 VERSION
14  
15 Version 0.0.1
16  
17 =cut
18  
19 3 our $VERSION = '0.0.1';
20  
21 # Where EDAC is in sysfs. Set by tests.
22 3 our $EDAC = '/sys/devices/system/edac';
23  
24 =head1 SYNOPSIS
25  
26 edac|perl:edac
27 edac_ecc_box|perl:edac -r -w 10 -c 100
28  
29 =head1 DESCRIPTION
30  
31 Reads the corrected and uncorrected memory error counts of each memory
32 controller under /sys/devices/system/edac/mc, without rasdaemon. See
33 L<Monitoring::Sneck::Checks::linux_ras> for that.
34  
35 - CRITICAL :: Any uncorrected errors. Corrected errors over --critical.
36  
37 - WARNING :: Corrected errors over --warning. No memory controllers
38 with --required.
39  
40 - UNKNOWN :: Not being Linux, or a controller's counts not being
41 readable.
42  
43 - OK :: Everything else, including no memory controllers, as on VMs
44 and boxes without ECC or a EDAC driver, so the same check can go
45 everywhere.
46  
47 The counts are since boot, or since they were last reset by writing to
48 reset_counters of the controller.
49  
50 The DIMMs with errors are named, by their label or as mc0 dimm2 if it
51 has none, as are errors EDAC could not tie to a DIMM. A line for each
52 controller follows the status line.
53  
54 =head1 OPTIONS
55  
56 - -w, --warning :: Range for corrected errors.
57 Default :: 0
58  
59 - -c, --critical :: Range for corrected errors.
60  
61 - -r, --required :: WARNING if there are no memory controllers, for
62 boxes that should have ECC and a EDAC driver loaded.
63  
64 =cut
65  
66 9 ▶sub option_spec { return ( 'warning|w=s', 'critical|c=s', 'required|r' ) }
Subroutine option_spec: called CC=1 SCAR=0.0
Pod documented
67  
68 9 ▶sub defaults { return { warning => '0' } }
Subroutine defaults: called CC=1 SCAR=0.0
Pod documented
69  
70 9 ▶sub ranges { return ( 'warning', 'critical' ) }
Subroutine ranges: called CC=1 SCAR=0.0
Pod documented
71  
72 =head1 METHODS
73  
74 =head2 check
75  
76 Does the check.
77  
78 =cut
79  
80 9 ▶sub check {
Subroutine check: called CC=27 SCAR=33.2
Pod documented
81 9 my ($self) = @_;
82  
83 9 ▶ die( 'not supported on ' . $self->os . "\n" ) if $self->os ne 'linux';
Branch: 1 branch
BranchTrueFalseTotal
if $self->os ne "linux" 1 8 9
84  
85 8 my $mc_dir = $EDAC . '/mc';
86 8 ▶ my $number = sub { ( $_[0] =~ /([0-9]+)\z/ )[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
87 8 my @controllers;
88 8 ▶ if ( opendir( my $dh, $mc_dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $mc_dir) 7 1 8
89 7 @controllers = sort { $number->($a) <=> $number->($b) } grep { /\Amc[0-9]+\z/ } readdir($dh);
90 }
91 8 ▶ if ( !defined( $controllers[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $controllers[0]) 3 5 8
92 3 ▶ return $self->finish( $self->opt('required') ? $self->WARNING : $self->OK, 'no EDAC memory controllers' );
Branch: 1 branch
BranchTrueFalseTotal
$self->opt('required') ? : 1 2 3
93 }
94  
95 # a file under mc, trimmed, or undef if it can not be read
96 87 ▶ my $read = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
97 87 my $content = read_file( $mc_dir . '/' . $_[0], err_mode => 'quiet' );
98 87 ▶ return defined($content) ? $content =~ s/\A\s+|\s+\z//gr : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $content ? : 85 2 87
99 5 };
100 # such as "3 corrected, 1 uncorrected", leaving out a count that is 0
101 12 ▶ my $counts = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
102 12 my ( $ce, $ue ) = @_;
103 12 ▶ return join( ', ', ( $ce ? $ce . ' corrected' : () ), ( $ue ? $ue . ' uncorrected' : () ) );
Branch: 2 branches
BranchTrueFalseTotal
$ce ? : 9 3 12
$ue ? : 3 9 12
104 5 };
105  
106 5 my $corrected = 0;
107 5 my $uncorrected = 0;
108 5 my @where;
109 my @details;
110 5 foreach my $controller (@controllers) {
111 9 my $ce = $read->( $controller . '/ce_count' );
112 9 my $ue = $read->( $controller . '/ue_count' );
113 9 ▶ return $self->finish( $self->UNKNOWN, 'can not read the counts of ' . $mc_dir . '/' . $controller )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ce and defined $ue and $ce =~ /\A[0-9]+\z/u and $ue =~ /\A[0-9]+\z/u 1 8 9
Condition66%6/9
defined $ce and defined $ue and $ce =~ /\A[0-9]+\z/u and $ue =~ /\A[0-9]+\z/u
!ll&&!rl&&r
108
defined $ce and defined $ue and $ce =~ /\A[0-9]+\z/u
!ll&&!rl&&r
108
defined $ce and defined $ue
!ll&&!rl&&r
108
MC/DC25%1/4
defined $ce and defined $ue and $ce =~ /\A[0-9]+\z/u and $ue =~ /\A[0-9]+\z/u
defined $ce defined $ue $ce =~ /\A[0-9]+\z/u $ue =~ /\A[0-9]+\z/u
Truth table40%2/5
A and B and C and D
A= defined $ceB= defined $ueC= $ce =~ /\A[0-9]+\z/uD= $ue =~ /\A[0-9]+\z/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
114 if !defined($ce) || !defined($ue) || $ce !~ /\A[0-9]+\z/ || $ue !~ /\A[0-9]+\z/;
115 8 $corrected = $corrected + $ce;
116 8 $uncorrected = $uncorrected + $ue;
117 8 ▶ push(
Condition50%2/4
&$read($controller . '/mc_name') // "unknown"
l!l
80
&$read($controller . '/size_mb') // "?"
l!l
80
MC/DC0%0/1
&$read($controller . '/mc_name') // "unknown"
&$read($controller . '/mc_name')
MC/DC0%0/1
&$read($controller . '/size_mb') // "?"
&$read($controller . '/size_mb')
Truth table50%1/2
A
A= &$read($controller . '/mc_name')
Aresult
11
00
Truth table50%1/2
A
A= &$read($controller . '/size_mb')
Aresult
11
00
118 @details,
119 join( ', ',
120 $controller . ' ' . ( $read->( $controller . '/mc_name' ) // 'unknown' ),
121 ( $read->( $controller . '/size_mb' ) // '?' ) . ' MB',
122 $ce . ' corrected',
123 $ue . ' uncorrected' )
124 );
125  
126 # newer kernels have dimm or rank dirs, depending on the driver
127 8 my @dimms;
128 8 ▶ if ( opendir( my $dh, $mc_dir . '/' . $controller ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $mc_dir . '/' . $controller) 8 0 8
129 8 @dimms = sort { $number->($a) <=> $number->($b) } grep { /\A(?:dimm|rank)[0-9]+\z/ } readdir($dh);
130 }
131 8 foreach my $dimm (@dimms) {
132 14 ▶ my $dimm_ce = $read->( $controller . '/' . $dimm . '/dimm_ce_count' ) || 0;
Condition100%2/2
&$read($controller . '/' . $dimm . '/dimm_ce_count') || 0
l!l
68
MC/DC100%1/1
&$read($controller . '/' . $dimm . '/dimm_ce_count') || 0
&$read($controller . '/' . $dimm . '/dimm_ce_count')
Truth table100%2/2
A
A= &$read($controller . '/' . $dimm . '/dimm_ce_count')
Aresult
11
00
133 14 ▶ my $dimm_ue = $read->( $controller . '/' . $dimm . '/dimm_ue_count' ) || 0;
Condition100%2/2
&$read($controller . '/' . $dimm . '/dimm_ue_count') || 0
l!l
311
MC/DC100%1/1
&$read($controller . '/' . $dimm . '/dimm_ue_count') || 0
&$read($controller . '/' . $dimm . '/dimm_ue_count')
Truth table100%2/2
A
A= &$read($controller . '/' . $dimm . '/dimm_ue_count')
Aresult
11
00
134 14 ▶ next if !$dimm_ce && !$dimm_ue;
Branch: 1 branch
BranchTrueFalseTotal
unless $dimm_ce or $dimm_ue 5 9 14
Condition100%3/3
$dimm_ce or $dimm_ue
l!l&&r!l&&!r
635
MC/DC100%2/2
$dimm_ce or $dimm_ue
$dimm_ce $dimm_ue
Truth table100%3/3
A or B
A= $dimm_ceB= $dimm_ue
ABresult
1X1
011
000
135 9 my $label = $read->( $controller . '/' . $dimm . '/dimm_label' );
136 9 ▶ $label = $controller . ' ' . $dimm if !defined($label) || $label eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $label or $label eq "" 3 6 9
Condition66%2/3
not defined $label or $label eq ""
l!l&&r!l&&!r
036
MC/DC50%1/2
not defined $label or $label eq ""
not defined $label $label eq ""
Truth table66%2/3
not(A) or B
A= not defined $labelB= $label eq ""
ABresult
1X1
011
000
137 9 push( @where, $label . ' ' . $counts->( $dimm_ce, $dimm_ue ) );
138 }
139 8 ▶ my $noinfo_ce = $read->( $controller . '/ce_noinfo_count' ) || 0;
Condition100%2/2
&$read($controller . '/ce_noinfo_count') || 0
l!l
35
MC/DC100%1/1
&$read($controller . '/ce_noinfo_count') || 0
&$read($controller . '/ce_noinfo_count')
Truth table100%2/2
A
A= &$read($controller . '/ce_noinfo_count')
Aresult
11
00
140 8 ▶ my $noinfo_ue = $read->( $controller . '/ue_noinfo_count' ) || 0;
Condition50%1/2
&$read($controller . '/ue_noinfo_count') || 0
l!l
08
MC/DC0%0/1
&$read($controller . '/ue_noinfo_count') || 0
&$read($controller . '/ue_noinfo_count')
Truth table50%1/2
A
A= &$read($controller . '/ue_noinfo_count')
Aresult
11
00
141 8 ▶ push( @where, $controller . ' no DIMM ' . $counts->( $noinfo_ce, $noinfo_ue ) ) if $noinfo_ce || $noinfo_ue;
Branch: 1 branch
BranchTrueFalseTotal
if $noinfo_ce or $noinfo_ue 3 5 8
Condition66%2/3
$noinfo_ce or $noinfo_ue
l!l&&r!l&&!r
305
MC/DC50%1/2
$noinfo_ce or $noinfo_ue
$noinfo_ce $noinfo_ue
Truth table66%2/3
A or B
A= $noinfo_ceB= $noinfo_ue
ABresult
1X1
011
000
142 } ## end foreach my $controller (@controllers)
143  
144 4 ▶ my $code = $self->worst( $self->threshold_status( $corrected, $self->opt('warning'), $self->opt('critical') ),
Branch: 1 branch
BranchTrueFalseTotal
$uncorrected ? : 3 1 4
145 $uncorrected ? $self->CRITICAL : $self->OK );
146 4 $self->perfdata(
147 label => 'corrected',
148 value => $corrected,
149 warning => $self->opt('warning'),
150 critical => $self->opt('critical'),
151 min => 0,
152 );
153 4 $self->perfdata( label => 'uncorrected', value => $uncorrected, critical => 0, min => 0 );
154 4 ▶ my $message
Branch: 1 branch
BranchTrueFalseTotal
@controllers == 1 ? : 0 4 4
155 = scalar(@controllers)
156 . ' memory controller'
157 . ( @controllers == 1 ? '' : 's' ) . ', '
158 . $corrected
159 . ' corrected, '
160 . $uncorrected
161 . ' uncorrected';
162 4 ▶ $message = $message . ', ' . join( ', ', @where ) if defined( $where[0] );
Branch: 1 branch
BranchTrueFalseTotal
if defined $where[0] 3 1 4
163  
164 4 return $self->finish( $code, $message, @details );
165 } ## end sub check
166  
167 3 1;
« blib/lib/Monitoring/Sneck/Checks/vrrp.pm ↑ Summary blib/lib/Monitoring/Sneck/Checks/apparmor.pm »