Skip to content

Container monitoring metrics return null due to name mismatch in GetLastNContainerMetrics #3465

@jmorenobl

Description

@jmorenobl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions