Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class SpaceUsedCheck implements Check |
||
10 | { |
||
11 | const IDENTIFIER = 'base:device:spaceUsed'; |
||
12 | |||
13 | private $maxUsageInPercent = 95; |
||
14 | |||
15 | private $directory = '/'; |
||
16 | |||
17 | public function init($maxUsageInPercent, $directory = '/') |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Checks if the space left on device is sufficient |
||
25 | * |
||
26 | * @return Result |
||
27 | */ |
||
28 | public function run() |
||
29 | { |
||
30 | $free = disk_free_space($this->directory); |
||
31 | $total = disk_total_space($this->directory); |
||
32 | |||
33 | $usage = 100 - round(($free / $total) * 100); |
||
34 | |||
35 | if ($usage > $this->maxUsageInPercent) { |
||
36 | $result = new MetricAwareResult(Result::STATUS_FAIL, 'No space left on device. ' . $usage . '% used (' . $this->directory . ').'); |
||
37 | } else { |
||
38 | $result = new MetricAwareResult(Result::STATUS_PASS, 'Enough space left on device. ' . $usage . '% used (' . $this->directory . ').'); |
||
39 | } |
||
40 | |||
41 | $result->setMetric($usage / 100, 'percent', MetricAwareResult::METRIC_TYPE_PERCENT); |
||
42 | $result->setLimit($this->maxUsageInPercent / 100); |
||
43 | $result->setLimitType(MetricAwareResult::LIMIT_TYPE_MAX); |
||
44 | $result->setObservedValuePrecision(2); |
||
45 | |||
46 | return $result; |
||
47 | } |
||
48 | |||
49 | public function getIdentifier() |
||
52 | } |
||
53 | } |
||
54 |