Skip to content

Commit 1530f8d

Browse files
feat: make ServerMetricsService optional in PrometheusController
Make ServerMetricsService dependency optional to handle cases where the Gophpeek\SystemMetrics package is not installed. The Prometheus endpoint will work without server metrics, exporting only queue metrics. Note: Server metrics require gophpeek/system-metrics package. When not available, Prometheus export continues with queue metrics only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d3b4132 commit 1530f8d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"Bash(curl:*)",
4343
"Bash(/Users/sylvester/Library/Application\\ Support/Herd/bin/php:*)",
4444
"Bash(/Users/sylvester/Library/Application Support/Herd/bin/php:*)",
45-
"Bash(composer dump-autoload:*)"
45+
"Bash(composer dump-autoload:*)",
46+
"Bash(timeout 10 php:*)"
4647
],
4748
"deny": [],
4849
"ask": []

src/Http/Controllers/PrometheusController.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public function __construct(
1919
private MetricsQueryService $metricsQuery,
2020
private QueueMetricsConfig $config,
21-
private ServerMetricsService $serverMetrics,
21+
private ?ServerMetricsService $serverMetrics = null,
2222
) {}
2323

2424
public function __invoke(): Response
@@ -68,8 +68,16 @@ public function __invoke(): Response
6868
'Overall health score (0-100)'
6969
);
7070

71-
// Server resource metrics
72-
$serverMetrics = $this->serverMetrics->getCurrentMetrics();
71+
// Server resource metrics (only if ServerMetricsService is available)
72+
if ($this->serverMetrics !== null) {
73+
try {
74+
$serverMetrics = $this->serverMetrics->getCurrentMetrics();
75+
} catch (\Throwable $e) {
76+
$serverMetrics = ['available' => false];
77+
}
78+
} else {
79+
$serverMetrics = ['available' => false];
80+
}
7381

7482
if ($serverMetrics['available']) {
7583
// Type-safe extraction with proper PHPDoc syntax for string keys

0 commit comments

Comments
 (0)