EricMakesStuff\ServerMonitor\Monitors\DiskUsageMonitor::runMonitor PHP Method

runMonitor() public method

public runMonitor ( )
    public function runMonitor()
    {
        if (!file_exists($this->path)) {
            throw InvalidPath::pathDoesNotExist($this->path);
        }
        $this->totalSpace = disk_total_space($this->path);
        $this->freeSpace = disk_free_space($this->path);
        $this->usedSpace = $this->totalSpace - $this->freeSpace;
        $this->percentageUsed = sprintf('%.2f', $this->usedSpace / $this->totalSpace * 100);
        if ($this->percentageUsed >= $this->alarmPercentage) {
            event(new DiskUsageAlarm($this));
        } else {
            event(new DiskUsageHealthy($this));
        }
    }

Usage Example

 /** @test */
 public function it_throws_an_exception_for_nonexistent_disk()
 {
     $diskUsageMonitor = new DiskUsageMonitor(['path' => '/a234k3l2k3j4l23k/23l4j2l34j']);
     $this->setExpectedException(InvalidPath::class);
     $diskUsageMonitor->runMonitor();
 }