Merge pull request #3639 from Machine-Garden-MUD/cmdserverload

Use consistent locale settings for system utilities
This commit is contained in:
Griatch 2024-10-21 20:09:44 +02:00 committed by GitHub
commit 5140f5b8d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,7 @@ import traceback
import django import django
import evennia import evennia
import subprocess
import twisted import twisted
from django.conf import settings from django.conf import settings
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
@ -862,16 +863,26 @@ class CmdServerLoad(COMMAND_DEFAULT_CLASS):
if not _RESOURCE: if not _RESOURCE:
import resource as _RESOURCE import resource as _RESOURCE
env = os.environ.copy()
env["LC_NUMERIC"] = "C" # use default locale instead of system locale
loadavg = os.getloadavg()[0] loadavg = os.getloadavg()[0]
rmem = (
float(os.popen("ps -p %d -o %s | tail -1" % (pid, "rss")).read()) / 1000.0 # Helper function to run the ps command with a modified environment
) # resident memory def run_ps_command(command):
vmem = ( result = subprocess.run(
float(os.popen("ps -p %d -o %s | tail -1" % (pid, "vsz")).read()) / 1000.0 command, shell=True, env=env, stdout=subprocess.PIPE, text=True
) # virtual memory )
pmem = float( return result.stdout.strip()
os.popen("ps -p %d -o %s | tail -1" % (pid, "%mem")).read()
) # % of resident memory to total # Resident memory
rmem = float(run_ps_command(f"ps -p {pid} -o rss | tail -1")) / 1000.0
# Virtual memory
vmem = float(run_ps_command(f"ps -p {pid} -o vsz | tail -1")) / 1000.0
# Percentage of resident memory to total
pmem = float(run_ps_command(f"ps -p {pid} -o %mem | tail -1"))
rusage = _RESOURCE.getrusage(_RESOURCE.RUSAGE_SELF) rusage = _RESOURCE.getrusage(_RESOURCE.RUSAGE_SELF)
if "mem" in self.switches: if "mem" in self.switches: