| 81 | return int(MemTotal), int(MemUsed), int(SwapTotal), int(SwapFree) |
| 82 | |
| 83 | def get_hdd(): |
| 84 | valid_fs = { |
| 85 | "ext4", "ext3", "ext2", "reiserfs", "jfs", "btrfs", "fuseblk", |
| 86 | "zfs", "simfs", "ntfs", "fat32", "exfat", "xfs" |
| 87 | } |
| 88 | disks = {} |
| 89 | size = 0 |
| 90 | used = 0 |
| 91 | try: |
| 92 | with open("/proc/mounts", "r") as f: |
| 93 | for line in f: |
| 94 | parts = line.split() |
| 95 | if len(parts) < 3: |
| 96 | continue |
| 97 | device = parts[0] |
| 98 | mountpoint = parts[1] |
| 99 | fstype = parts[2].lower() |
| 100 | if fstype not in valid_fs or device in disks: |
| 101 | continue |
| 102 | disks[device] = mountpoint |
| 103 | for mountpoint in disks.values(): |
| 104 | st = os.statvfs(mountpoint) |
| 105 | total_bytes = st.f_blocks * st.f_frsize |
| 106 | used_bytes = (st.f_blocks - st.f_bavail) * st.f_frsize |
| 107 | size += total_bytes |
| 108 | used += used_bytes |
| 109 | except Exception: |
| 110 | pass |
| 111 | return int(size / 1024 / 1024), int(used / 1024 / 1024) |
| 112 | |
| 113 | def get_time(): |
| 114 | with open("/proc/stat", "r") as f: |