MetricsController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A metrics() 0 19 1
1
<?php
2
3
namespace XHGui\Controller;
4
5
use Slim\Http\Response;
6
use Slim\Slim as App;
7
use XHGui\AbstractController;
8
use XHGui\Searcher\SearcherInterface;
9
10
class MetricsController extends AbstractController
11
{
12
    /**
13
     * @var SearcherInterface
14
     */
15
    protected $searcher;
16
17
    public function __construct(App $app, SearcherInterface $searcher)
18
    {
19
        parent::__construct($app);
20
        $this->searcher = $searcher;
21
    }
22
23
    public function metrics(Response $response): void
24
    {
25
        $stats = $this->searcher->stats();
26
27
        $body = "# HELP xhgui_profiles_total Number of profiles collected.\n";
28
        $body .= "# TYPE xhgui_profiles_total gauge\n";
29
        $body .= sprintf("xhgui_profiles_total %0.1F\n\n", $stats['profiles']);
30
31
        $body .= "# HELP xhgui_profile_bytes_total Size of profiles collected.\n";
32
        $body .= "# TYPE xhgui_profile_bytes_total gauge\n";
33
        $body .= sprintf("xhgui_profile_bytes_total %0.1F\n\n", $stats['bytes']);
34
35
        $body .= "# HELP xhgui_latest_profile_seconds UNIX timestamp of most recent profile.\n";
36
        $body .= "# TYPE xhgui_latest_profile_seconds gauge\n";
37
        $body .= sprintf("xhgui_latest_profile_seconds %0.1F\n", $stats['latest']);
38
39
        $response->body($body);
40
        $response['Content-Type'] = 'text/plain; version=0.0.4';
41
    }
42
}
43