Completed
Push — master ( 52a46f...98e19a )
by Petrică
02:29
created

CpuAverageGauge::getSamplingPeriod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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