dokploy icon indicating copy to clipboard operation
dokploy copied to clipboard

Container monitoring metrics return null due to name mismatch in GetLastNContainerMetrics

Open jmorenobl opened this issue 10 months ago • 3 comments

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

jmorenobl avatar Jan 16 '26 11:01 jmorenobl

same problem!

midgogo avatar Jan 23 '26 14:01 midgogo

DOK-866

linear-code[bot] avatar Oct 15 '26 15:10 linear-code[bot]

Hello @jmorenobl, this issue was fixed on Feb 27, 2026 in #3813 (same bug as #3463), with a follow-up on Mar 8, 2026 in #3947 so applications and databases work too (#3896).

I have tested it on the current version (v0.30.10), and container monitoring is working fine.

If you still don't see metrics, try this:

  1. Go to Remote Servers → Setup Server → Monitoring, add the service under Include Services, and save.
  2. Wait a minute or two for the first readings to come in.

If anything else comes up, feel free to open a new issue or comment here. For now, closing this.

imrja8 avatar Oct 25 '26 15:10 imrja8