Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Last active March 12, 2024 01:25
Show Gist options
  • Save managedkaos/7540b0dae8c7a11621fbc52e5b86bbb4 to your computer and use it in GitHub Desktop.
Save managedkaos/7540b0dae8c7a11621fbc52e5b86bbb4 to your computer and use it in GitHub Desktop.
Jupyter-Environment-Specs.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOH2Luw6YLzExflWU2zffAf",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/managedkaos/7540b0dae8c7a11621fbc52e5b86bbb4/jupyter-environment-specs.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2AuGt6WCWTLW",
"outputId": "8785139f-7414-44bb-9c8a-41bc1d1333f9"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: psutil==5.9.4 in /usr/local/lib/python3.9/dist-packages (5.9.4)\n",
"Collecting py-cpuinfo==9.0.0\n",
" Downloading py_cpuinfo-9.0.0-py3-none-any.whl (22 kB)\n",
"Installing collected packages: py-cpuinfo\n",
"Successfully installed py-cpuinfo-9.0.0\n"
]
}
],
"source": [
"%pip install psutil==5.9 py-cpuinfo==9.0"
]
},
{
"cell_type": "code",
"source": [
"import psutil\n",
"import platform\n",
"from datetime import datetime\n",
"import cpuinfo\n",
"import socket\n",
"import uuid\n",
"import re\n",
"\n",
"\n",
"def get_size(bytes, suffix=\"B\"):\n",
" \"\"\"\n",
" Scale bytes to its proper format\n",
" e.g:\n",
" 1253656 => '1.20MB'\n",
" 1253656678 => '1.17GB'\n",
" \"\"\"\n",
" factor = 1024\n",
" for unit in [\"\", \"K\", \"M\", \"G\", \"T\", \"P\"]:\n",
" if bytes < factor:\n",
" return f\"{bytes:.2f}{unit}{suffix}\"\n",
" bytes /= factor\n",
"\n",
"def System_information():\n",
" print(\"=\"*40, \"System Information\", \"=\"*40)\n",
" uname = platform.uname()\n",
" print(f\"System: {uname.system}\")\n",
" print(f\"Node Name: {uname.node}\")\n",
" print(f\"Release: {uname.release}\")\n",
" print(f\"Version: {uname.version}\")\n",
" print(f\"Machine: {uname.machine}\")\n",
" print(f\"Processor: {uname.processor}\")\n",
" print(f\"Processor: {cpuinfo.get_cpu_info()['brand_raw']}\")\n",
"\n",
"\n",
" # print CPU information\n",
" print(\"=\"*40, \"CPU Info\", \"=\"*40)\n",
"\n",
" # number of cores\n",
" print(\"Physical cores:\", psutil.cpu_count(logical=False))\n",
"\n",
"\n",
" # Memory Information\n",
" print(\"=\"*40, \"Memory Information\", \"=\"*40)\n",
"\n",
" # get the memory details\n",
" svmem = psutil.virtual_memory()\n",
" print(f\"Total: {get_size(svmem.total)}\")\n",
"\n",
" # Disk Information\n",
" print(\"=\"*40, \"Disk Information\", \"=\"*40)\n",
" print(\"Partitions and Usage:\")\n",
"\n",
" # get all disk partitions\n",
" partitions = psutil.disk_partitions()\n",
" for partition in partitions:\n",
" if partition.mountpoint in [\"/\", \"/boot\"]:\n",
" print(f\"=== Device: {partition.device} ===\")\n",
" print(f\" Mountpoint: {partition.mountpoint}\")\n",
" print(f\" File system type: {partition.fstype}\")\n",
" try:\n",
" partition_usage = psutil.disk_usage(partition.mountpoint)\n",
" except PermissionError:\n",
" # this can be caught due to the disk that\n",
" # isn't ready\n",
" continue\n",
" print(f\" Total Size: {get_size(partition_usage.total)}\")\n",
"\n",
"if __name__ == \"__main__\":\n",
"\n",
" System_information()\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wNiXkifpWWR-",
"outputId": "07fa3de1-ab03-4839-f10b-864f0b2e0768"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"======================================== System Information ========================================\n",
"System: Linux\n",
"Node Name: f91cec1a069f\n",
"Release: 5.10.147+\n",
"Version: #1 SMP Sat Dec 10 16:00:40 UTC 2022\n",
"Machine: x86_64\n",
"Processor: x86_64\n",
"Processor: Intel(R) Xeon(R) CPU @ 2.20GHz\n",
"======================================== CPU Info ========================================\n",
"Physical cores: 1\n",
"======================================== Memory Information ========================================\n",
"Total: 12.68GB\n",
"======================================== Disk Information ========================================\n",
"Partitions and Usage:\n"
]
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "gdErLVx8Wjvg"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment