Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active September 28, 2021 15:10
Show Gist options
  • Save ThomasG77/12c85e5e65b7776fd6d86bf9cb00a1bc to your computer and use it in GitHub Desktop.
Save ThomasG77/12c85e5e65b7776fd6d86bf9cb00a1bc to your computer and use it in GitHub Desktop.
import json
import os
import platform
import re
import socket
import uuid
from pprint import pprint as pp
import distro
from hurry.filesize import size
import psutil
# Need pip install distro psutil hurry.filesize
distro_name, distro_version, distro_codename = distro.linux_distribution()
partitions = psutil.disk_partitions()
disk_usage = []
for p in partitions:
usage = psutil.disk_usage(p.mountpoint)
disk_usage.append({
'mountpoint': p.mountpoint,
'total': size(int(usage.total)),
'used': size(int(usage.used))
})
config_content = {
"platform_release": platform.release(),
"platform_version": platform.version(),
"architecture": platform.machine(),
"hostname": socket.gethostname(),
"ip_address": socket.gethostbyname(socket.gethostname()),
"mac_address": ":".join(re.findall("..", "%012x" % uuid.getnode())),
"distro_name": distro_name,
"distro_version": distro_version,
"distro_codename": distro_codename,
"cpu_number": psutil.cpu_count(),
"disk_usage": disk_usage,
"ram": "{} GB".format(round(psutil.virtual_memory().total / (1024.0 ** 3))),
}
pp(config_content)
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
with open(os.path.join(__location__, "out.json"), "w") as inputfile:
json.dump(config_content, inputfile, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment