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

Diskspace   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleSuccessfulProcess() 0 20 3
A getDiskUsagePercentage() 0 4 1
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