blib/lib/Linux/GetPidstat/Writer.pm

filter: Statementstmt 100% 33 / 33 Branchbran 83.3% 10 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 92.7% 51 / 55 CC 7 SCAR 13.9
CC
7
Cov
96%
output
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Linux/GetPidstat/Reader.pm ↑ Summary blib/lib/Linux/GetPidstat/Collector.pm »
1 package Linux::GetPidstat::Writer;
2 14 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use Linux::GetPidstat::Writer::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Linux::GetPidstat::Writer::Mackerel;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 21 ▶ my ( $class, %opt ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 21 bless \%opt, $class;
13 }
14  
15 sub output {
16 20 ▶ my ($self, $ret_pidstats) = @_;
Subroutine output: called CC=7 SCAR=19.5
Pod undocumented
17  
18 20 my $file;
19 20 ▶ if (length $self->{res_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"res_file"}) 20 0 20
20 $file = Linux::GetPidstat::Writer::File->new(
21 res_file => $self->{res_file},
22 now => $self->{now},
23 dry_run => $self->{dry_run},
24 20 );
25 }
26  
27 20 my $mackerel;
28 20 ▶ if (length $self->{mackerel_metric_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"mackerel_metric_type"}) 6 14 20
29 $mackerel = Linux::GetPidstat::Writer::Mackerel->new(
30 mackerel_metric_type => $self->{mackerel_metric_type},
31 mackerel_api_key => $self->{mackerel_api_key},
32 mackerel_service_name => $self->{mackerel_service_name},
33 mackerel_metric_key_prefix => $self->{mackerel_metric_key_prefix},
34 mackerel_host_id => $self->{mackerel_host_id},
35 now => $self->{now},
36 dry_run => $self->{dry_run},
37 6 );
38 }
39  
40 # ex. backup_mysql => { cpu => 21.0 }
41 20 ▶ while (my ($program_name, $s) = each %$ret_pidstats) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$ret_pidstats) 40 20 60
42 40 ▶ while (my ($metric_name, $metric) = each %$s) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$s) 360 40 400
43 360 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 360 0 360
44 360 $file->output($program_name, $metric_name, $metric);
45 }
46 }
47 }
48 20 ▶ if ($mackerel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mackerel) 6 14 20
49 6 $mackerel->bulk_output($ret_pidstats);
50 }
51 }
52  
53 14 1;
54 __END__
« blib/lib/Linux/GetPidstat/Reader.pm ↑ Summary blib/lib/Linux/GetPidstat/Collector.pm »