Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

CorentinMre
Copy link

@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
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)

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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.