Dokploy / Dokploy/dokploy

Container monitoring metrics return null due to name mismatch in GetLastNContainerMetrics

Open
#3,465 1 comment 1 reaction 0 assignees View on GitHub

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 records
  • SELECT 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:

  1. Remove the name truncation logic from GetLastNContainerMetrics and GetAllMetricsContainer
  2. Or apply the same truncation logic in SaveContainerMetric before saving

Environment

  • Dokploy Cloud with remote node
  • dokploy/monitoring:latest image
  • Ubuntu 24.04.3 LTS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.