Conditions | 7 |
Paths | 7 |
Total Lines | 36 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
18 | public function print(Metric $metric): string |
||
19 | { |
||
20 | if (count($metric->measurements()->get()) === 0) { |
||
21 | return ''; |
||
22 | } |
||
23 | |||
24 | $string = ''; |
||
25 | if (strlen($metric->config()->description()) > 0) { |
||
26 | $string = '# HELP ' . $metric->config()->name() . ' ' . $metric->config()->description() . self::NL; |
||
27 | } |
||
28 | |||
29 | $string .= '# TYPE ' . $metric->config()->name() . ' ' . $metric->config()->type() . self::NL; |
||
30 | |||
31 | foreach ($metric->measurements()->get() as $measurement) { |
||
32 | $string .= $metric->config()->name(); |
||
33 | $tags = array_merge($metric->tags()->get(), $measurement->tags()->get()); |
||
34 | $tagCount = count($tags); |
||
35 | if ($tagCount > 0) { |
||
36 | $tagKeys = array_keys($tags); |
||
37 | $string .= '{'; |
||
38 | for ($i = 0; $i < $tagCount; $i++) { |
||
39 | $string .= $tags[$tagKeys[$i]]->key() . '="' . $tags[$tagKeys[$i]]->value() . '"'; |
||
40 | if (! array_key_exists($i + 1, $tagKeys)) { |
||
41 | continue; |
||
42 | } |
||
43 | |||
44 | $string .= ','; |
||
45 | } |
||
46 | |||
47 | $string .= '}'; |
||
48 | } |
||
49 | |||
50 | $string .= ' ' . $measurement->value() . ' ' . floor($metric->time() * 1000) . self::NL; |
||
51 | } |
||
52 | |||
53 | return $string . self::NL; |
||
54 | } |
||
56 |