You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
606 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/python3
#-*-coding: utf-8-*-
# 获取cpu负载信息并调用钉钉接口发送
import subprocess,sys,datetime
import dingding
def cpu_load(): # 定义函数获取系统cpu负载
a = subprocess.getoutput('uptime |cut -d":" -f4')
upload = a.split() # 将结果转换为列表
return upload # 返回 这里要注意return和print的区别
a = cpu_load() # 调用方法
time = datetime.datetime.now() # 定义当前时间
data = 'cpu 负载为:{}\n当前时间:{}'.format(a,time)
dingding.msg(data) # 调用钉钉
if __name__ == '__main__':
print(data) # 测试数据