|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Tvi\MonitorBundle\Check\DiskUsage; |
|
12
|
|
|
|
|
13
|
|
|
use ZendDiagnostics\Result\Failure; |
|
14
|
|
|
use ZendDiagnostics\Result\Success; |
|
15
|
|
|
use ZendDiagnostics\Result\SuccessInterface; |
|
16
|
|
|
use ZendDiagnostics\Result\Warning; |
|
17
|
|
|
use ZendDiagnostics\Result\WarningInterface; |
|
18
|
|
|
use ZendDiagnostics\Result\SkipInterface; |
|
19
|
|
|
use ZendDiagnostics\Result\FailureInterface; |
|
20
|
|
|
|
|
21
|
|
|
use Tvi\MonitorBundle\Check\CheckInterface; |
|
22
|
|
|
use Tvi\MonitorBundle\Check\CheckTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
|
|
|
|
|
25
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
class Check extends \ZendDiagnostics\Check\DiskUsage implements CheckInterface |
|
28
|
|
|
{ |
|
29
|
|
|
use CheckTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
|
|
|
|
|
32
|
|
|
* @inheritdoc |
|
33
|
|
|
*/ |
|
|
|
|
|
|
34
|
|
|
public function check() |
|
35
|
|
|
{ |
|
36
|
|
|
$df = disk_free_space($this->path); |
|
37
|
|
|
$dt = disk_total_space($this->path); |
|
38
|
|
|
|
|
39
|
|
|
$du = $dt - $df; |
|
40
|
|
|
$dp = round(($du / $dt) * 100, 2); |
|
41
|
|
|
|
|
42
|
|
|
if ($dp >= $this->criticalThreshold) { |
|
43
|
|
|
return new Failure(sprintf('Disk usage too high: %.2f %%.', $dp), $dp); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($dp >= $this->warningThreshold) { |
|
47
|
|
|
return new Warning(sprintf('Disk usage high: %.2f %%.', $dp), $dp); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return new Success(sprintf('Disk usage is %.5f %%.', $dp), $dp); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|