From eea08f529ea238c4c4b3515b804bb2fe40bc0ded Mon Sep 17 00:00:00 2001 From: cppla Date: Fri, 27 Feb 2026 17:12:12 +0800 Subject: [PATCH] fix bug --- README.md | 4 ++-- clients/client-linux.py | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fcd870f..7c0c2da 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ `Docker`: wget --no-check-certificate -qO ~/serverstatus-config.json https://raw.githubusercontent.com/cppla/ServerStatus/master/server/config.json && mkdir ~/serverstatus-monthtraffic -docker run -d --restart=always --name=serverstatus -v ~/serverstatus-config.json:/ServerStatus/server/config.json -v ~/serverstatus-monthtraffic:/usr/share/nginx/html/json -p 80:80 -p 35601:35601 cppla/serverstatus:server +docker run -d --restart=always --name=serverstatus-server -v ~/serverstatus-config.json:/ServerStatus/server/config.json -v ~/serverstatus-monthtraffic:/usr/share/nginx/html/json -p 80:80 -p 35601:35601 cppla/serverstatus:server `Docker-compose`: docker compose -f docker-compose-server.yml up -d @@ -38,7 +38,7 @@ docker build -f Dockerfile.server -t serverstatus-server . wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python3 client-linux.py SERVER={$SERVER} USER={$USER} >/dev/null 2>&1 & `Docker`: -docker run --network=host -e SERVER=127.0.0.1 -e USER=s01 cppla/serververstatus:client +docker run --restart=always --name=serverstatus-client --network=host -e SERVER=127.0.0.1 -e USER=s01 cppla/serverstatus:client `Docker-compose`: docker compose -f docker-compose-client.yml up -d diff --git a/clients/client-linux.py b/clients/client-linux.py index 4bde3ad..9463be5 100755 --- a/clients/client-linux.py +++ b/clients/client-linux.py @@ -81,11 +81,37 @@ def get_memory(): return int(MemTotal), int(MemUsed), int(SwapTotal), int(SwapFree) def get_hdd(): - p = subprocess.check_output(['df', '-Tlm', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk', '-t', 'zfs', '-t', 'simfs', '-t', 'xfs']).decode("Utf-8") - total = p.splitlines()[-1] - used = total.split()[3] - size = total.split()[2] - return int(size), int(used) + valid_fs = { + "ext4", "ext3", "ext2", "reiserfs", "jfs", "ntfs", "fat32", + "btrfs", "fuseblk", "zfs", "simfs", "xfs", "exfat", "f2fs" + } + seen = set() + size = 0 + used = 0 + try: + with open("/proc/mounts", "r") as f: + for line in f: + parts = line.split() + if len(parts) < 3: + continue + mountpoint = parts[1] + fstype = parts[2].lower() + if fstype not in valid_fs or mountpoint in seen: + continue + seen.add(mountpoint) + st = os.statvfs(mountpoint) + total_bytes = st.f_blocks * st.f_frsize + used_bytes = (st.f_blocks - st.f_bavail) * st.f_frsize + size += total_bytes + used += used_bytes + except Exception: + pass + # Keep client alive even on minimal/containerized systems. + if size <= 0: + st = os.statvfs("/") + size = st.f_blocks * st.f_frsize + used = (st.f_blocks - st.f_bavail) * st.f_frsize + return int(size / 1024 / 1024), int(used / 1024 / 1024) def get_time(): with open("/proc/stat", "r") as f: