Fix sparkline service name mapping
- Pass service names (not slugs) to DockerStatsCollector - Create slug->name mapping for sparkline lookups - Stats are stored by service name, looked up by slug - Add debug logging when no containers found
This commit is contained in:
@@ -201,7 +201,7 @@ class DockerStatsCollector:
|
||||
refresh_counter = 0
|
||||
|
||||
while self._running:
|
||||
# Refresh container mapping every 30 iterations (~60 seconds)
|
||||
# Refresh container mapping every 30 iterations (~5 minutes at 10s interval)
|
||||
if refresh_counter % 30 == 0:
|
||||
service_to_container = await self._discover_containers(service_names)
|
||||
if service_to_container:
|
||||
@@ -209,6 +209,11 @@ class DockerStatsCollector:
|
||||
"Discovered containers: %s",
|
||||
", ".join(f"{k}={v}" for k, v in service_to_container.items()),
|
||||
)
|
||||
else:
|
||||
log.debug(
|
||||
"No containers found for services: %s",
|
||||
", ".join(service_names),
|
||||
)
|
||||
|
||||
refresh_counter += 1
|
||||
|
||||
|
||||
@@ -347,8 +347,14 @@ class LocalServer:
|
||||
if self._compose_mode and self._landing_apps:
|
||||
self._docker_stats = DockerStatsCollector()
|
||||
if self._docker_stats.available:
|
||||
containers = [app.slug for app in self._landing_apps]
|
||||
self._docker_stats.start(containers)
|
||||
# Pass service names (not slugs) for Docker matching
|
||||
# Also pass slug->name mapping so we can look up by slug
|
||||
service_names = [app.name for app in self._landing_apps]
|
||||
self._docker_stats.start(service_names)
|
||||
# Create slug->name mapping for lookups
|
||||
self._slug_to_service: dict[str, str] = {
|
||||
app.slug: app.name for app in self._landing_apps
|
||||
}
|
||||
stack.push_async_callback(self._docker_stats.stop)
|
||||
|
||||
site = web.TCPSite(runner, self.host, self.port)
|
||||
@@ -659,10 +665,12 @@ class LocalServer:
|
||||
height = 20
|
||||
height = max(10, min(100, height))
|
||||
|
||||
# Get CPU history
|
||||
# Get CPU history - map slug to service name if needed
|
||||
values: list[float] = []
|
||||
if self._docker_stats:
|
||||
values = self._docker_stats.get_cpu_history(container)
|
||||
# Container param is slug, but stats are stored by service name
|
||||
service_name = getattr(self, "_slug_to_service", {}).get(container, container)
|
||||
values = self._docker_stats.get_cpu_history(service_name)
|
||||
|
||||
svg = render_sparkline_svg(values, width=width, height=height)
|
||||
headers = {"Cache-Control": "no-cache, max-age=0"}
|
||||
|
||||
Reference in New Issue
Block a user