Skip to content

Commit

Permalink
Skip unreadable filesystems (#392)
Browse files Browse the repository at this point in the history
* Skip unreadable filesystems

* Formatting

* Rescue exception

* Use `Pulse::rescue`

* Reset handler

---------

Co-authored-by: Tim MacDonald <hello@timacdonald.me>
  • Loading branch information
27pchrisl and timacdonald authored Jul 8, 2024
1 parent 8fac922 commit d28bc76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Recorders/Servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function record(SharedBeat $event): void
'memory_used' => $memoryUsed,
'memory_total' => $memoryTotal,
'storage' => collect($this->config->get('pulse.recorders.'.self::class.'.directories')) // @phpstan-ignore argument.templateType, argument.templateType
->filter(fn (string $directory) => ($this->pulse->rescue(fn () => disk_total_space($directory)) ?? false) !== false)
->map(fn (string $directory) => [
'directory' => $directory,
'total' => $total = intval(round(disk_total_space($directory) / 1024 / 1024)), // MB
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/Recorders/ServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@
Servers::detectCpuUsing(null);
Servers::detectMemoryUsing(null);
});

it('skips missing filesystems when recording events', function () {
Pulse::handleExceptionsUsing(function () {
//
});
Config::set('pulse.recorders.'.Servers::class . '.directories', ['/', '/nonexistent']);
Date::setTestNow(Date::now()->startOfMinute());

event(new SharedBeat(CarbonImmutable::now(), 'instance-id'));
Pulse::ingest();

$value = Pulse::ignore(fn () => DB::table('pulse_values')->sole());

$payload = json_decode($value->value);
expect($payload->storage)->toHaveCount(1);
});

0 comments on commit d28bc76

Please sign in to comment.