Skip to content

Commit

Permalink
Merge pull request #67 from abashurov/master
Browse files Browse the repository at this point in the history
FEATURE PPP-63513 Show actual hardware RAM size
  • Loading branch information
vfuse authored Mar 28, 2024
2 parents dce26b7 + 6b4bb72 commit 35372fb
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions agent360/plugins/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ def systemCommand(Command, newlines=True):
return (Stdout, Stderr)


def linux_hardware_memory():
block_size = 0
try:
with open("/sys/devices/system/memory/block_size_bytes", "r") as f:
block_size = int(f.readline().strip(), 16)

memory = 0
with os.scandir("/sys/devices/system/memory/") as it:
for entry in it:
if not entry.name.startswith("memory"):
continue
with open(entry.path + "/state", "r") as f:
if "online" != f.readline().strip():
continue
else:
memory += block_size

return memory
except Exception:
return 0


def ip_addresses():
ip_list = {}
ip_list['v4'] = {}
Expand Down Expand Up @@ -93,8 +115,12 @@ def run(self, *unused):
cpu['brand'] = line.rstrip('\n').split(':')[1].strip()
if "CPU(s)" == line.rstrip('\n').split(':')[0].strip():
cpu['count'] = line.rstrip('\n').split(':')[1].strip()
mem = psutil.virtual_memory()
mem = psutil.virtual_memory().total
if sys.platform == "linux" or sys.platform == "linux2":
hw_mem = linux_hardware_memory()
if hw_mem != 0:
mem = hw_mem

if distro is None:
systeminfo['os'] = str(' '.join(platform.linux_distribution()))
else:
Expand All @@ -115,7 +141,7 @@ def run(self, *unused):
systeminfo['os'] = "{} {}".format(platform.uname()[0], platform.uname()[2])
systeminfo['cpu'] = cpu['brand']
systeminfo['cores'] = cpu['count']
systeminfo['memory'] = mem.total
systeminfo['memory'] = mem
systeminfo['psutil'] = '.'.join(map(str, psutil.version_info))
systeminfo['python_version'] = sys.version
systeminfo['platform'] = platform.platform()
Expand Down

0 comments on commit 35372fb

Please sign in to comment.