|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Innmind\ProvisionerBundle\Alert; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Hold any data relative to an alert |
|
9
|
|
|
*/ |
|
10
|
|
|
class Alert |
|
11
|
|
|
{ |
|
12
|
|
|
const UNDER_USED = 'under_used'; |
|
13
|
|
|
const OVER_USED = 'over_used'; |
|
14
|
|
|
|
|
15
|
|
|
protected $type; |
|
16
|
|
|
protected $commandName; |
|
17
|
|
|
protected $commandInput; |
|
18
|
|
|
protected $cpuUsage; |
|
19
|
|
|
protected $loadAverage; |
|
20
|
|
|
protected $runningProcesses; |
|
21
|
|
|
protected $leftOver = 0; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Set the alert type to under used |
|
25
|
|
|
* |
|
26
|
|
|
* @return Alert self |
|
27
|
|
|
*/ |
|
28
|
21 |
|
public function setUnderUsed() |
|
29
|
|
|
{ |
|
30
|
21 |
|
$this->type = self::UNDER_USED; |
|
31
|
|
|
|
|
32
|
21 |
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Check if the alert is of under used type |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
30 |
|
public function isUnderUsed() |
|
41
|
|
|
{ |
|
42
|
30 |
|
return $this->type === self::UNDER_USED; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Set the alert type to over used |
|
47
|
|
|
* |
|
48
|
|
|
* @return Alert self |
|
49
|
|
|
*/ |
|
50
|
18 |
|
public function setOverUsed() |
|
51
|
|
|
{ |
|
52
|
18 |
|
$this->type = self::OVER_USED; |
|
53
|
|
|
|
|
54
|
18 |
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Check if the alert is of over used type |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
33 |
|
public function isOverUsed() |
|
63
|
|
|
{ |
|
64
|
33 |
|
return $this->type === self::OVER_USED; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Return the alert type as string |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
21 |
|
public function getType() |
|
73
|
|
|
{ |
|
74
|
21 |
|
return $this->type; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set the command name |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $name |
|
81
|
|
|
* |
|
82
|
|
|
* @return Alert self |
|
83
|
|
|
*/ |
|
84
|
45 |
|
public function setCommandName($name) |
|
85
|
|
|
{ |
|
86
|
45 |
|
$this->commandName = (string) $name; |
|
87
|
|
|
|
|
88
|
45 |
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Return the command name |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
21 |
|
public function getCommandName() |
|
97
|
|
|
{ |
|
98
|
21 |
|
return $this->commandName; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Set the command input |
|
103
|
|
|
* |
|
104
|
|
|
* @param InputInterface $input |
|
105
|
|
|
* |
|
106
|
|
|
* @return Alert self |
|
107
|
|
|
*/ |
|
108
|
45 |
|
public function setCommandInput(InputInterface $input) |
|
109
|
|
|
{ |
|
110
|
45 |
|
$this->commandInput = $input; |
|
111
|
|
|
|
|
112
|
45 |
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Return the command input |
|
117
|
|
|
* |
|
118
|
|
|
* @return InputInterface |
|
119
|
|
|
*/ |
|
120
|
36 |
|
public function getCommandInput() |
|
121
|
|
|
{ |
|
122
|
36 |
|
return $this->commandInput; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set the server CPU usage at provision time |
|
127
|
|
|
* |
|
128
|
|
|
* @param float $usage |
|
129
|
|
|
* |
|
130
|
|
|
* @return Alert self |
|
131
|
|
|
*/ |
|
132
|
45 |
|
public function setCpuUsage($usage) |
|
133
|
|
|
{ |
|
134
|
45 |
|
$this->cpuUsage = (float) $usage; |
|
135
|
|
|
|
|
136
|
45 |
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Return the CPU usage |
|
141
|
|
|
* |
|
142
|
|
|
* @return float |
|
143
|
|
|
*/ |
|
144
|
36 |
|
public function getCpuUsage() |
|
145
|
|
|
{ |
|
146
|
36 |
|
return $this->cpuUsage; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Set the server load average at provision time |
|
151
|
|
|
* |
|
152
|
|
|
* @param float $load |
|
153
|
|
|
* |
|
154
|
|
|
* @return Alert self |
|
155
|
|
|
*/ |
|
156
|
45 |
|
public function setLoadAverage($load) |
|
157
|
|
|
{ |
|
158
|
45 |
|
$this->loadAverage = (float) $load; |
|
159
|
|
|
|
|
160
|
45 |
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Return the load average |
|
165
|
|
|
* |
|
166
|
|
|
* @return float |
|
167
|
|
|
*/ |
|
168
|
36 |
|
public function getLoadAverage() |
|
169
|
|
|
{ |
|
170
|
36 |
|
return $this->loadAverage; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Set the number of already running processes of the command |
|
175
|
|
|
* being provisioned |
|
176
|
|
|
* |
|
177
|
|
|
* @param int $count |
|
178
|
|
|
* |
|
179
|
|
|
* @return Alert self |
|
180
|
|
|
*/ |
|
181
|
33 |
|
public function setRunningProcesses($count) |
|
182
|
|
|
{ |
|
183
|
33 |
|
$this->runningProcesses = (int) $count; |
|
184
|
|
|
|
|
185
|
33 |
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Return the number of processes running for the associated command |
|
190
|
|
|
* |
|
191
|
|
|
* @return int |
|
192
|
|
|
*/ |
|
193
|
27 |
|
public function getRunningProcesses() |
|
194
|
|
|
{ |
|
195
|
27 |
|
return $this->runningProcesses; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Set the number of processes that couldn't be launched |
|
200
|
|
|
* |
|
201
|
|
|
* @param int $leftOver |
|
202
|
|
|
* |
|
203
|
|
|
* @return Alert self |
|
204
|
|
|
*/ |
|
205
|
45 |
|
public function setLeftOver($leftOver) |
|
206
|
|
|
{ |
|
207
|
45 |
|
$this->leftOver = (int) $leftOver; |
|
208
|
|
|
|
|
209
|
45 |
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Return the number of processes that couldn't be launched |
|
214
|
|
|
* |
|
215
|
|
|
* @return int |
|
216
|
|
|
*/ |
|
217
|
27 |
|
public function getLeftOver() |
|
218
|
|
|
{ |
|
219
|
27 |
|
return $this->leftOver; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|