Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more accurate memory usage statistics #525

Merged
merged 1 commit into from
Apr 12, 2023
Merged

fix: more accurate memory usage statistics #525

merged 1 commit into from
Apr 12, 2023

Conversation

shawaj
Copy link
Member

@shawaj shawaj commented Apr 10, 2023

As per https://psutil.readthedocs.io/en/latest/#psutil.virtual_memory the best way to calculate available and used memory is by using the "total" and "available" metrics.

Also see https://github.com/giampaolo/psutil/blob/master/scripts/meminfo.py

Related to #485 and #522

Issue

  • Link:
  • Summary:

How

Screenshots

References

Checklist

  • Tests added
  • Cleaned up commit history (rebase!)
  • Documentation added
  • Thought about variable and method names

As per https://psutil.readthedocs.io/en/latest/#psutil.virtual_memory the best way to calculate available and used memory is by using the "total" and "available" metrics.

Also see https://github.com/giampaolo/psutil/blob/master/scripts/meminfo.py

Related to #485 and #522
@shawaj shawaj requested a review from a team as a code owner April 10, 2023 14:41
@sonarcloud
Copy link

sonarcloud bot commented Apr 10, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@shawaj
Copy link
Member Author

shawaj commented Apr 10, 2023

@robputt could we also use from psutil._common import bytes2human to simplify this bit as well?

<td>RAM Usage</td>
<td class="text-right">
<div class="progress progress-xl">
<div class="progress-bar bg-success text-black" role="progressbar" style="width: {{ ((device_metrics.memory_used/device_metrics.memory_total) * 100)|round|int }}%;" aria-valuenow="{{ device_metrics.memory_used|round|int }}" aria-valuemin="0" aria-valuemax="{{ device_metrics.memory_total|round|int }}">{{ (device_metrics.memory_used / 1048576)|round|int }} MB / {{ (device_metrics.memory_total / 1048576)|round|int }} MB</div>
</div>
</td>
</tr>
<tr>
<td class="border-0">Disk Usage</td>
<td class="border-0 text-right">
<div class="progress progress-xl">
<div class="progress-bar bg-success text-black" role="progressbar" style="width: {{ ((device_metrics.disk_used/device_metrics.disk_total) * 100)|round|int }}%;" aria-valuenow="{{ device_metrics.disk_used|round|int }}" aria-valuemin="0" aria-valuemax="{{ device_metrics.disk_total|round|int }}">{{ "%.2f"|format((device_metrics.disk_used / 1073741824)|float) }} GB / {{ "%.2f"|format((device_metrics.disk_total / 1073741824)|float) }} GB</div>
</div>

https://github.com/giampaolo/psutil/blob/7eadee31db2f038763a3a6f978db1ea76bbc4674/psutil/_common.py#L816

@shawaj
Copy link
Member Author

shawaj commented Apr 10, 2023

Actually ignore my last comment @robputt as it isn't a number so wouldn't allow us to actually show the progress bar properly I guess.

Although there also appears to be an undocumented percent feature... psutil.virtual_memory().percent

And the same goes for disk usage... psutil.disk_usage('/').percent
https://psutil.readthedocs.io/en/latest/#psutil.disk_usage

@shawaj shawaj merged commit 326487f into master Apr 12, 2023
@shawaj shawaj deleted the shawaj/mem branch April 12, 2023 21:42
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.

None yet

3 participants