17 lines
606 B
Python
17 lines
606 B
Python
|
#!/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) # 测试数据
|
|||
|
|