|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Check\sys\CpuPerformance; |
|
13
|
|
|
|
|
14
|
|
|
use Tvi\MonitorBundle\Check\CheckInterface; |
|
15
|
|
|
use Tvi\MonitorBundle\Check\CheckTrait; |
|
16
|
|
|
use ZendDiagnostics\Result\Failure; |
|
17
|
|
|
use ZendDiagnostics\Result\Success; |
|
18
|
|
|
use ZendDiagnostics\Result\Warning; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
|
|
|
|
|
21
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
22
|
|
|
*/ |
|
|
|
|
|
|
23
|
|
|
class Check extends \ZendDiagnostics\Check\CpuPerformance implements CheckInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use CheckTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
|
|
|
|
|
30
|
2 |
|
public function check() |
|
31
|
|
|
{ |
|
32
|
|
|
// Check if bcmath extension is present |
|
33
|
|
|
// @codeCoverageIgnoreStart |
|
34
|
|
|
if (!\extension_loaded('bcmath')) { |
|
35
|
|
|
return new Warning('Check\CpuPerformance requires BCMath extension to be loaded.'); |
|
36
|
|
|
} |
|
37
|
|
|
// @codeCoverageIgnoreEnd |
|
38
|
|
|
|
|
39
|
2 |
|
$timeStart = microtime(true); |
|
40
|
2 |
|
$result = static::calcPi(1000); |
|
41
|
2 |
|
$duration = microtime(true) - $timeStart; |
|
42
|
2 |
|
$performance = round($duration / $this->baseline, 5); |
|
43
|
|
|
|
|
44
|
2 |
|
if ($result !== $this->expectedResult) { |
|
45
|
|
|
// Ignore code coverage here because it's impractical to test against faulty calculations. |
|
46
|
|
|
// @codeCoverageIgnoreStart |
|
47
|
|
|
return new Warning('PI calculation failed. This might mean CPU or RAM failure', $result); |
|
48
|
|
|
// @codeCoverageIgnoreEnd |
|
|
|
|
|
|
49
|
2 |
|
} elseif ($performance > $this->minPerformance) { |
|
50
|
2 |
|
return new Success(sprintf('Cpu Performance is %.5f.', $performance), $performance); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
return new Failure(null, $performance); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|