1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/* |
5
|
|
|
* This file is part of PhuninNode. |
6
|
|
|
* |
7
|
|
|
** (c) 2013 - 2016 Cees-Jan Kiewiet |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
/* |
15
|
|
|
* This file is part of PhuninNode. |
16
|
|
|
* |
17
|
|
|
** (c) 2013 - 2016 Cees-Jan Kiewiet |
18
|
|
|
* |
19
|
|
|
* For the full copyright and license information, please view the LICENSE |
20
|
|
|
* file that was distributed with this source code. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
declare(strict_types=1); |
24
|
|
|
/* |
25
|
|
|
* This file is part of PhuninNode. |
26
|
|
|
* |
27
|
|
|
** (c) 2013 - 2016 Cees-Jan Kiewiet |
28
|
|
|
* |
29
|
|
|
* For the full copyright and license information, please view the LICENSE |
30
|
|
|
* file that was distributed with this source code. |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
namespace WyriHaximus\PhuninNode\Plugins; |
34
|
|
|
|
35
|
|
|
use React\Promise\Deferred; |
36
|
|
|
use WyriHaximus\PhuninNode\Configuration; |
37
|
|
|
use WyriHaximus\PhuninNode\Node; |
38
|
|
|
use WyriHaximus\PhuninNode\PluginInterface; |
39
|
|
|
use WyriHaximus\PhuninNode\Value; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Class MultiGraph |
43
|
|
|
* @package WyriHaximus\PhuninNode\Plugins |
44
|
|
|
*/ |
45
|
|
|
class MultiGraph implements PluginInterface |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
/** |
48
|
|
|
* @var Node |
49
|
|
|
*/ |
50
|
|
|
private $node; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $plugins = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param PluginInterface[] $plugins |
59
|
|
|
*/ |
60
|
|
|
public function __construct(array $plugins) |
61
|
|
|
{ |
62
|
|
|
$this->plugns = $plugins; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function setNode(Node $node) |
69
|
|
|
{ |
70
|
|
|
$this->node = $node; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function getSlug() |
77
|
|
|
{ |
78
|
|
|
return 'uptime'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getConfiguration(Deferred $deferred) |
85
|
|
|
{ |
86
|
|
|
$this->configuration = new Configuration(); |
|
|
|
|
87
|
|
|
$this->configuration->setPair('graph_category', 'phunin_node'); |
88
|
|
|
$this->configuration->setPair('graph_title', 'Uptime'); |
89
|
|
|
$this->configuration->setPair('graph_args', '--base 1000 -l 0'); |
90
|
|
|
$this->configuration->setPair('graph_vlabel', 'uptime in days'); |
91
|
|
|
$this->configuration->setPair('uptime.label', 'uptime'); |
92
|
|
|
$this->configuration->setPair('uptime.draw', 'AREA'); |
93
|
|
|
|
94
|
|
|
$deferred->resolve($this->configuration); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getValues(Deferred $deferred) |
101
|
|
|
{ |
102
|
|
|
$values = new \SplObjectStorage; |
103
|
|
|
$values->attach($this->getUptimeValue()); |
104
|
|
|
$deferred->resolve($values); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return \WyriHaximus\PhuninNode\Value |
109
|
|
|
*/ |
110
|
|
|
private function getUptimeValue() |
111
|
|
|
{ |
112
|
|
|
$value = new Value(); |
|
|
|
|
113
|
|
|
$value->setKey('uptime'); |
|
|
|
|
114
|
|
|
$value->setValue(round(((time() - $this->startTime) / self::DAY_IN_SECONDS), 2)); |
|
|
|
|
115
|
|
|
return $value; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|