Skip to content

Conversation

@CorentinMre
Copy link
Contributor

@CorentinMre CorentinMre commented Oct 12, 2025

Description

Fixes memory usage calculation in monitoring to reflect actual memory usage excluding cache/buffers.

Problem

The current implementation uses v.Used which includes Linux cache and buffers, leading to:

  • Inflated memory usage percentages (often 80-90% on healthy systems)
  • False positive alerts when memory is actually available
  • Misleading monitoring metrics

Solution

Changed the calculation to use Total - Available which:

  • Excludes cache/buffers that can be freed automatically
  • Matches the behavior of free -h command
  • Provides accurate memory pressure monitoring

Testing

Tested on VPS (1.928 GiB RAM):

  • Before: Monitoring showed 300 MiB while free -h showed 1.33 GiB used
  • After: Both report 1.33 GiB (the real memory usage)

In Code

  • Replace v.Used with (Total - Available) calculation

- Replace v.Used with (Total - Available) calculation
- Provides accurate memory usage for monitoring alerts
- Prevents false alerts caused by Linux cache/buffers
- Aligns with 'free -h' available memory metric
@CorentinMre
Copy link
Contributor Author

CPU Usage

Using cpu.Percent(0, false) provides instantaneous measurements which are:

  • Unreliable and often showing 0% or incorrect values
  • Not representative of actual CPU load
  • Inconsistent with standard monitoring tools

Solutions

Changed to use cpu.Percent(time.Second, false) which:

  • Observes CPU usage over 1 second for accurate measurement
  • Provides reliable and consistent metrics
  • Aligns with standard monitoring practices

Testing

CPU:

  • Before: Often showing "3%-4% or inconsistent values with instantaneous measurement
  • After: Accurate measurements matching system load (tested under various loads)

@Siumauricio Siumauricio merged commit 6fb3584 into Dokploy:canary Oct 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants