-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmeminfo.py
More file actions
154 lines (134 loc) · 5.77 KB
/
meminfo.py
File metadata and controls
154 lines (134 loc) · 5.77 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
"""
formatter for meminfo plugin
"""
from util.util import convert_bytes, SHOW_SWAP
from plugins import meminfo
meminfo_class = meminfo.Meminfo()
def main():
"""
returns the data, but formatted.
"""
data = meminfo_class.get_data()
if data["virtual"]["values"]["total"] != 0 and SHOW_SWAP is not False:
combined_total_memory = (
data["physical"]["values"]["total"] + data["virtual"]["values"]["total"]
)
combined_total_actual_used = (
data["physical"]["values"]["actual_used"]
+ data["virtual"]["values"]["used"]
)
combined_total_used = (
data["physical"]["values"]["used"] + data["virtual"]["values"]["used"]
)
combined_total_available = (
data["physical"]["values"]["available"] + data["virtual"]["values"]["free"]
)
combined_used_percent = round(
(
data["physical"]["percentage"]["used"]
+ data["virtual"]["percentage"]["used"]
)
/ 2,
1,
)
combined_available_percent = round(
(
data["physical"]["percentage"]["available"]
+ data["virtual"]["percentage"]["free"]
)
/ 2,
1,
)
output_list_phys_virt = [
f" --- /proc/meminfo {'-' * 47}\n",
f" RAM: {' ' * 25}Swap:\n",
f" Total: {convert_bytes(data['physical']['values']['total'])}",
f" Used: {convert_bytes(data['physical']['values']['used'])} ({data['physical']['percentage']['used']}%)",
f" Ac. Used: {convert_bytes(data['physical']['values']['actual_used'])} ({data['physical']['percentage']['actual_used']}%)\n",
f" Available: {convert_bytes(data['physical']['values']['available'])} ({data['physical']['percentage']['available']}%)\n",
f" Free: {convert_bytes(data['physical']['values']['free'])} ({data['physical']['percentage']['free']}%)",
f" Cached: {convert_bytes(data['physical']['values']['cached'])} ({data['physical']['percentage']['cached']}%)",
f" - Combined: {'- ' * 26}\n",
f" Total: {convert_bytes(combined_total_memory)}",
f" Available: {convert_bytes(combined_total_available)} ({combined_available_percent}%)",
]
# 0. plugin name
# 1. table row
# 2. Total
# 3. Used
# 4. Actual Used
# 5. Available
# 6. Free
# 7. Cached
# line = line + spaces * 40 [len line] + other_line
# this is what basically happens over the next lines. i choose to do this
# instead of using a library because i do not want to depend on external libraries
# and i "cba" to write a different solution. for now, this is the best solution.
output_list_phys_virt[2] = (
output_list_phys_virt[2]
+ " " * max(0, 40 - len(output_list_phys_virt[2]))
+ f"Total: {convert_bytes(data['virtual']['values']['total'])}\n"
)
output_list_phys_virt[3] = (
output_list_phys_virt[3]
+ " " * max(0, 41 - len(output_list_phys_virt[3]))
+ f"Used: {convert_bytes(data['virtual']['values']['used'])} ({data['virtual']['percentage']['used']}%)\n"
)
output_list_phys_virt[6] = (
output_list_phys_virt[6]
+ " " * max(0, 36 - len(output_list_phys_virt[6]))
+ f" Free: {convert_bytes(data['virtual']['values']['free'])} ({data['virtual']['percentage']['free']}%)\n"
)
output_list_phys_virt[7] = (
output_list_phys_virt[7]
+ " " * max(0, 39 - len(output_list_phys_virt[7]))
+ f"Cached: {convert_bytes(data['virtual']['values']['cached'])}\n"
)
output_list_phys_virt[9] = (
output_list_phys_virt[9]
+ " " * max(0, 41 - len(output_list_phys_virt[9]))
+ f"Used: {convert_bytes(combined_total_used)} ({combined_used_percent}%)\n"
)
output_list_phys_virt[10] = (
output_list_phys_virt[10]
+ " " * max(0, 37 - len(output_list_phys_virt[10]))
+ f"Ac. Used: {convert_bytes(combined_total_actual_used)}\n"
)
return "".join(output_list_phys_virt)
output_list_phys = [
f" --- /proc/meminfo {'-' * 47}\n",
f" RAM: {' ' * 25}\n",
f" Total: {convert_bytes(data['physical']['values']['total'])}",
f" Used: {convert_bytes(data['physical']['values']['used'])} ({data['physical']['percentage']['used']}%)",
f" Available: {convert_bytes(data['physical']['values']['available'])} ({data['physical']['percentage']['available']}%)",
]
# 0. plugin name
# 1. table row
# 2. Total
# 3. Used
# 4. Free
# avail, actual, cached
output_list_phys[2] = (
output_list_phys[2]
+ " " * max(0, 41 - len(output_list_phys[2]))
+ f"Free: {convert_bytes(data['physical']['values']['free'])} ({data['physical']['percentage']['free']}%)\n"
)
output_list_phys[3] = (
output_list_phys[3]
+ " " * max(0, 37 - len(output_list_phys[3]))
+ f"Ac. Used: {convert_bytes(data['physical']['values']['actual_used'])} ({data['physical']['percentage']['actual_used']}%)\n"
)
output_list_phys[4] = (
output_list_phys[4]
+ " " * max(0, 39 - len(output_list_phys[4]))
+ f"Cached: {convert_bytes(data['physical']['values']['cached'])} ({data['physical']['percentage']['cached']}%)\n"
)
return "".join(output_list_phys)
def end():
"""
clean up when the program exits
"""
meminfo_class.close_files()
if __name__ == "__main__":
main()