-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSystemInfo.py
More file actions
110 lines (84 loc) · 3.06 KB
/
SystemInfo.py
File metadata and controls
110 lines (84 loc) · 3.06 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
import logging
import platform
import socket
import sys
import flask
import numpy
import psutil
if 'window' in platform.system().lower():
import wmi
from prettytable import PrettyTable
def get_size(bytes, suffix="B"):
"""
Scale bytes to its proper format
e.g:
1253656 => '1.20MB'
1253656678 => '1.17GB'
"""
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
def getSystemInfo():
try:
# Collecting Python and librray info
python = {}
python['Python'] = sys.version
python['Numpy'] = numpy.__version__
python['Flask'] = flask.__version__
pythonTable = PrettyTable(["", "Python and Libraries Information"])
for key in python:
pythonTable.add_row([key, python[key]])
print(pythonTable)
general = {}
cpu = {}
memory = {}
# Collecting general info
general['System'] = platform.system()
general['Platform'] = platform.platform()
# general['Platform2'] = platform.uname()
if 'window' in platform.system().lower():
c = wmi.WMI()
os = c.Win32_OperatingSystem()[0]
general['Windows-Version'] = os.Caption
else:
general['Platform-Version'] = platform.version()
general['Platform-Release'] = platform.release()
# general['Platform-Version'] = platform.version()
general['Architecture'] = platform.machine()
general['Hostname'] = socket.gethostname()
generalTable = PrettyTable(["", "General Information"])
for key in general:
generalTable.add_row([key, general[key]])
print(generalTable)
# Collecting CPU Info
cpu['Processor'] = platform.processor()
cpu['Physical_Cores'] = psutil.cpu_count(logical=False)
cpu['Total_Cores'] = psutil.cpu_count(logical=True)
cpufreq = psutil.cpu_freq()
cpu['Max Frequency'] = f"{cpufreq.max}" + " Mhz"
cpu['Min Frequency'] = f"{cpufreq.min}" + " Mhz"
cpu['Current Frequency'] = f"{cpufreq.current}" + " Mhz"
cpuTable = PrettyTable(["", "CPU Information"])
for key in cpu:
cpuTable.add_row([key, cpu[key]])
print(cpuTable)
# Collecting Memory Info
mem = psutil.virtual_memory()
memory['Total_Memory'] = get_size(mem.total)
memory['Available_Memory'] = get_size(mem.available)
memory['Used_Memory'] = get_size(mem.used)
swap = psutil.swap_memory()
memory['Total_Swap_Memory'] = get_size(swap.total)
memory['Free_Swap_Memory'] = get_size(swap.free)
memory['Used_Swap_Memory'] = get_size(swap.used)
memoryTable = PrettyTable(["", "Memory Information"])
for key in memory:
memoryTable.add_row([key, memory[key]])
print(memoryTable)
# return json.dumps(general)
except Exception as e:
logging.exception(e)
if __name__ == '__main__':
getSystemInfo()