Repository navigation
fix(monitoring): show stats for compose and stack containers - #113
Merged
Merged
Conversation
The Monitoring tab of a compose or stack service stayed empty: CPU,
memory, block and network I/O were all zero and no error was shown.
The tab asks for stats of one container, named after the container
("<project>-<service>-1" for compose, "<stack>_<service>.1.<task>" for a
stack), not after the Dokploy service. The fork's metrics access check
looked that name up as a service appName, found nothing and refused, so
the stats socket closed at once without a reason and readAppMonitoring
returned UNAUTHORIZED. Applications and databases were not affected,
because their container is named after the service.
When the name matches no service and no metrics server is involved, the
check now reads the local container's owner labels (compose project,
stack namespace, swarm service), takes the service they point to and
applies the same organization and monitoring-read checks to it. Only an
exact container name counts (docker inspect also resolves ID prefixes),
and only services on this host, since only local containers are seen.
The stats socket now closes with 4003 "Not authorized" when access is
refused, so the page shows why instead of staying blank.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Вкладка Monitoring у сервиса compose или stack оставалась пустой: CPU, память, Block I/O и Network I/O показывали нули, и никакой ошибки не появлялось. Теперь у каждого контейнера compose и stack видно, сколько ресурсов он использует, и после открытия вкладки подгружается история графиков.
Причина
Вкладка запрашивает статистику одного контейнера по его имени (
<project>-<service>-1у compose,<stack>_<service>.1.<task>у stack), а не по имени сервиса Dokploy. Проверка доступа к метрикам в форке искала это имя средиappNameсервисов, ничего не находила и отказывала. Сокет/listen-docker-stats-monitoringзакрывался сразу без причины (код 1005), аapplication.readAppMonitoringвозвращалUNAUTHORIZED. У приложений и баз контейнер называется так же, как сервис, поэтому их это не касалось.Что изменилось
assertContainerMetricsServiceAccess: если имя не совпало ни с одним сервисом и запрос не идёт к серверу метрик, владелец берётся из меток локального контейнера (com.docker.compose.project,com.docker.stack.namespace,com.docker.swarm.service.name). К найденному сервису применяются те же проверки: организация и правоmonitoring.read.docker inspectпонимает и префиксы ID, такие совпадения отбрасываются. Учитываются только сервисы этого хоста, потому что проверка видит только локальные контейнеры.Not authorized, и страница показывает причину, а не остаётся пустой.Проверки
__test__/monitoring/container-metrics-access.test.ts(9 тестов): контейнер compose и задача stack находят свой сервис; имя сервиса не вызывает docker; отказ при совпадении по префиксу ID, при чужой организации, при сервисе на удалённом сервере, без меток, при ошибке docker, при запросе к серверу метрик и при имени, которое не является идентификатором docker. Без исправления падают оба теста про compose и stack.__test__/wss/docker-stats.test.ts: при отказе в доступе сокет закрывается с 4003Not authorizedи не опрашивает docker.tsc --noEmitвapps/dokployпроходит, Biome без новых замечаний.application.real.test.ts) и два теста Traefik с таймаутом 5 с под нагрузкой; отдельно эти два проходят и здесь, и наAgentHits-Dev.com.docker.compose.projectсappNameсервиса.🤖 Generated with Claude Code