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

CpuAverageGauge   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 0
cbo 1
dl 0
loc 40
ccs 10
cts 12
cp 0.8333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSamplingPeriod() 0 4 1
A getCollection() 0 13 3
A getLoadAverage() 0 4 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