Ф-я получения данных о состоянии системы

import psutil
import datetime
import platform


def get_system_info():

    result = {}

    # ОС
    os_platform = platform.system()
    # Процессор
    processor = platform.processor()
    result.update({'platform': os_platform, 'processor': processor})
    # диски
    disks = psutil.disk_partitions()
    for i in disks:
        try:
            disk_usage = psutil.disk_usage(i.device)
            total = int(disk_usage .total) / 1048576
            used = int(disk_usage .used) / 1048576
            free = int(disk_usage .free) / 1048576
            percent = float(disk_usage .percent)
            disk_dict = {'total_space': total, 'used_space': used, 'free_space': free, 'free_percent': percent}
            result.update({'disk_space': disk_dict})

        except:
            pass

    # загрузка процессора
    cpu_percent = psutil.cpu_percent()
    result.update({'cpu_percent': cpu_percent})

    # аптайм
    boot_time = psutil.boot_time()
    uptime = datetime.datetime.now().timestamp() - boot_time
    result.update({'uptime': uptime})

    # оперативка:
    mem_status = psutil.virtual_memory()
    m_total = int(mem_status.total) / 1048576
    m_available = int(mem_status.available) / 1048576
    m_used = int(mem_status.used) / 1048576
    m_free = int(mem_status.free) / 1048576
    m_percent = float(mem_status.percent)
    memory_dict = {'total_mem': m_total, 'available_mem': m_available, 'used_mem': m_used,
                   'free_mem': m_free, 'free_percent_mem': m_percent}
    result.update({'memory_space': memory_dict})

    # температура процессора:
    try:
        # ToDo скорее всего надо прописать итератор для перечня  датчиков
        proc_temp = float(psutil.sensors_temperatures().current)
    except:
        proc_temp = None

    result.update({'proc_temp': proc_temp})

    return result


if __name__ == "__main__":
    res = get_system_info()
    for i in res.keys():
        print(i, res[i])

Источники:

Читать далее