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