Completed
Push — graph-cache ( 447735 )
by Tony
10:09
created

RRDGraph   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A fetch() 0 8 1
1
<?php
2
/**
3
 * RRDGraph.php
4
 *
5
 * -Description-
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
26
namespace App\Data;
27
28
29
use Cache;
30
31
class RRDGraph extends RRD
32
{
33
    protected $supported_formats = ['png'];
34
    private $key;
35
36
    public function __construct($definitions, $start, $end, $width, $height)
37
    {
38
        $args = " graph - -s $start -e $end  --width $width --height $height ".
39
            "--alt-autoscale-max --rigid -E -c BACK#EEEEEE00 -c SHADEA#EEEEEE00 -c SHADEB#EEEEEE00 -c \
40
            FONT#000000 -c CANVAS#FFFFFF00 -c GRID#a5a5a5 -c MGRID#FF9999 -c FRAME#5e5e5e -c ARROW#5e5e5e \
41
            -R normal --font LEGEND:8:DejaVuSansMono --font AXIS:7:DejaVuSansMono --font-render-mode normal ".
42
            $definitions;
43
44
        parent::__construct($args);
45
46
        $this->key = $this->genKey('graph', $definitions, $this->roundTime($start), $this->roundTime($end), $width, $height);
47
    }
48
49
    /**
50
     * Return the output from this data source
51
     * May be base64 encoded PNG, Json Data, or CSV Data
52
     *
53
     * @param string $format png, json, or csv
54
     * @return string
55
     */
56
    public function fetch($format)
57
    {
58
        $this->checkFormatSupported($format);
59
60
        return Cache::tags('graphs')->remember($this->key, 5, function () {
61
            return base64_encode($this->run());
62
        });
63
    }
64
}
65