psutil

测开之路六十八:监控平台之监控逻辑和处理逻辑

匿名 (未验证) 提交于 2019-12-02 23:49:02
获取机器的数据 import timeimport socketimport datetimeimport psutilfrom common import send_emailfrom common.mongo import Mongoclass Agent(object): def __init__(self): super(Agent).__init__() self.mongo = Mongo() def get_ip(self): """ 通过socket库可以获取机器名,通过机器名可以获取ip地址。 """ hostname = socket.gethostname() return socket.gethostbyname(hostname) def get_cpu(self): """ cpu相关,interval代表获取数据的时间间隔,percpu为True时,如果机器多核,则返回多个核数据。 """ result = {} data = psutil.cpu_percent(interval=1, percpu=True) # cpu使用率 result['avg'] = sum(data) / psutil.cpu_count() # 平均使用率 result['idle'] = 100 - result['avg'] # cpu空闲率 result[

Python学习笔记:第三方模块2

匿名 (未验证) 提交于 2019-12-02 22:54:36
最近在学习深度学习,已经跑出了几个模型,但Pyhton的基础不够扎实,因此,开始补习Python了,大家都推荐廖雪峰的课程,因此,开始了学习,但光学有没有用,还要和大家讨论一下,因此,写下这些帖子,廖雪峰的课程连接在这里: 廖雪峰 Python的相关介绍,以及它的历史故事和运行机制,可以参见这篇: python介绍 Python的安装可以参见这篇: Python安装 Python的运行模式以及输入输出可以参见这篇: Python IO Python的基础概念介绍,可以参见这篇: Python 基础 Python字符串和编码的介绍,可以参见这篇: Python字符串与编码 Python基本数据结构:list和tuple介绍,可以参见这篇: Python list和tuple Python控制语句介绍:ifelse,可以参见这篇: Python 条件判断 Python控制语句介绍:循环实现,可以参见这篇: Python循环语句 Python数据结构:dict和set介绍 Python数据结构dict和set Python函数相关: Python函数 Python高阶特性: Python高级特性 Python高阶函数: Python高阶函数 Python匿名函数: Python匿名函数 Python装饰器: Python装饰器 Python偏函数: Python偏函数 Python模块:

Python程序监控CPU利用率并写入文件

匿名 (未验证) 提交于 2019-12-02 22:51:30
Python程序监控CPU利用率并写入文件 #__author__ = 'chubby_superman' #_*_coding=utf-8 _*_ import psutil import time import os import matplotlib.dates import matplotlib.pyplot as plt def cpu_count(): print('-----------------------------cpu信息---------------------------------------' + '\n') print(u"物理CPU个数: %s" % psutil.cpu_count(logical=False)) print(u"CPU核心总数: %s" % psutil.cpu_count()) f = open('cpu.txt', 'a') f.write('-----------------------------cpu信息---------------------------------------') f.write(u"物理CPU个数: %s" % psutil.cpu_count(logical=False) + '\n') f.write(u"CPU核心总数: %s" % psutil.cpu_count() + '\n')

Ways to free memory back to OS from Python?

被刻印的时光 ゝ 提交于 2019-12-01 20:21:06
问题 I have code that looks similar to this: def memoryIntensiveFunction(x): largeTempVariable = Intermediate(x) processFunction(largeTempVariable,x) The problem is that the variable temp is something like 500 mb in a test case of mine, but that space is not returned to the OS when memoryIntensiveFunction is finished. I know this because memory profiling with the guppy tool says largeTempVariable is freed (i.e., within Python), but psutil shows it isn't. I presume I'm seeing the effects described

Only first subprocess.Popen(…, stdin=f) in a loop works correctly

梦想与她 提交于 2019-12-01 14:57:41
My main goal here is to get all the cpu charge of a list of Linux-connected computers. I have been struggling and searching on the net for some time but I must miss something as I can't find my answer. So I defined a cpu_script.py : import psutil print(psutil.cpu_percent(interval=1,percpu=True)) to be called in my main script, which is in the same folder, with: import subprocess import os import numpy as np import psutil usr = "AA" computer = ["c1", "c2", "c3"] #list of computer which cpu load is to be tested cpu_script = os.path.join(os.getcwd(),"cpu_script.py") with open(cpu_script,"rb") as

Only first subprocess.Popen(…, stdin=f) in a loop works correctly

时光毁灭记忆、已成空白 提交于 2019-12-01 12:20:46
问题 My main goal here is to get all the cpu charge of a list of Linux-connected computers. I have been struggling and searching on the net for some time but I must miss something as I can't find my answer. So I defined a cpu_script.py : import psutil print(psutil.cpu_percent(interval=1,percpu=True)) to be called in my main script, which is in the same folder, with: import subprocess import os import numpy as np import psutil usr = "AA" computer = ["c1", "c2", "c3"] #list of computer which cpu

Memory usage of a single process with psutil in python (in byte)

无人久伴 提交于 2019-11-30 14:17:23
问题 How to get the amount of memory which has been used by a single process in windows platform with psutil library? (I dont want to have the percentage , I want to know the amount in bytes) We can use: psutil.virtual_memory().used To find the memory usage of the whole OS in bytes, but how about each single process? Thanks, 回答1: Call memory_info_ex: >>> import psutil >>> p = psutil.Process() >>> p.name() 'python.exe' >>> _ = p.memory_info_ex() >>> _.wset, _.pagefile (11665408, 8499200) The

Memory usage of a single process with psutil in python (in byte)

瘦欲@ 提交于 2019-11-30 10:18:48
How to get the amount of memory which has been used by a single process in windows platform with psutil library? (I dont want to have the percentage , I want to know the amount in bytes) We can use: psutil.virtual_memory().used To find the memory usage of the whole OS in bytes, but how about each single process? Thanks, Call memory_info_ex : >>> import psutil >>> p = psutil.Process() >>> p.name() 'python.exe' >>> _ = p.memory_info_ex() >>> _.wset, _.pagefile (11665408, 8499200) The working set includes pages that are shared or shareable by other processes, so in the above example it's actually

psutil模块

孤街浪徒 提交于 2019-11-30 05:56:06
psutil 能够轻松实现获取系统运行的进程和系统利用率 安装、导入模块 pip install psutil # 安装 import psutils # 导入 获取系统性能信息 CPU信息 1.使用cpu_times()方法获取CPU的完整信息: psutil.cpu_times() --------------------------------------------------------------------------------------- scputimes(user=15606.75, system=14908.984374999942, idle=323725.765625, interrupt=685.906 25, dpc=571.21875) 2.获取单项数据,例如用户user的CPU时间比: psutil.cpu_times().user 3.获取CPU的个数: psutil.cpu_count() # 默认logical=True,获取逻辑个数 psutil.cpu_count(logical=False) # 获取CPU的物理个数 内存信息 获取物理内存总大小和已使用内存: mem = psutil.virtual_memory() mem # 显示所有的参数,svmem(total=8494747648, available

psutil模块

半腔热情 提交于 2019-11-29 18:38:46
import psutil# cpu 详情# re = psutil.cpu_percent(interval=1) # 返回cpu使用百分比# re = psutil.cpu_count() # 返回CPU核数# 内存# re = psutil.virtual_memory() # 获取内存# svmem(total=8476856320, available=4131033088, percent=51.3, used=4345823232, free=4131033088)# a = float(re.total / (1024 * 1024 * 1024)) # 换成称G# print ('%.2f' %(a)) # 结果保留两位小数# re = psutil.swap_memory() # 交换内存# print(re)# sswap(total=9819033600, used=5821399040, free=3997634560, percent=59.3, sin=0, sout=0)# 硬盘# disk = psutil.disk_usage('c:') # 硬盘使用情况# print(disk)# sdiskusage(total=127544819712, used=28217819136, free=99327000576, percent=22.1)#