Skip to content

Commit d28bc76

Browse files
Skip unreadable filesystems (#392)
* Skip unreadable filesystems * Formatting * Rescue exception * Use `Pulse::rescue` * Reset handler --------- Co-authored-by: Tim MacDonald <[email protected]>
1 parent 8fac922 commit d28bc76

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Recorders/Servers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function record(SharedBeat $event): void
8686
'memory_used' => $memoryUsed,
8787
'memory_total' => $memoryTotal,
8888
'storage' => collect($this->config->get('pulse.recorders.'.self::class.'.directories')) // @phpstan-ignore argument.templateType, argument.templateType
89+
->filter(fn (string $directory) => ($this->pulse->rescue(fn () => disk_total_space($directory)) ?? false) !== false)
8990
->map(fn (string $directory) => [
9091
'directory' => $directory,
9192
'total' => $total = intval(round(disk_total_space($directory) / 1024 / 1024)), // MB

tests/Feature/Recorders/ServersTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@
6262
Servers::detectCpuUsing(null);
6363
Servers::detectMemoryUsing(null);
6464
});
65+
66+
it('skips missing filesystems when recording events', function () {
67+
Pulse::handleExceptionsUsing(function () {
68+
//
69+
});
70+
Config::set('pulse.recorders.'.Servers::class . '.directories', ['/', '/nonexistent']);
71+
Date::setTestNow(Date::now()->startOfMinute());
72+
73+
event(new SharedBeat(CarbonImmutable::now(), 'instance-id'));
74+
Pulse::ingest();
75+
76+
$value = Pulse::ignore(fn () => DB::table('pulse_values')->sole());
77+
78+
$payload = json_decode($value->value);
79+
expect($payload->storage)->toHaveCount(1);
80+
});

0 commit comments

Comments
 (0)