Passed
Branch master (98e19a)
by Petrică
02:49 queued 10s
created

CpuAverageGauge::getValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 6
nc 2
nop 0
crap 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Petrica
5
 * Date: 3/22/2016
6
 * Time: 23:03
7
 */
8
namespace Petrica\StatsdSystem\Gauge;
9
10
use Petrica\StatsdSystem\Collection\ValuesCollection;
11
12
class CpuAverageGauge implements GaugeInterface
13
{
14
    /**
15
     * Report every 60 seconds
16
     * Load average is calculated every 1 minute
17
     *
18
     * @return int
19
     */
20 1
    public function getSamplingPeriod()
21
    {
22 1
        return 60;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function getCollection()
29
    {
30 1
        $collection = new ValuesCollection();
31
32 1
        $load = $this->getLoadAverage();
33
34 1
        $value = null;
35 1
        if (!empty($load) && isset($load[0])) {
36 1
            $value = $load[0];
37 1
        }
38
39 1
        return $collection->add('load.average', $value);
40
    }
41
42
    /**
43
     * Return CPU load average
44
     *
45
     * @return array
46
     */
47
    protected function getLoadAverage()
48
    {
49
        return sys_getloadavg();
50
    }
51
}
52