import psutil
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def cpu_info():
cpu = psutil.cpu_percent(1) # 一秒内cpu使用率,单位
cpu_per = '%.2f%%' % cpu # 变成百分数,保留两位小数
return cpu_per
def mem_info():
mem = psutil.virtual_memory()
mem_per = '%.2f%%' % mem[2]
mem_total = str(int(mem[0] / 1024 / 1024)) + 'M'
mem_used = str(int(mem[3] / 1024 / 1024)) + 'M'
mem_dict = {
'mem_per': mem_per,
'mem_total': mem_total,
'mem_used': mem_used,
}
return mem_dict
# C盘利用率
def disk_info():
c_info = psutil.disk_usage("C:")
c_per = '%.2f%%' % c_info[3]
return c_per
def network_info():
net = psutil.net_io_counters()
net_sent = str(int(net[0]/1024/1024)) + 'MB'
net_rece = str(int(net[1]/1024/1024)) + 'MB'
net_dict = {
'net_cent': net_sent,
'net_rece': net_rece
}
return net_dict
def send_mail(message):
sender = 'your@163.com' # 发送邮箱