Sfoglia il codice sorgente

free memory calculation fix

Denys Bashkatov 1 settimana fa
parent
commit
1637a172ad
1 ha cambiato i file con 4 aggiunte e 2 eliminazioni
  1. 4 2
      scripts/resource-monitor.sh

+ 4 - 2
scripts/resource-monitor.sh

@@ -113,7 +113,8 @@ get_process_info() {
     fi
     
     # Convert RAM percentage to MB (assuming total RAM is available)
-    local total_ram_mb=$(free -m | awk 'NR==2{print $2}')
+    local total_ram_kb=$(free | awk 'NR==2{print $2}')
+    local total_ram_mb=$((total_ram_kb / 1024))
     # Set locale to C to ensure decimal points instead of commas
     export LC_NUMERIC=C
     local ram_mb_calc=$(echo "$ram_percent * $total_ram_mb / 100" | bc -l 2>/dev/null | cut -d. -f1)
@@ -142,7 +143,8 @@ get_process_info() {
 
 # Function to get system total RAM
 get_system_ram() {
-    local total_ram_mb=$(free -m | awk 'NR==2{print $2}')
+    local total_ram_kb=$(free | awk 'NR==2{print $2}')
+    local total_ram_mb=$((total_ram_kb / 1024))
     echo "$total_ram_mb"
 }