Completed
Pull Request — master (#331)
by Elan
02:10 queued 57s
created

MetricsController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

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