python监控cpu 硬盘 内存
import psutil
import time
import yagmail def sendmail(subject,contents):
yag = yagmail.SMTP(user='155xxx8589@163.com',password='邮箱授权码',host='smtp.163.com')
yag.send(to='15534828589@163.com',subject=subject,contents=contents)
yag.close() def cpu():
cpu = psutil.cpu_percent(1)
return {'cpu_percent':cpu}
def mem():
mem_total = psutil.virtual_memory()[0]
mem_percent = psutil.virtual_memory()[2]
return {'mem_total':int(mem_total/1024/1024),'mem_percent':mem_percent}
def disk():
disk_total = psutil.disk_usage('c:')[0]
disk_percent = psutil.disk_usage('c:')[3]
return {'disk_total':int(disk_total/1024/1024/1024),'disk_percent':disk_percent}
def main():
info = {}
info.update(cpu())
info.update(mem())
info.update(disk()) msg = '''
cpu使用率:%s%%
内存使用率:%s%%
硬盘使用率:%s%% 内存总大小:%sM
硬盘总大小:%sG
''' % (info['cpu_percent'],info['mem_percent'],info['disk_percent'],info['mem_total'],info['disk_total'])
if info['cpu_percent'] > 5:
sendmail('cpu报警',msg)
if info['mem_percent'] > 50:
sendmail('内存报警',msg)
if info['disk_percent'] > 50:
sendmail('硬盘报警',msg)
while True :
if __name__ == '__main__':
main()
time.sleep(60)
python监控cpu 硬盘 内存的更多相关文章
- 监控CPU和内存的使用
监控CPU和内存的使用: #!/bin/bash #script to capture system statistics outfile=/home/rainbow/test/file.csv da ...
- Python获取CPU、内存使用率以及网络使用状态代码
Python获取CPU.内存使用率以及网络使用状态代码_python_脚本之家 http://www.jb51.net/article/134714.htm
- jmeter性能工具 之监控cpu,内存等信息(四)
1.jmeter 本身不支持直接监控 cpu,内存等信息,需要去官网下载控件 JMeterPlugins-Standard-1.4.0.zip 解压好将其中\lib\ext\JMeterPlug ...
- Shell脚本监控CPU、内存和硬盘利用率
1.监控CPU利用率(通过vmstat工具) #!/bin/bash #==================================================== # Author: l ...
- python代码优化-----cpu和内存监控
1.memory_profiler可以监控代码的内存消耗及增长量,以下面的代码为例. 发现在for循环里增加了0.3MB,这个工具可以帮助我们定位内存泄露的问题. 2.profile与cProfile ...
- python 获取cpu、内存、硬盘等实时信息 psutil
psutil是一个跨平台库,能够轻松实现获取系统运行的进程和系统利用率(CPU,内存,磁盘,网络等)信息,主要应用于系统监控,分析和限制系统资源及进程的管理,它实现了同等命令行工具提供的功能,如ps, ...
- linux中监控CPU、内存和磁盘状态的shell脚本。(centos7)
这篇博客中所写的脚本,在实际工作中并没有什么卵用,工作中并不会用到这种脚本去监控.不过自己写一遍,可以让初学者对CPU.内存.磁盘等一些基础知识和基础命令更加了解. 1.利用vmstat工具监控CPU ...
- Linux监控--CPU、内存、I/O
CPU top命令能够实时监控系统的运行状态,并且可以按照CPU.内存和执行时间进行排序,同时top命令还可以通过交互式命令进行设定显示,通过top命令可以查看即时活跃的进行. 内存 free命令可以 ...
- Linux监控CPU,内存,磁盘I/O
简单讲讲Linux下监控 [CPU] 监控CPU,top命令能够实时监控系统的运行状态,并且可以按照CPU.内存和执行时间进行排序,同时top命令还可以通过交互式命令进行设定显示,通过top命令可以查 ...
随机推荐
- 百度大脑IOCR财会票据识别技术接入小程序,快速实现财会票据识别
本文主要介绍iOCR财会票据识别的小程序功能实现. 想了解微信小程序的开发过程,请参看我之前的帖子:<UNIT接入小程序>https://ai.baidu.com/forum/topic/ ...
- django-建表出现的错误
在执行python3 manage.py migrate时出现以下错误 ?: (mysql.W002) MySQL Strict Mode is not set for database connec ...
- 【ftp服务】ftp登陆报错530 Login incorrect. Login failed.
ftp登陆时报错,530 Login incorrect.Login failed.1.cat /etc/passwd,查看你登陆的账户主目录和登陆shell对应的是什么,我的是/sbin/nolog ...
- 拓展 centos 7
查看端口的占用情况 Centos6/contos7(ECS) 使用 netstat 查询系统上有多少TCP 多少UDP会话 netstat -tun -t: tcp -u: udp -a: all 表 ...
- .net core3.0部署Linux服务器 使用Docker容器和Nginx反代理教程
本人刚接触.net core 由于公司项目需要部署在Linux上 近些日子学习和网上大面积搜教程 我在这给大家归拢归拢借鉴的教程做了套方案(我写的可以实现 但不一定是最好的 仅供参考) 我只用过cor ...
- Java 入土之路
概述 变量与数据类型 运算符与方法 面向对象 异常处理 包装类与常量池 集合框架 多线程 网络通讯协议 socket 编程-概念未发布 socket 编程-java环境未发布 web入门 Servle ...
- Electron npm install 常见错误(Windows)
问题一:node_gyp使用版本不对 if not defined npm_config_node_gyp (node "C:\Users\Administrator\AppData\Roa ...
- 46.QT-自带库QSerialPort串口使用
之前一章学习的是第三方库使用: 34.QT-qextserialport第三方库制作串口助手(并动态检测在线串口,附带源码) 本章来学习自带serial库 1.QSerialPortInfo QLis ...
- subprocess 的 Popen用法
使用Popen方法时,需要获取输出内容时可以按如下方法获取: # -*- coding:utf-8 -*- import subprocess cmd = r"ping www.baidu. ...
- SpringMVC自学笔记
1.<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 通过ser ...