-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocpid.py
More file actions
36 lines (25 loc) · 873 Bytes
/
Copy pathprocpid.py
File metadata and controls
36 lines (25 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""
formatter for procpid plugin
"""
from util.util import convert_bytes
from plugins import procpid
procpid_class = procpid.Procpid()
def main():
"""
returns the data, but formatted.
"""
data = procpid_class.get_data()
formatted_data = [
f" --- /proc/pid/status {'-' * 44}\n Name PID RSS State"
]
for proc in data["processes"]:
vmrss_human_format = convert_bytes(proc["vmrss"])
formatted_data.append(
f" {proc['name'] or '!?!?'}{' ' * (28 - len(proc['name'] or '!?!?'))}"
f" {proc['pid']}{' ' * (7 - len(str(proc['pid'])))}"
f" {vmrss_human_format}{' ' * (14 - len(vmrss_human_format))} {proc['state'] or '!?!?'}"
)
return "\n".join(formatted_data) + "\n"
if __name__ == "__main__":
main()