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

AbstractMemoryGauge::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/24/2016
6
 * Time: 1:17
7
 */
8
namespace Petrica\StatsdSystem\Gauge;
9
10
abstract class AbstractMemoryGauge implements GaugeInterface
11
{
12
    const MEMINFO_PATH = '/proc/meminfo';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getSamplingPeriod()
18
    {
19
        return 10;
20
    }
21
22
    /**
23
     * Only for linux/unix OS
24
     *
25
     * @return array
26
     */
27
    protected function getSystemMemoryInfo()
28
    {
29
        $meminfo = array();
30
31
        if (file_exists(static::MEMINFO_PATH)) {
32
            $data = explode("\n", file_get_contents(static::MEMINFO_PATH));
33
            $meminfo = array();
34
            foreach ($data as $line) {
35
                if (!empty($line)) {
36
                    list($key, $val) = explode(":", $line);
37
38
                    $meminfo[$key] = intval($val);
39
                }
40
            }
41
        }
42
43
        return $meminfo;
44
    }
45
}