Container monitoring metrics return null due to name mismatch in GetLastNContainerMetrics
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 37.4k
- Forks
- 3k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 73
Description
Bug Description
Container monitoring metrics return null even though data is being collected and stored correctly in the database. The issue is in the GetLastNContainerMetrics function in apps/monitoring/database/containers.go.
Root Cause
The function truncates the container name by removing the last segment after splitting by -:
parts := strings.Split(name, "-")
if len(parts) > 1 {
containerName = strings.Join(parts[:len(parts)-1], "-")
}
However, the SaveContainerMetric function saves data with the full container name (e.g., automations-stack-xxqyba-n8n-1).
When querying, the function transforms:
- Input:
automations-stack-xxqyba-n8n-1 - Query searches for:
automations-stack-xxqyba-n8n
This results in no records being found because the data is stored with the full name.
Evidence
Direct database queries on the monitoring.db:
SELECT COUNT(*) FROM container_metrics WHERE container_name = 'automations-stack-xxqyba-n8n';→ 0 recordsSELECT COUNT(*) FROM container_metrics WHERE container_name = 'automations-stack-xxqyba-n8n-1';→ 3,524 records
Expected Behavior
The query function should search using the same name format that the save function uses, or both should use consistent name processing.
Suggested Fix
Either:
- Remove the name truncation logic from
GetLastNContainerMetricsandGetAllMetricsContainer - Or apply the same truncation logic in
SaveContainerMetricbefore saving
Environment
- Dokploy Cloud with remote node
- dokploy/monitoring:latest image
- Ubuntu 24.04.3 LTS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/monitoring/database/containers.go by comparing GetLastNContainerMetrics and GetAllMetricsContainer with SaveContainerMetric. Verify how container names are transformed before querying and storing, then make the formats consistent so the full name used in the database returns metrics instead of null. Confirm the behavior against the provided container name and database counts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100