Engine/Health/Threads.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 10 Conditioncond n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 75 CC 6 SCAR 25.9
CC
6
Cov
0%
check
30.0
new
6.0
BEGIN
2.0
CRAP 13.4
1 package Service::Engine::Health::Threads;
2  
3 use 5.010;
4 use strict;
5 use warnings;
6 use Data::Dumper;
7 use JSON;
8  
9 use Service::Engine;
10  
11 our $Config;
12 our $Log;
13 our $Threads;
14 our $EngineName;
15 our $EngineInstance;
16  
17 # are enough threads running?
18  
19 sub new {
20
21 my ($class,$options) = @_;
22
23 # set some defaults
24 my $attributes = {'method'=>''};
25
26 # load options
27 if (ref($options) eq 'HASH') {
28 foreach my $option (keys %{$options}) {
29 $attributes->{$option} = $options->{$option};
30 }
31 }
32
33 # pull in some Service::Engine globals
34 $Config = $Service::Engine::Config;
35 $Log = $Service::Engine::Log;
36 $Threads = $Service::Engine::Threads;
37 $EngineName = $Service::Engine::EngineName;
38 $EngineInstance = $Service::Engine::EngineInstance;
39
40 # set some defaults
41
42 my $self = bless $attributes, $class;
43
44 return $self;
45  
46 }
47  
48 # a check returns a status object
49 sub check {
50 my ($self) = @_;
51
52 # do our test and set state
53 my $options = $Config->get_config('health')->{'modules'}->{'Threads'}->{'options'};
54 if (ref($options) ne 'HASH') {
55 $Log->log({'msg'=>"Threads options not found",'level'=>2});
56 return {};
57 }
58
59 my $critical = $options->{'critical'};
60 my $warning = $options->{'warning'};
61 my $thread_count = $Threads->get_thread_count();
62
63 my $condition = ($thread_count <= $critical) ? 'critical' : ($thread_count < $warning) ? 'warning' : 'info';
64 my $state = ($condition eq 'info') ? 'ok' : 'error';
65 my $msg = uc($condition) . ": $EngineName:$EngineInstance thread count is $thread_count";
66 my $data = {'thread_count'=>$thread_count, 'condition'=>$condition, 'state'=>$state, 'msg'=>$msg, 'time'=>time()};
67
68 my $status = {
69 'state'=>$state, # ok | error
70 'condition'=>$condition, # info|warning|critical
71 'msg'=> $msg,
72 'data'=>$data, # any data we want to return
73 };
74
75 return $status;
76 }
77  
78 1;