SwooleProcessCollector   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A collect() 0 51 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Hhxsv5\LaravelS\Components\Prometheus\Collectors;
4
5
use Hhxsv5\LaravelS\Components\MetricCollector;
6
7
class SwooleProcessCollector extends MetricCollector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SwooleProcessCollector
Loading history...
8
{
9
    public function collect(array $params = [])
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function collect()
Loading history...
10
    {
11
        // Worker Memory Stats
12
        $labels = http_build_query([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
13
            'process_id'   => $params['process_id'],
14
            'process_type' => $params['process_type'],
15
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
16
17
        // Memory Usage
18
        $memoryMetrics = [
19
            [
20
                'name'  => 'swoole_process_memory_usage',
21
                'type'  => 'gauge',
22
                'value' => memory_get_usage(),
23
            ],
24
            [
25
                'name'  => 'swoole_process_memory_real_usage',
26
                'type'  => 'gauge',
27
                'value' => memory_get_usage(true),
28
            ],
29
        ];
30
31
        // GC Status
32
        $gcMetrics = [];
33
        if (PHP_VERSION_ID >= 70300) {
34
            $gcStatus = gc_status();
35
            $gcMetrics = [
36
                [
37
                    'name'  => 'swoole_process_gc_runs',
38
                    'type'  => 'gauge',
39
                    'value' => $gcStatus['runs'],
40
                ],
41
                [
42
                    'name'  => 'swoole_process_gc_collected',
43
                    'type'  => 'gauge',
44
                    'value' => $gcStatus['collected'],
45
                ],
46
                [
47
                    'name'  => 'swoole_process_gc_threshold',
48
                    'type'  => 'gauge',
49
                    'value' => $gcStatus['threshold'],
50
                ],
51
                [
52
                    'name'  => 'swoole_process_gc_roots',
53
                    'type'  => 'gauge',
54
                    'value' => $gcStatus['roots'],
55
                ],
56
            ];
57
        }
58
        $apcuKey = implode($this->config['apcu_key_separator'], [$this->config['apcu_key_prefix'], 'swoole_process_stats', '', $labels]);
59
        apcu_store($apcuKey, array_merge($memoryMetrics, $gcMetrics), $this->config['apcu_key_max_age']);
60
    }
61
}