www.cnblogs.com/ruiyqinrui

开源、架构、Linux C/C++/python AI BI 运维开发自动化运维。 春风桃李花 秋雨梧桐叶。“力尽不知热 但惜夏日长”。夏不惜,秋不获。@ruiY--秦瑞

python爬虫,C编程,嵌入式开发.hadoop大数据,桉树,onenebula云计算架构.linux运维及驱动开发.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#@auhor by ruiy
#
#
#
#pip install paramiko -i https://pypi.tuna.tsinghua.edu.cn/simple
#
#pip install psutil -i https://pypi.tuna.tsinghua.edu.cn/simple
#
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import paramiko
import datetime
import time
import os
import psutil

dt = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
print(dt)

#psutil

def get_cpu_infos():
    cpu_count = psutil.cpu_count(logical=False)
    xc_count = psutil.cpu_count()
    cpu_percent = round((psutil.cpu_percent(1)),2)
    cpu_info = (cpu_count,xc_count,cpu_percent)
    return cpu_info


def get_mem_infos():
    memory = psutil.virtual_memory()
    total_mem = round((float(memory.total) / 1024 / 1024 / 1024),2)
    used_mem = round((float(memory.used) / 1024 / 1024 / 1024),2)
    free_mem = round((float(memory.free) / 1024 / 1024 / 1024),2)
    percent_mem = round((float(memory.used) / float(memory.total) * 100),2)
    mem_info = (total_mem,used_mem,free_mem,percent_mem)
    return mem_info

def get_disk_infos():
    list = psutil.disk_partitions()
    ilen = len(list)
    i = 0
    retlist1 = []
    retlist2 = []
    disk_info_list = []
    
    while i < ilen:
        diskinfo = psutil.disk_usage(list[i].device)
        total_disk = round((float(diskinfo.total) / 1024 / 1024 / 1024),2)
        used_disk = round((float(diskinfo.used) / 1024 / 1024 / 1024),2)
        free_disk = round((float(diskinfo.free) / 1024 / 1024 / 1024),2)
        #percent_disk = diskinfo.percent()
        retlist1 = [i,list[i].device,total_disk,used_disk,free_disk]
        disk_info_list.append(retlist1)
        i = i + 1
    return disk_info_list

if __name__ == '__main__':
    hosts = [
    'hostname="127.0.0.1",port=3389,username="administrator",password=""',
    ]

    for i in hosts:
        print(i)

    cpuInfos = get_cpu_infos()
    print(cpuInfos)

    memInfos = get_mem_infos()
    print(memInfos)

    diskInfos = get_disk_infos()
    print(diskInfos)

 

posted on 2022-11-17 15:57  秦瑞It行程实录  阅读(57)  评论(0编辑  收藏  举报
www.cnblogs.com/ruiyqinrui