Passed
Push — master ( fa6214...4cbce0 )
by Biao
03:09
created

SystemCollector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A collect() 0 26 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\Prometheus\PrometheusCollector;
6
7
class SystemCollector extends PrometheusCollector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SystemCollector
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
        $load = sys_getloadavg();
12
        $metrics = [
13
            [
14
                'name'  => 'system_load_average_1m',
15
                'help'  => '',
16
                'type'  => 'gauge',
17
                'value' => $load[0],
18
            ],
19
            [
20
                'name'  => 'system_load_average_5m',
21
                'help'  => '',
22
                'type'  => 'gauge',
23
                'value' => $load[1],
24
            ],
25
            [
26
                'name'  => 'system_load_average_15m',
27
                'help'  => '',
28
                'type'  => 'gauge',
29
                'value' => $load[2],
30
            ],
31
        ];
32
        foreach ($metrics as $metric) {
33
            $key = implode($this->config['apcu_key_separator'], [$this->config['apcu_key_prefix'], $metric['name'], $metric['type'], '']);
34
            apcu_store($key, $metric['value'], $this->config['apcu_key_max_age']);
35
        }
36
    }
37
}