首页 > 系统相关 >python windows psutil获取基本监控指标

python windows psutil获取基本监控指标

时间:2022-11-17 16:15:19浏览次数:37  
标签:1024 psutil python float windows disk mem cpu

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#@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)

 

标签:1024,psutil,python,float,windows,disk,mem,cpu
From: https://www.cnblogs.com/ruiy/p/16899768.html

相关文章

  • Python图像处理丨5种图像处理特效
    摘要:本篇文章主要讲解了图像常见的特效处理,从处理效果图、算法原理、代码实现三个步骤进行详细讲解,涉及图像素描特效、怀旧特效、光照特效、流年特效、图像滤镜等。本文分......
  • Python图像处理丨5种图像处理特效
    摘要:本篇文章主要讲解了图像常见的特效处理,从处理效果图、算法原理、代码实现三个步骤进行详细讲解,涉及图像素描特效、怀旧特效、光照特效、流年特效、图像滤镜等。本文分享......
  • [oeasy]python0016_编码_encode_编号_字节_计算机
    编码(encode)回忆上次内容上次找到了字符和字节状态之间的映射对应关系字符对应着二进制字节二进制字节也对应着字符这种字节状态是用2位16进制数来表示的hex(n)可以把数字......
  • python3-基础篇-09-字典
     字典的特点:1.无序的2.key唯一ps:类似于java中的map一、字典创建字典的每个键值key=>value对用冒号:分割,每个键值对之间用逗号,分割,整个字典包括在花括号{}中,格......
  • Python之configparser模块的简单使用
    一、configparser安装pip3installconfigparser二、新建config.ini[ENV]env=QA1[QA1]url=https://qa1-xxx.cns_url=https://qa-s-xxx.cn[QA2]url=htt......
  • python rsa加解密
    pythonrsa加解密代码:只适用python3:importbase64fromCrypto.CipherimportPKCS1_v1_5fromCryptoimportRandomfromCrypto.PublicKeyimportRSA#-------......
  • Python数据分析与应用 ---- 航空公司客户价值分析
    Python数据分析与应用----航空公司客户价值分析 Python数据分析与应用----航空公司客户价值分析_骑着蜗牛ひ追导弹'的博客-CSDN博客_航空客户数据分析......
  • python三十六期---
    昨日内容回顾TCP与UDP协议TCP 可靠协议三次握手建立链接 1.洪水攻击 2.消息反馈四次挥手断开链接 1.time_waitUDP 不可靠协议"""TCP......
  • ubuntu安装python环境scikit-learn低版本
    ubuntu安装python环境scikit-learn低版本Ubuntu默认使用的是python3.8,要安装插件需要先安装几个依赖包      安装uwsgi需要安装gccpython3.8-dev python-dev......
  • 【学习笔记】Python深浅copy拷贝解析
    一、列表的赋值(一般用于读操作)这个和列表的深浅拷贝其实没有关系,就是一个赋值操作;list1和list2指向的是同一片内存地址;即,你家有套房子,叫清华楼A栋101室,也叫......