line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Metric::Grafana; |
2
|
99
|
|
|
99
|
|
665
|
use strict; |
|
99
|
|
|
|
|
205
|
|
|
99
|
|
|
|
|
2518
|
|
3
|
99
|
|
|
99
|
|
493
|
use warnings; |
|
99
|
|
|
|
|
212
|
|
|
99
|
|
|
|
|
3313
|
|
4
|
|
|
|
|
|
|
our $VERSION = '20191206'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
99
|
|
|
99
|
|
495
|
use JSON; |
|
99
|
|
|
|
|
282
|
|
|
99
|
|
|
|
|
470
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub get_json { |
9
|
0
|
|
|
0
|
1
|
|
my ( $self, $file ) = @_; |
10
|
0
|
|
|
|
|
|
my $basefile = __FILE__; |
11
|
0
|
|
|
|
|
|
$basefile =~ s/Grafana\.pm$/$file/; |
12
|
0
|
|
|
|
|
|
$basefile .= '.json'; |
13
|
0
|
0
|
|
|
|
|
if ( ! -e $basefile ) { |
14
|
0
|
|
|
|
|
|
die 'json file ' . $file . ' not found'; |
15
|
|
|
|
|
|
|
} |
16
|
0
|
|
|
|
|
|
open my $InF, '<', $basefile; |
17
|
0
|
|
|
|
|
|
my @Content = <$InF>; |
18
|
0
|
|
|
|
|
|
close $InF; |
19
|
0
|
|
|
|
|
|
return join( q{}, @Content ); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
1
|
|
my ( $class ) = @_; |
24
|
0
|
|
|
|
|
|
my $self = {}; |
25
|
0
|
|
|
|
|
|
bless $self, $class; |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_dashboard { |
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $server ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my @Rows; |
33
|
|
|
|
|
|
|
# Add default system rows |
34
|
0
|
|
|
|
|
|
push @Rows, $self->get_json( 'RowThroughput' ); |
35
|
0
|
|
|
|
|
|
push @Rows, $self->get_json( 'RowProcesses' ); |
36
|
0
|
|
|
|
|
|
push @Rows, $self->get_json( 'RowProcessingTime' ); |
37
|
0
|
|
|
|
|
|
push @Rows, $self->get_json( 'RowErrors' ); |
38
|
0
|
|
|
|
|
|
push @Rows, $self->get_json( 'RowUptime' ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
foreach my $Handler ( sort keys %{ $server->{ 'handler' } } ) { |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $HandlerObj = $server->{ 'handler' }->{ $Handler }; |
42
|
0
|
0
|
|
|
|
|
if ( $HandlerObj->can( 'grafana_rows' ) ) { |
43
|
0
|
|
|
|
|
|
my $HandlerRows = $HandlerObj->grafana_rows(); |
44
|
0
|
|
|
|
|
|
foreach my $Row ( @$HandlerRows ) { |
45
|
0
|
0
|
|
|
|
|
push @Rows, $Row if $Row; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $J = JSON->new(); |
51
|
0
|
|
|
|
|
|
$J->pretty(); |
52
|
0
|
|
|
|
|
|
$J->canonical(); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $Base = $self->get_json( 'Base' ); |
55
|
0
|
|
|
|
|
|
my $BaseData = $J->decode( $Base ); |
56
|
0
|
|
|
|
|
|
my $RowsData = $J->decode( '[' . join( ',', @Rows ) . ']' ); |
57
|
0
|
|
|
|
|
|
$BaseData->{ 'rows' } = $RowsData; |
58
|
0
|
|
|
|
|
|
return $J->encode( $BaseData ) . "\n"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding UTF-8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Mail::Milter::Authentication::Metric::Grafana |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 VERSION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
version 20191206 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Automatically generate a grafana dashboard for installed handlers |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item new() |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $object = Mail::Milter::Authentication::Metric::Grafana->new(); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Creates a new object. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item get_Base() |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the base json for the dashboard |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item get_RowThroughput() |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns the Row json for THroughput |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item get_RowProcesses() |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Returns the Row json for Processes |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item get_RowProcessingTime() |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns the Row json for Processing TIme |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item get_RowErrors() |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Returns the Row json for Errors |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item get_RowUptime() |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the Row json for Uptime |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item get_json ( $file ) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Retrieve json data from external file |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item get_dashboard( $server ) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the json for the grafana dashboard |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$server is the current handler object |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Marc Bradshaw. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
142
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |