| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Prometheus::MetricRenderer; |
|
2
|
12
|
|
|
12
|
|
86
|
use Mojo::Base -base, -signatures; |
|
|
12
|
|
|
|
|
30
|
|
|
|
12
|
|
|
|
|
104
|
|
|
3
|
12
|
|
|
12
|
|
4282
|
use List::Util 'pairmap'; |
|
|
12
|
|
|
|
|
32
|
|
|
|
12
|
|
|
|
|
1032
|
|
|
4
|
12
|
|
|
12
|
|
80
|
use Scalar::Util 'looks_like_number'; |
|
|
12
|
|
|
|
|
34
|
|
|
|
12
|
|
|
|
|
11369
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
0
|
3
|
sub render($self, $metrics) { |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3
|
|
|
7
|
|
|
|
|
|
|
Mojo::Collection->new($metrics->@*) |
|
8
|
|
|
|
|
|
|
->map(sub { |
|
9
|
1
|
|
|
1
|
|
21
|
my $sampleset = $_; |
|
10
|
1
|
|
|
|
|
32
|
my $name = $sampleset->fullname; |
|
11
|
1
|
|
|
|
|
10
|
my $help = _format_help($sampleset); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
return ( |
|
14
|
|
|
|
|
|
|
"# HELP $name $help", |
|
15
|
|
|
|
|
|
|
"# TYPE $name " . $sampleset->type, |
|
16
|
1
|
|
|
|
|
14
|
map { _format_sample($_) } $sampleset->samples->@* |
|
|
1
|
|
|
|
|
11
|
|
|
17
|
|
|
|
|
|
|
) |
|
18
|
|
|
|
|
|
|
}) |
|
19
|
1
|
|
|
|
|
4
|
->join("\n"); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
2
|
sub _format_help($sampleset) { |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
23
|
1
|
|
|
|
|
15
|
my $help = $sampleset->help; |
|
24
|
1
|
|
|
|
|
6
|
$help =~ s/\\/\\\\/g; |
|
25
|
1
|
|
|
|
|
3
|
$help =~ s/\n/\\n/g; |
|
26
|
1
|
|
|
|
|
2
|
return $help; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
2
|
sub _format_sample($sample) { |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3
|
|
|
30
|
1
|
50
|
|
|
|
11
|
return unless defined $sample->value; |
|
31
|
1
|
50
|
|
|
|
16
|
my $value = looks_like_number($sample->value) ? $sample->value : 'NaN'; |
|
32
|
1
|
|
|
|
|
30
|
my $labels = _format_labels($sample->labels); |
|
33
|
1
|
|
|
|
|
14
|
sprintf '%s%s %s', $sample->varname, $labels, $value; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
6
|
sub _format_labels($labels) { |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1
|
|
|
37
|
1
|
50
|
|
|
|
6
|
return '' unless scalar @$labels; |
|
38
|
1
|
|
|
1
|
|
9
|
return '{' . join(',', pairmap { $a . '=' . _escape_label_value($b) } @$labels ) . '}'; |
|
|
1
|
|
|
|
|
5
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
2
|
sub _escape_label_value($value) { |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
42
|
1
|
|
|
|
|
4
|
$value =~ s/(["\\])/\\$1/g; |
|
43
|
1
|
|
|
|
|
3
|
$value =~ s/\n/\\n/g; |
|
44
|
1
|
|
|
|
|
7
|
return qq("$value"); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |