@@ -40,6 +40,28 @@ def systemCommand(Command, newlines=True):
40
40
return (Stdout , Stderr )
41
41
42
42
43
+ def linux_hardware_memory ():
44
+ block_size = 0
45
+ try :
46
+ with open ("/sys/devices/system/memory/block_size_bytes" , "r" ) as f :
47
+ block_size = int (f .readline ().strip (), 16 )
48
+
49
+ memory = 0
50
+ with os .scandir ("/sys/devices/system/memory/" ) as it :
51
+ for entry in it :
52
+ if not entry .name .startswith ("memory" ):
53
+ continue
54
+ with open (entry .path + "/state" , "r" ) as f :
55
+ if "online" != f .readline ().strip ():
56
+ continue
57
+ else :
58
+ memory += block_size
59
+
60
+ return memory
61
+ except Exception :
62
+ return 0
63
+
64
+
43
65
def ip_addresses ():
44
66
ip_list = {}
45
67
ip_list ['v4' ] = {}
@@ -93,8 +115,12 @@ def run(self, *unused):
93
115
cpu ['brand' ] = line .rstrip ('\n ' ).split (':' )[1 ].strip ()
94
116
if "CPU(s)" == line .rstrip ('\n ' ).split (':' )[0 ].strip ():
95
117
cpu ['count' ] = line .rstrip ('\n ' ).split (':' )[1 ].strip ()
96
- mem = psutil .virtual_memory ()
118
+ mem = psutil .virtual_memory (). total
97
119
if sys .platform == "linux" or sys .platform == "linux2" :
120
+ hw_mem = linux_hardware_memory ()
121
+ if hw_mem != 0 :
122
+ mem = hw_mem
123
+
98
124
if distro is None :
99
125
systeminfo ['os' ] = str (' ' .join (platform .linux_distribution ()))
100
126
else :
@@ -115,7 +141,7 @@ def run(self, *unused):
115
141
systeminfo ['os' ] = "{} {}" .format (platform .uname ()[0 ], platform .uname ()[2 ])
116
142
systeminfo ['cpu' ] = cpu ['brand' ]
117
143
systeminfo ['cores' ] = cpu ['count' ]
118
- systeminfo ['memory' ] = mem . total
144
+ systeminfo ['memory' ] = mem
119
145
systeminfo ['psutil' ] = '.' .join (map (str , psutil .version_info ))
120
146
systeminfo ['python_version' ] = sys .version
121
147
systeminfo ['platform' ] = platform .platform ()
0 commit comments