| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 42 | 40 | ▶ | while (my ($metric_name, $metric) = each %$s) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 360 | ▶ | if ($file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 360 | $file->output($program_name, $metric_name, $metric); | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | 20 | ▶ | if ($mackerel) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 6 | $mackerel->bulk_output($ret_pidstats); | |||||||||
| 50 | } | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 14 | 1; | |||||||||
| 54 | __END__ | ||||||||||