Engine/Health/Throughput.pm untested

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