Completed
Push — master ( e2c5a9...852a9e )
by Petrică
02:20
created

CpuAverageGauge::getSamplingPeriod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * CPU average load path reported to statsd
25
     *
26
     * @return string
27
     */
28
    public function getPath()
29
    {
30
        return 'cpu.load.average';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getValue()
37
    {
38
        $load = $this->getLoadAverage();
39
40
        $value = null;
41
        if ($load && isset($load[0])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $load of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
42
            $value = $load[0];
43
        }
44
45
        return $value;
46
    }
47
48
    /**
49
     * Return CPU load average
50
     *
51
     * @return array
52
     */
53
    protected function getLoadAverage()
54
    {
55
        return sys_getloadavg();
56
    }
57
}