| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HealthCheck::Diagnostic::Redis; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
80963
|
use strict; |
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
430
|
use parent 'HealthCheck::Diagnostic'; |
|
|
1
|
|
|
|
|
289
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4504
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
51
|
|
|
9
|
1
|
|
|
1
|
|
493
|
use Redis::Fast; |
|
|
1
|
|
|
|
|
17674
|
|
|
|
1
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Check for Redis connectivity and operations in HealthCheck |
|
12
|
1
|
|
|
1
|
|
8
|
use version; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 'v0.0.4'; # VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
2
|
|
|
2
|
1
|
2462
|
my ($class, @params) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %params = @params == 1 && ( ref $params[0] || '' ) eq 'HASH' |
|
19
|
2
|
50
|
33
|
|
|
13
|
? %{ $params[0] } : @params; |
|
|
0
|
|
|
|
|
0
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
15
|
return $class->SUPER::new( |
|
22
|
|
|
|
|
|
|
id => 'redis', |
|
23
|
|
|
|
|
|
|
label => 'redis', |
|
24
|
|
|
|
|
|
|
%params, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub check { |
|
29
|
5
|
|
|
5
|
1
|
3258
|
my ($self, %params) = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Allow the diagnostic to be called as a class as well. |
|
32
|
5
|
100
|
|
|
|
16
|
if ( ref $self ) { |
|
33
|
|
|
|
|
|
|
$params{$_} = $self->{$_} |
|
34
|
2
|
|
|
|
|
9
|
foreach grep { ! defined $params{$_} } keys %$self; |
|
|
6
|
|
|
|
|
22
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# The host is the only required parameter. |
|
38
|
5
|
100
|
|
|
|
232
|
croak "No host" unless $params{host}; |
|
39
|
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
21
|
return $self->SUPER::check(%params); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub run { |
|
44
|
4
|
|
|
4
|
1
|
95
|
my ($self, %params) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
9
|
my $host = $params{host}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
8
|
my $name = $params{name}; |
|
49
|
4
|
50
|
|
|
|
14
|
my $description = $name ? "$name ($host) Redis" : "$host Redis"; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Add on the port if need be. |
|
52
|
4
|
50
|
|
|
|
18
|
$host .= ':6379' unless $host =~ /:\d+$/; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Connect to the host... |
|
55
|
4
|
|
|
|
|
6
|
my $redis; |
|
56
|
4
|
|
|
|
|
6
|
local $@; |
|
57
|
4
|
|
|
|
|
6
|
eval { |
|
58
|
4
|
|
|
|
|
16
|
local $SIG{__DIE__}; |
|
59
|
4
|
|
|
|
|
29
|
$redis = Redis::Fast->new( |
|
60
|
|
|
|
|
|
|
server => $host, |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# HealthCheck should not reconnect |
|
63
|
|
|
|
|
|
|
reconnect => 0, |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Make this quick... |
|
66
|
|
|
|
|
|
|
cnx_timeout => 0.5, |
|
67
|
|
|
|
|
|
|
read_timeout => 0.5, |
|
68
|
|
|
|
|
|
|
write_timeout => 0.5, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
}; |
|
71
|
|
|
|
|
|
|
return { |
|
72
|
4
|
100
|
|
|
|
99
|
status => 'CRITICAL', |
|
73
|
|
|
|
|
|
|
info => "Error for $description: $@", |
|
74
|
|
|
|
|
|
|
} if $@; |
|
75
|
|
|
|
|
|
|
|
|
76
|
3
|
50
|
|
|
|
9
|
unless ($redis->ping) { |
|
77
|
|
|
|
|
|
|
return { |
|
78
|
0
|
|
|
|
|
0
|
status => 'CRITICAL', |
|
79
|
|
|
|
|
|
|
info => "Error for $description: Redis ping failed", |
|
80
|
|
|
|
|
|
|
}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
26
|
my ($key, $error) = $redis->randomkey(); |
|
84
|
|
|
|
|
|
|
return { |
|
85
|
3
|
50
|
|
|
|
37
|
status => 'CRITICAL', |
|
86
|
|
|
|
|
|
|
info => "Error for $description: Getting Random entry failed - $error", |
|
87
|
|
|
|
|
|
|
} if ($error); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# At this point, the only way this fails is if there are no entries in the |
|
90
|
|
|
|
|
|
|
# Redis DB. |
|
91
|
3
|
50
|
|
|
|
10
|
if ($key) { |
|
92
|
3
|
|
|
|
|
14
|
my $val = $redis->get($key); |
|
93
|
|
|
|
|
|
|
return { |
|
94
|
3
|
50
|
|
|
|
22
|
status => 'CRITICAL', |
|
95
|
|
|
|
|
|
|
info => "Error for $description: Failed fetching value of key $key", |
|
96
|
|
|
|
|
|
|
} unless defined $val; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return { |
|
100
|
3
|
|
|
|
|
29
|
status => 'OK', |
|
101
|
|
|
|
|
|
|
info => "Successful connection for $description", |
|
102
|
|
|
|
|
|
|
}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |