博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python———系统的监控脚本
阅读量:3939 次
发布时间:2019-05-24

本文共 473 字,大约阅读时间需要 1 分钟。

需求:

    1. 获取当前主机信息, 包含操作系统名, 主机名,
    内核版本, 硬件架构等
    2. 获取开机时间和开机时长;
    3. 获取当前登陆用户

 

"""import osimport psutilfrom datetime import datetimeprint('主机信息'.center(50,'*'))info = os.uname()print("""    操作系统:%s    主机名称:%s    内核版本:%s    硬件架构:%s"""%(info.sysname,info.nodename,info.release,info.machine))print('开机信息'.center(50,'*'))boot_time = psutil.boot_time() #返回的是一个时间戳# 将时间戳转化为datatime类型的时间boot_time_obj = datetime.fromtimestamp(boot_time)print(type(boot_time_obj))now_time = datetime.now()

 

转载地址:http://hqdwi.baihongyu.com/

你可能感兴趣的文章
Linux下 socket-udp通信
查看>>
Linux - 守护进程-1
查看>>
syslog 和 rsyslog
查看>>
Linux下,write/read,recv/send, recvfrom/sendto的区别
查看>>
ubuntu下 rc.local的脚本不运行
查看>>
Linux下简单Makefile文件的编写
查看>>
linux下配置JDK JAVA环境
查看>>
解决Ubuntu 14.04 grub选择启动项10秒等待时间
查看>>
Python函数操作集锦之字符串测试、判断函数
查看>>
Python字符串操作集锦之字符串映射表
查看>>
Python字符串操作集锦之字符串编码解码函数
查看>>
Python字符串类型转换函数
查看>>
Python有用的命令
查看>>
Python条件语句
查看>>
Python eval()函数
查看>>
Linux rz和sz命令详解
查看>>
Python 集合set
查看>>
Codeforces Round #400 (Div. 1 + Div. 2, combined)D - The Door Problem(2-sat)
查看>>
IDEA中Struts2文件上传时404错误The origin server did not find a current representation for the target resour
查看>>
Perl/Tk 变量追踪及类线程实现
查看>>