| 1 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | package OD::Prometheus::Client; | ||||||||||||||
| 5 | 1 | $OD::Prometheus::Client::VERSION = '0.005'; | |||||||||||||
| 6 | 1 | ▶ | use v5.24; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Data::Printer; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use OD::Prometheus::Metric; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use OD::Prometheus::Set; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | =head1 NAME | ||||||||||||||
| 14 | |||||||||||||||
| 15 | OD::Prometheus::Client - Client library to talk to Prometheus nodes | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 VERSION | ||||||||||||||
| 18 | |||||||||||||||
| 19 | version 0.005 | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =cut | ||||||||||||||
| 22 | |||||||||||||||
| 23 | |||||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | has host => ( | |||||||||||||
| 26 | is => 'ro', | ||||||||||||||
| 27 | isa => 'Str', | ||||||||||||||
| 28 | required => 1, | ||||||||||||||
| 29 | ); | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 1 | has port => ( | |||||||||||||
| 32 | is => 'ro', | ||||||||||||||
| 33 | isa => 'Num', | ||||||||||||||
| 34 | required => 1, | ||||||||||||||
| 35 | |||||||||||||||
| 36 | ); | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 1 | has path => ( | |||||||||||||
| 39 | is => 'ro', | ||||||||||||||
| 40 | isa => 'Str', | ||||||||||||||
| 41 | required => 0, | ||||||||||||||
| 42 | default => '/metrics', | ||||||||||||||
| 43 | ); | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 1 | has scheme => ( | |||||||||||||
| 46 | is => 'ro', | ||||||||||||||
| 47 | isa => 'Str', | ||||||||||||||
| 48 | required => 0, | ||||||||||||||
| 49 | default => 'http', | ||||||||||||||
| 50 | ); | ||||||||||||||
| 51 | |||||||||||||||
| 52 | has ua => ( | ||||||||||||||
| 53 | is => 'ro', | ||||||||||||||
| 54 | isa => 'LWP::UserAgent', | ||||||||||||||
| 55 | required => 0, | ||||||||||||||
| 56 | 0 | ▶ | default => sub { LWP::UserAgent->new }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 57 | 1 | ); | |||||||||||||
| 58 | |||||||||||||||
| 59 | has headers => ( | ||||||||||||||
| 60 | is => 'ro', | ||||||||||||||
| 61 | isa => 'HTTP::Headers', | ||||||||||||||
| 62 | required => 0, | ||||||||||||||
| 63 | default => sub { | ||||||||||||||
| 64 | 0 | ▶ | HTTP::Headers->new( | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 65 | Accept => 'text/plain;version=0.0.4;q=0.3', | ||||||||||||||
| 66 | ); | ||||||||||||||
| 67 | }, | ||||||||||||||
| 68 | 1 | ); | |||||||||||||
| 69 | |||||||||||||||
| 70 | sub BUILD { | ||||||||||||||
| 71 | 0 | ▶ | my $self = shift // die 'incorrect call'; | ||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
shift() // die("incorrect call")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 72 | 0 | $self->ua->default_headers( $self->headers ) | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | sub url { | ||||||||||||||
| 76 | 0 | ▶ | my $self = shift // die 'incorrect call'; | ||||||||||||
|
Subroutine
url: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
shift() // die("incorrect call")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 77 | 0 | $self->scheme.'://'.$self->host.':'.$self->port.$self->path | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | sub request { | ||||||||||||||
| 81 | 0 | ▶ | my $self = shift // die 'incorrect call'; | ||||||||||||
|
Subroutine
request: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
shift() // die("incorrect call")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 82 | 0 | HTTP::Request->new( GET => $self->url ); | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | sub get { | ||||||||||||||
| 86 | 0 | ▶ | my $self = shift // die 'incorrect call'; | ||||||||||||
|
Subroutine
get: not called CC=6 SCAR=37.4
Pod
undocumented
Condition0%0/2
shift() // die("incorrect call")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 87 | 0 | my $res = $self->ua->request($self->request); | |||||||||||||
| 88 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 0 | my $ret = OD::Prometheus::Set->new; | |||||||||||||
| 90 | 0 | my @comments = (); | |||||||||||||
| 91 | 0 | for my $line ( split("\n",$res->decoded_content) ) { | |||||||||||||
| 92 | 0 | ▶ | if( $line =~ /^#/ ){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 93 | 0 | push @comments, $line | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | elsif( $line =~ /^\s*$/ ) { # prometheus exposition format says empty lines are ignored | ||||||||||||||
| 96 | next | ||||||||||||||
| 97 | 0 | } | |||||||||||||
| 98 | else { | ||||||||||||||
| 99 | 0 | $ret->push( OD::Prometheus::Metric->new( line => $line, comments => \@comments ) ); | |||||||||||||
| 100 | 0 | @comments = (); | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | } | ||||||||||||||
| 103 | 0 | return $ret | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | else { | ||||||||||||||
| 106 | 0 | die $res->status_line | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head1 COPYRIGHT & LICENSE | ||||||||||||||
| 111 | |||||||||||||||
| 112 | Copyright 2018 Athanasios Douitsis, all rights reserved. | ||||||||||||||
| 113 | |||||||||||||||
| 114 | This program is free software; you can use it | ||||||||||||||
| 115 | under the terms of Artistic License 2.0 which can be found at | ||||||||||||||
| 116 | http://www.perlfoundation.org/artistic_license_2_0 | ||||||||||||||
| 117 | |||||||||||||||
| 118 | =cut | ||||||||||||||
| 119 | |||||||||||||||
| 120 | 1 | 1; | |||||||||||||