Skip to content

Commit 35372fb

Browse files
authored
Merge pull request #67 from abashurov/master
FEATURE PPP-63513 Show actual hardware RAM size
2 parents dce26b7 + 6b4bb72 commit 35372fb

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

agent360/plugins/system.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ def systemCommand(Command, newlines=True):
4040
return (Stdout, Stderr)
4141

4242

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+
4365
def ip_addresses():
4466
ip_list = {}
4567
ip_list['v4'] = {}
@@ -93,8 +115,12 @@ def run(self, *unused):
93115
cpu['brand'] = line.rstrip('\n').split(':')[1].strip()
94116
if "CPU(s)" == line.rstrip('\n').split(':')[0].strip():
95117
cpu['count'] = line.rstrip('\n').split(':')[1].strip()
96-
mem = psutil.virtual_memory()
118+
mem = psutil.virtual_memory().total
97119
if sys.platform == "linux" or sys.platform == "linux2":
120+
hw_mem = linux_hardware_memory()
121+
if hw_mem != 0:
122+
mem = hw_mem
123+
98124
if distro is None:
99125
systeminfo['os'] = str(' '.join(platform.linux_distribution()))
100126
else:
@@ -115,7 +141,7 @@ def run(self, *unused):
115141
systeminfo['os'] = "{} {}".format(platform.uname()[0], platform.uname()[2])
116142
systeminfo['cpu'] = cpu['brand']
117143
systeminfo['cores'] = cpu['count']
118-
systeminfo['memory'] = mem.total
144+
systeminfo['memory'] = mem
119145
systeminfo['psutil'] = '.'.join(map(str, psutil.version_info))
120146
systeminfo['python_version'] = sys.version
121147
systeminfo['platform'] = platform.platform()

0 commit comments

Comments
 (0)