Completed
Push — master ( e19dd9...c43d00 )
by Freek
02:00
created

Diskspace::performNextRunInMinutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\ServerMonitor\CheckDefinitions;
4
5
use Spatie\Regex\Regex;
6
use Symfony\Component\Process\Process;
7
8
final class Diskspace extends CheckDefinition
9
{
10
    public $command = 'df -P .';
11
12
    public function handleSuccessfulProcess(Process $process)
13
    {
14
        $percentage = $this->getDiskUsagePercentage($process->getOutput());
15
16
        $message = "usage at {$percentage}%";
17
18
        if ($percentage >= 90) {
19
            $this->check->failed($message);
20
21
            return;
22
        }
23
24
        if ($percentage >= 80) {
25
            $this->check->warn($message);
26
27
            return;
28
        }
29
30
        $this->check->succeeded($message);
31
    }
32
33
    protected function getDiskUsagePercentage(string $commandOutput): int
34
    {
35
        return (int) Regex::match('/(\d?\d)%/', $commandOutput)->group(1);
36
    }
37
}
38