Completed
Push — master ( c091a3...52a46f )
by Petrică
02:24
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
class CpuAverageGauge implements GaugeInterface
11
{
12
    /**
13
     * Report every 60 seconds
14
     * Load average is calculated every 1 minute
15
     *
16
     * @return int
17
     */
18
    public function getSamplingPeriod()
19
    {
20
        return 60;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 1
    public function getValue()
27
    {
28 1
        $load = $this->getLoadAverage();
29
30 1
        $value = null;
31 1
        if (!empty($load) && isset($load[0])) {
32 1
            $value = $load[0];
33 1
        }
34
35 1
        return $value;
36
    }
37
38
    /**
39
     * Return CPU load average
40
     *
41
     * @return array
42
     */
43
    protected function getLoadAverage()
44
    {
45
        return sys_getloadavg();
46
    }
47
}
48