0

I'm a beginner at flask. I want to implement a function that runs when RAM usage exceeds 80 percent on my server. What is the best way to implement it?

backdrop
  • 1
  • 1

2 Answers2

0

you can import psutil to check the memory.

memory_usage = psutil.virtual_memory().percent

you can check the link to have more ideas about it. https://psutil.readthedocs.io/en/latest/

I wish if my answer is good.

IHA87
  • 11
  • 4
0

Reading how much ram is used is very simple, as you can also read from this question always asked on stackoverflow:

import psutil
# you can calculate percentage of available memory
print(str(psutil.virtual_memory().available * 100 / psutil.virtual_memory().total))
20.8

To install psutil:

pip install psutil
Matteo Pasini
  • 1,036
  • 2
  • 9
  • 20