Completed
Push — master ( c091a3...52a46f )
by Petrică
02:24
created

CpuAverageGauge::getSamplingPeriod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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