[GH-ISSUE #1231] 内存统计显示不正确 #7793

Closed
opened 2026-03-12 22:48:05 +03:00 by kerem · 7 comments
Owner

Originally created by @gang929 on GitHub (Jul 14, 2025).
Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1231

在主机上用free 命令显示 为
XXXX:~# free
total used free shared buff/cache available
Mem: 8131956 919524 3721500 85052 3887004 7212432

而在Nginx UI的dashboard中显示的内存为 523M.

估计是因为 nginx所使用的used算法是 total - free - buff/cache
而 free 命令的算法是 total - available

Originally created by @gang929 on GitHub (Jul 14, 2025). Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1231 在主机上用free 命令显示 为 XXXX:~# free total used free shared buff/cache available Mem: 8131956 919524 3721500 85052 3887004 7212432 而在Nginx UI的dashboard中显示的内存为 523M. 估计是因为 nginx所使用的used算法是 total - free - buff/cache 而 free 命令的算法是 total - available
kerem 2026-03-12 22:48:05 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@0xJacky commented on GitHub (Jul 15, 2025):

您好,请提供一下操作系统,部署方式(直接安装 or 容器部署),Dashboard 截图以及 free -m 输出。因为这个部分是 gopsutil 直接返回的,我们没有做加减操作。

<!-- gh-comment-id:3073012248 --> @0xJacky commented on GitHub (Jul 15, 2025): 您好,请提供一下操作系统,部署方式(直接安装 or 容器部署),Dashboard 截图以及 `free -m` 输出。因为这个部分是 gopsutil 直接返回的,我们没有做加减操作。
Author
Owner

@gang929 commented on GitHub (Jul 16, 2025):

操作系统 Ubuntu 22.04
部署方式 install.sh

Image
s174332:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            7941         872        3627          71        3816        7068
Swap:              0           0           0
<!-- gh-comment-id:3076386808 --> @gang929 commented on GitHub (Jul 16, 2025): 操作系统 Ubuntu 22.04 部署方式 install.sh <img width="620" height="280" alt="Image" src="https://github.com/user-attachments/assets/21faf5c5-374d-4c72-8022-2a16e9a748eb" /> ``` s174332:~# free -m total used free shared buff/cache available Mem: 7941 872 3627 71 3816 7068 Swap: 0 0 0 ```
Author
Owner

@gang929 commented on GitHub (Jul 16, 2025):

估计是gopsutil 这个算得有问题

<!-- gh-comment-id:3076387392 --> @gang929 commented on GitHub (Jul 16, 2025): 估计是gopsutil 这个算得有问题
Author
Owner

@0xJacky commented on GitHub (Jul 16, 2025):

-m 换算的应该是 MiB,当前版本是用的 MB,所以计算肯定是没问题的。

关于 MiB/MB 的问题已经在 PR #1222 中改为使用二进制进位换算,您可以更新到最新的开发版查看新的换算结果。

<!-- gh-comment-id:3076418005 --> @0xJacky commented on GitHub (Jul 16, 2025): -m 换算的应该是 MiB,当前版本是用的 MB,所以计算肯定是没问题的。 关于 MiB/MB 的问题已经在 PR #1222 中改为使用二进制进位换算,您可以更新到最新的开发版查看新的换算结果。
Author
Owner

@gang929 commented on GitHub (Jul 16, 2025):

不是换算的问题,应该是 gopsutil 是用 total - free - buff/cache 计算的,而free 是用 total - available 计算的

<!-- gh-comment-id:3076433292 --> @gang929 commented on GitHub (Jul 16, 2025): 不是换算的问题,应该是 gopsutil 是用 total - free - buff/cache 计算的,而free 是用 total - available 计算的
Author
Owner

@0xJacky commented on GitHub (Jul 16, 2025):

哦哦 看错了,我以为你说的 total

<!-- gh-comment-id:3076440099 --> @0xJacky commented on GitHub (Jul 16, 2025): 哦哦 看错了,我以为你说的 total
Author
Owner

@0xJacky commented on GitHub (Jul 17, 2025):

看了代码,确实是 total - free - buff/cache
但是新版 linux manual 的定义是:used Used or unavailable memory (calculated as total - available)

github.com/shirou/gopsutil@4a774b4303/mem/mem_linux.go (L307)

我看 gopsutil 有 issue 在讨论这个问题 https://github.com/shirou/gopsutil/issues/1873

对应 PR: https://github.com/shirou/gopsutil/pull/1882

<!-- gh-comment-id:3082270237 --> @0xJacky commented on GitHub (Jul 17, 2025): 看了代码,确实是 total - free - buff/cache 但是新版 linux manual 的定义是:used Used or unavailable memory (calculated as total - available) https://github.com/shirou/gopsutil/blob/4a774b43033f3521c46e467b5bc8902829c989fc/mem/mem_linux.go#L307 我看 gopsutil 有 issue 在讨论这个问题 https://github.com/shirou/gopsutil/issues/1873 对应 PR: https://github.com/shirou/gopsutil/pull/1882
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-ui#7793
No description provided.