line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::GetPidstat; |
2
|
13
|
|
|
13
|
|
778714
|
use 5.008001; |
|
13
|
|
|
|
|
50
|
|
3
|
13
|
|
|
13
|
|
52
|
use strict; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
207
|
|
4
|
13
|
|
|
13
|
|
53
|
use warnings; |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
452
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.07"; |
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
78
|
use Carp; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
529
|
|
9
|
13
|
|
|
13
|
|
4938
|
use Time::Piece::MySQL; |
|
13
|
|
|
|
|
109985
|
|
|
13
|
|
|
|
|
77
|
|
10
|
|
|
|
|
|
|
|
11
|
13
|
|
|
13
|
|
4684
|
use Linux::GetPidstat::Reader; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
325
|
|
12
|
13
|
|
|
13
|
|
3939
|
use Linux::GetPidstat::Collector; |
|
13
|
|
|
|
|
28
|
|
|
13
|
|
|
|
|
318
|
|
13
|
13
|
|
|
13
|
|
4169
|
use Linux::GetPidstat::Writer; |
|
13
|
|
|
|
|
39
|
|
|
13
|
|
|
|
|
4009
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
12
|
|
|
12
|
0
|
6398
|
my $class = shift; |
17
|
12
|
|
|
|
|
49
|
bless {}, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub run { |
21
|
46
|
|
|
46
|
1
|
144596
|
my ($self, %args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
46
|
|
|
|
|
289
|
$self->_validate_args(%args); |
24
|
|
|
|
|
|
|
|
25
|
46
|
|
|
|
|
172
|
my $pid_dir_path = $args{pid_dir}; |
26
|
46
|
|
|
|
|
117
|
my $datetime; |
27
|
46
|
50
|
|
|
|
186
|
unless (length $args{datetime}) { |
28
|
0
|
|
|
|
|
0
|
$datetime = localtime; |
29
|
|
|
|
|
|
|
} else { |
30
|
46
|
|
|
|
|
344
|
$datetime = localtime->from_mysql_datetime($args{datetime}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $program_pid_mapping = Linux::GetPidstat::Reader->new( |
34
|
|
|
|
|
|
|
pid_dir => $pid_dir_path, |
35
|
|
|
|
|
|
|
include_child => $args{include_child}, |
36
|
|
|
|
|
|
|
max_child_limit => $args{max_child_limit}, |
37
|
46
|
|
|
|
|
10728
|
)->get_program_pid_mapping; |
38
|
|
|
|
|
|
|
|
39
|
46
|
100
|
|
|
|
570
|
unless (@$program_pid_mapping) { |
40
|
11
|
|
|
|
|
726
|
croak "Not found pids in pid_dir: $pid_dir_path"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $ret_pidstats = Linux::GetPidstat::Collector->new( |
44
|
|
|
|
|
|
|
interval => $args{interval}, |
45
|
|
|
|
|
|
|
count => $args{count}, |
46
|
35
|
|
|
|
|
525
|
)->get_pidstats_results($program_pid_mapping); |
47
|
|
|
|
|
|
|
|
48
|
25
|
100
|
|
|
|
11862
|
unless (%$ret_pidstats) { |
49
|
9
|
|
|
|
|
2232
|
croak "Failed to collect metrics"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Linux::GetPidstat::Writer->new( |
53
|
|
|
|
|
|
|
res_file => $args{res_file}, |
54
|
|
|
|
|
|
|
mackerel_metric_type => $args{mackerel_metric_type}, |
55
|
|
|
|
|
|
|
mackerel_api_key => $args{mackerel_api_key}, |
56
|
|
|
|
|
|
|
mackerel_service_name => $args{mackerel_service_name}, |
57
|
|
|
|
|
|
|
mackerel_metric_key_prefix => $args{mackerel_metric_key_prefix}, |
58
|
|
|
|
|
|
|
mackerel_host_id => $args{mackerel_host_id}, |
59
|
|
|
|
|
|
|
now => $datetime, |
60
|
|
|
|
|
|
|
dry_run => $args{dry_run}, |
61
|
16
|
|
|
|
|
546
|
)->output($ret_pidstats); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _validate_args { |
65
|
134
|
|
|
134
|
|
83712
|
my ($self, %args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
134
|
100
|
|
|
|
519
|
unless (length $args{pid_dir}) { |
68
|
11
|
|
|
|
|
1408
|
croak("pid_dir required"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
123
|
|
|
|
|
288
|
my $mackerel_metric_type = $args{mackerel_metric_type}; |
72
|
123
|
|
|
|
|
251
|
my $mackerel_api_key = $args{mackerel_api_key}; |
73
|
123
|
|
|
|
|
278
|
my $mackerel_service_name = $args{mackerel_service_name}; |
74
|
123
|
100
|
100
|
|
|
603
|
if (length $mackerel_metric_type && $mackerel_metric_type eq "service") { |
75
|
41
|
100
|
66
|
|
|
194
|
unless (length $mackerel_api_key && |
76
|
|
|
|
|
|
|
length $mackerel_service_name) { |
77
|
11
|
|
|
|
|
682
|
croak("when mackerel_metric_type is 'service', mackerel_[api_key|service_name] are required"); |
78
|
|
|
|
|
|
|
} |
79
|
30
|
|
|
|
|
106
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
82
|
|
|
|
|
167
|
my $mackerel_host_id = $args{mackerel_host_id}; |
83
|
82
|
100
|
66
|
|
|
304
|
if (length $mackerel_metric_type && $mackerel_metric_type eq "host") { |
84
|
22
|
50
|
66
|
|
|
110
|
unless (length $mackerel_api_key && |
|
|
|
66
|
|
|
|
|
85
|
|
|
|
|
|
|
length $mackerel_service_name && |
86
|
|
|
|
|
|
|
length $mackerel_host_id) { |
87
|
11
|
|
|
|
|
682
|
croak("when mackerel_metric_type is 'host', mackerel_[api_key|service_name|host_id] are required"); |
88
|
|
|
|
|
|
|
} |
89
|
11
|
|
|
|
|
33
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
60
|
|
|
|
|
136
|
my $res_file = $args{res_file}; |
93
|
60
|
100
|
|
|
|
284
|
if (length $res_file) { |
94
|
49
|
|
|
|
|
411
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
11
|
|
|
|
|
693
|
croak("res_file or mackerel_metric_type required"); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |