Get process stats from /proc.
(pid)
| 83 | return None |
| 84 | |
| 85 | def proc_stat(pid): |
| 86 | """Get process stats from /proc.""" |
| 87 | stats = {} |
| 88 | try: |
| 89 | with open(f"/proc/{pid}/status") as f: |
| 90 | for line in f: |
| 91 | if line.startswith("VmRSS:"): |
| 92 | stats["rss_kb"] = int(line.split()[1]) |
| 93 | elif line.startswith("VmSize:"): |
| 94 | stats["vms_kb"] = int(line.split()[1]) |
| 95 | elif line.startswith("Threads:"): |
| 96 | stats["threads"] = int(line.split()[1]) |
| 97 | stats["fds"] = len(os.listdir(f"/proc/{pid}/fd")) |
| 98 | except: |
| 99 | pass |
| 100 | return stats |
| 101 | |
| 102 | def fmt_kb(kb): |
| 103 | if kb > 1024*1024: |