| 1 | package Mail::Milter::Authentication::Metric::Grafana; | ||||||||||
| 2 | 143 | ▶ | use 5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 143 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 143 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 143 | ▶ | use Mail::Milter::Authentication::Pragmas; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | # ABSTRACT: Class for Grafana dashboards | ||||||||||
| 7 | 143 | our $VERSION = '4.20261116'; # VERSION | |||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | sub get_json { | ||||||||
|
Subroutine
get_json: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 10 | 0 | my ( $self, $file ) = @_; | |||||||||
| 11 | 0 | my $basefile = __FILE__; | |||||||||
| 12 | 0 | $basefile =~ s/Grafana\.pm$/$file/; | |||||||||
| 13 | 0 | $basefile .= '.json'; | |||||||||
| 14 | 0 | ▶ | if ( ! -e $basefile ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 24 | 0 | my ( $class ) = @_; | |||||||||
| 25 | 0 | my $self = {}; | |||||||||
| 26 | 0 | bless $self, $class; | |||||||||
| 27 | 0 | return $self; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub get_dashboard { | ||||||||
|
Subroutine
get_dashboard: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 31 | 0 | 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' } } ) { | |||||||||
| 42 | 0 | my $HandlerObj = $server->{ 'handler' }->{ $Handler }; | |||||||||
| 43 | 0 | ▶ | if ( $HandlerObj->can( 'grafana_rows' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my $HandlerRows = $HandlerObj->grafana_rows(); | |||||||||
| 45 | 0 | foreach my $Row ( @$HandlerRows ) { | |||||||||
| 46 | 0 | ▶ | push @Rows, $Row if $Row; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 143 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||