|
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\fs\DiskFree; |
|
12
|
|
|
|
|
13
|
|
|
use ZendDiagnostics\Result\Failure; |
|
14
|
|
|
use ZendDiagnostics\Result\Success; |
|
15
|
|
|
use ZendDiagnostics\Result\Warning; |
|
16
|
|
|
|
|
17
|
|
|
use Tvi\MonitorBundle\Check\CheckInterface; |
|
18
|
|
|
use Tvi\MonitorBundle\Check\CheckTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
|
|
|
|
|
21
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
22
|
|
|
*/ |
|
|
|
|
|
|
23
|
|
|
class Check extends \ZendDiagnostics\Check\DiskFree implements CheckInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use CheckTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
|
|
|
|
|
28
|
|
|
* @inheritdoc |
|
29
|
|
|
*/ |
|
|
|
|
|
|
30
|
2 |
|
public function check() |
|
31
|
|
|
{ |
|
32
|
|
|
// We are using error suppression because the method will trigger a warning |
|
33
|
|
|
// in case of non-existent paths and other errors. We are more interested in |
|
34
|
|
|
// the potential return value of FALSE, which will tell us that free space |
|
35
|
|
|
// could not be obtained and we do not care about the real cause of this. |
|
36
|
2 |
|
$free = @ disk_free_space($this->path); |
|
37
|
|
|
|
|
38
|
2 |
|
if ($free === false || ! is_float($free) || $free < 0) { |
|
39
|
|
|
return new Warning('Unable to determine free disk space at ' . $this->path .'.'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
$freeHumanReadable = static::bytesToString($free, 2); |
|
|
|
|
|
|
43
|
2 |
|
$minFreeHumanReadable = static::bytesToString($this->minDiskBytes, 2); |
|
44
|
2 |
|
$description = sprintf('Remaining space at %s: %s, requared min: %s.', $this->path, $freeHumanReadable, $minFreeHumanReadable); |
|
45
|
|
|
|
|
46
|
2 |
|
if (disk_free_space($this->path) < $this->minDiskBytes) { |
|
47
|
|
|
return new Failure($description, $free); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
return new Success($description, $free); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|