Skip to content

Commit

Permalink
Fix turning stats to zero by casting them to int before multiplying.
Browse files Browse the repository at this point in the history
  • Loading branch information
matlorr committed Dec 28, 2024
1 parent 5f30572 commit 52898d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/src/components/landing_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ function LandingPage() {
}
if (line2) {
let values = line2.split(',')
setUsageCPU(100 * parseInt(values[0]));
setUsageMem(100 * parseInt(values[1]));
setUsageCPU(100 * parseFloat(values[0]));
setUsageMem(100 * parseFloat(values[1]));
}
}).catch(err => {
console.info('server stats unavailable')
Expand Down
4 changes: 2 additions & 2 deletions relay/cpu_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ def measure_proc_stat() -> dict[str, int]:
d_total = curr_total - prev_total
d_idle = curr_idle - prev_idle

cpu_usage = ((d_total - d_idle)/d_total) * 100
print(round(cpu_usage, 20))
cpu_usage = ((d_total - d_idle)/d_total)
print(cpu_usage)
2 changes: 1 addition & 1 deletion relay/stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ cpu_usage=$L4G_DIR/lean4game/relay/cpu_usage.py
# Execute python script
cpu=$($python $cpu_usage)
# Calculate memory usage by computing used_memory/total_memory
mem=$(free | sed '2q;d' | awk '{print $3/$2*100}')
mem=$(free | sed '2q;d' | awk '{print $3/$2}')

printf "CPU, MEM\n%.2f, %.2f\n" $cpu $mem

0 comments on commit 52898d9

Please sign in to comment.