|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of PhuninNode. |
|
5
|
|
|
* |
|
6
|
|
|
** (c) 2013 - 2015 Cees-Jan Kiewiet |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WyriHaximus\React\ChildProcess\Pool\PhuninNode; |
|
13
|
|
|
|
|
14
|
|
|
use React\Promise\PromiseInterface; |
|
15
|
|
|
use WyriHaximus\PhuninNode\Configuration; |
|
16
|
|
|
use WyriHaximus\PhuninNode\Metric; |
|
17
|
|
|
use WyriHaximus\PhuninNode\Node; |
|
18
|
|
|
use WyriHaximus\PhuninNode\PluginInterface; |
|
19
|
|
|
use WyriHaximus\React\ChildProcess\Pool\Info; |
|
20
|
|
|
use WyriHaximus\React\ChildProcess\Pool\PoolInfoInterface; |
|
21
|
|
|
use function React\Promise\resolve; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class MemoryUsage |
|
25
|
|
|
* @package WyriHaximus\PhuninNode\Plugins |
|
26
|
|
|
*/ |
|
27
|
|
|
class Pool implements PluginInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var PoolInfoInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $pool; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $title; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $slug; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $categorySlug; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Node |
|
51
|
|
|
*/ |
|
52
|
|
|
private $node; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Cached configuration state |
|
56
|
|
|
* |
|
57
|
|
|
* @var Configuration |
|
58
|
|
|
*/ |
|
59
|
|
|
private $configuration; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Pool constructor. |
|
63
|
|
|
* @param PoolInfoInterface $pool |
|
64
|
|
|
* @param string $slug |
|
65
|
|
|
* @param string $categorySlug |
|
66
|
|
|
* @param string $title |
|
67
|
|
|
*/ |
|
68
|
7 |
|
public function __construct(PoolInfoInterface $pool, $title, $slug, $categorySlug) |
|
69
|
|
|
{ |
|
70
|
7 |
|
$this->pool = $pool; |
|
71
|
7 |
|
$this->title = $title; |
|
72
|
7 |
|
$this->slug = $slug; |
|
73
|
7 |
|
$this->categorySlug = $categorySlug; |
|
74
|
7 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
7 |
|
public function setNode(Node $node) |
|
80
|
|
|
{ |
|
81
|
7 |
|
$this->node = $node; |
|
82
|
7 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function getSlug(): string |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $this->slug; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getCategorySlug(): string |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->categorySlug; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritdoc} |
|
102
|
|
|
*/ |
|
103
|
2 |
|
public function getConfiguration(): PromiseInterface |
|
104
|
|
|
{ |
|
105
|
2 |
|
if ($this->configuration instanceof Configuration) { |
|
106
|
1 |
|
return resolve($this->configuration); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
2 |
|
$this->configuration = new Configuration(); |
|
110
|
2 |
|
$this->configuration->setPair('graph_category', $this->categorySlug); |
|
111
|
2 |
|
$this->configuration->setPair('graph_title', $this->title); |
|
112
|
2 |
|
$this->configuration->setPair('current_size.label', 'Current Pool size'); |
|
113
|
2 |
|
$this->configuration->setPair('current_queued_calls.label', 'Current Queued call count'); |
|
114
|
2 |
|
$this->configuration->setPair('current_busy.label', 'Current Busy worker count'); |
|
115
|
2 |
|
$this->configuration->setPair('current_idle_workers.label', 'Current Idle Workers count'); |
|
116
|
|
|
|
|
117
|
2 |
|
return resolve($this->configuration); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* {@inheritdoc} |
|
122
|
|
|
*/ |
|
123
|
2 |
|
public function getValues(): PromiseInterface |
|
124
|
|
|
{ |
|
125
|
2 |
|
$info = $this->pool->info(); |
|
126
|
2 |
|
$storage = new \SplObjectStorage(); |
|
127
|
2 |
|
$storage->attach(new Metric('current_size', $info[Info::SIZE])); |
|
128
|
2 |
|
$storage->attach(new Metric('current_busy', $info[Info::BUSY])); |
|
129
|
2 |
|
$storage->attach(new Metric('current_queued_calls', $info[Info::CALLS])); |
|
130
|
2 |
|
$storage->attach(new Metric('current_idle_workers', $info[Info::IDLE])); |
|
131
|
2 |
|
return resolve($storage); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|