line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::Size; |
2
|
1
|
|
|
1
|
|
995
|
use 5.20.0; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
14
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
7
|
use Mail::Milter::Authentication::Pragmas; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for message size metrics |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230911'; # VERSION |
8
|
1
|
|
|
1
|
|
237
|
use base 'Mail::Milter::Authentication::Handler'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
742
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub default_config { |
11
|
0
|
|
|
0
|
0
|
|
return {}; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub grafana_rows { |
15
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
16
|
0
|
|
|
|
|
|
my @rows; |
17
|
0
|
|
|
|
|
|
push @rows, $self->get_json( 'Size_metrics' ); |
18
|
0
|
|
|
|
|
|
return \@rows; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub register_metrics { |
22
|
|
|
|
|
|
|
return { |
23
|
0
|
|
|
0
|
1
|
|
'size_total' => 'The number of emails processed for Size', |
24
|
|
|
|
|
|
|
'size_header_bytes_added_total' => 'The header size added to emails processed for Size', |
25
|
|
|
|
|
|
|
'size_header_bytes_total' => 'The header size of emails processed for Size', |
26
|
|
|
|
|
|
|
'size_body_bytes_total' => 'The body size of emails processed for Size', |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub envfrom_callback { |
31
|
0
|
|
|
0
|
0
|
|
my ( $self, $env_from ) = @_; |
32
|
0
|
|
|
|
|
|
$self->{'headersize'} = 0; |
33
|
0
|
|
|
|
|
|
$self->{'bodysize'} = 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub header_callback { |
37
|
0
|
|
|
0
|
0
|
|
my ( $self, $header, $value ) = @_; |
38
|
0
|
|
|
|
|
|
$self->{ 'headersize' } = $self->{ 'headersize' } + length( $header . ': ' . $value ) + 2; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub body_callback { |
42
|
0
|
|
|
0
|
0
|
|
my ( $self, $body_chunk ) = @_; |
43
|
0
|
|
|
|
|
|
$self->{ 'bodysize' } = $self->{ 'bodysize' } + length ( $body_chunk ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub eom_callback { |
47
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
48
|
0
|
|
|
|
|
|
$self->metric_count( 'size_total', {}, 1 ); |
49
|
0
|
|
|
|
|
|
$self->metric_count( 'size_header_bytes_total', {}, $self->{ 'headersize' } ); |
50
|
0
|
|
|
|
|
|
$self->metric_count( 'size_body_bytes_total', {}, $self->{ 'bodysize' } ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub close_callback { |
54
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $top_handler = $self->get_top_handler(); |
57
|
0
|
0
|
|
|
|
|
if ( exists( $top_handler->{'pre_headers'} ) ) { |
58
|
0
|
|
|
|
|
|
foreach my $header ( @{ $top_handler->{'pre_headers'} } ) { |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $size = length( $header->{'field'} ) + length ( $header->{'value'} ) + 3; |
60
|
0
|
|
|
|
|
|
$self->metric_count( 'size_header_bytes_added_total', { where => 'pre', 'header' => $header->{'field'} }, $size ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
0
|
0
|
|
|
|
|
if ( exists( $top_handler->{'add_headers'} ) ) { |
64
|
0
|
|
|
|
|
|
foreach my $header ( @{ $top_handler->{'add_headers'} } ) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $size = length( $header->{'field'} ) + length ( $header->{'value'} ) + 3; |
66
|
0
|
|
|
|
|
|
$self->metric_count( 'size_header_bytes_added_total', { where => 'add', 'header' => $header->{'field'} }, $size ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
delete $self->{'bodysize'}; |
71
|
0
|
|
|
|
|
|
delete $self->{'headersize'}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Mail::Milter::Authentication::Handler::Size - Handler class for message size metrics |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
version 3.20230911 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Module to provide metrics related to message size. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CONFIGURATION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
"Size" : {}, | Config for the Size Module |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Marc Bradshaw. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
107
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |