User-Profile-Image
hankin
  • 5
  • centos7
  • docker
  • mysql
  • PostgreSQL
  • git/gitlab
  • ELK
  • python
    • python-Tornado
    • python-django
  • redis
  • nginx
  • kvm
  • proxmox
  • mongo
  • kubernetes
  • prometheus
  • GlusterFs
  • nfs
  • freeswitch
  • httpd
  • shell脚本
  • linux
  • fastdfs
  • nextcloud
  • openssl
  • openvpn
  • rabbitmq
  • sqlite
  • svn
  • java
  • ubuntu
  • vue2
  • wordpress
  • php
  • IOT物联网
  • 项目
  • 故障处理
  • 树莓派
  • 博客存档
  • 未分类
  • 杂项
  • #1742(无标题)
  • 新视野
  • 分类
    • 项目
    • 树莓派
    • 杂项
    • 未分类
    • 新视野
    • 故障处理
    • 博客存档
    • wordpress
    • vue2
    • ubuntu
    • svn
    • sqlite
    • shell脚本
    • redis
    • rabbitmq
    • python-django
    • python
    • proxmox
    • prometheus
    • PostgreSQL
    • php
    • openvpn
    • openssl
    • nginx
    • nfs
    • nextcloud
    • mysql
    • mongo
    • linux
    • kvm
    • kubernetes
    • java
    • IOT物联网
    • httpd
    • GlusterFs
    • git/gitlab
    • freeswitch
    • fastdfs
    • ELK
    • docker
    • centos7
  • 页面
    • #1742(无标题)
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
    首页   ›   python   ›   正文
python

python代码片段-系统调用相关

2022-11-08 11:14:23
850  0 0

获取进程、硬件等基本运行信息

import psutil #进程运行情况
import platform #包含系统信息查询函数
import os
import logging
# 硬件信息
svmem = psutil.virtual_memory()
mem_total = svmem.total # 系统内存总数
mem_used = svmem.used # 内存已使用
mem_free = svmem.free # 内存空闲大小
mem_per = svmem.percent # 内存使用率
system_version = platform.linux_distribution() # 获取linux发行版本详细信息
system_machine = platform.machine() # 获取操作系统架构
with open('/proc/cpuinfo') as f: # 获取cpu型号
    for line in f:
       if line.strip():
           if line.rstrip('\n').startswith('model name'):
              cpu_name = line.rstrip('\n').split(':')[1]
              break
cpu_type = cpu_name.split()[0]
cpu_count = psutil.cpu_count() # cpu核数
host_name = platform.node() # 电脑名称
stinfo = os.statvfs('/home')
print('CPU使用率',psutil.cpu_percent(1))
print('每个核的cpu使用率',psutil.cpu_percent(percpu=True))
print('硬盘使用',psutil.disk_usage("/home").percent)
# stinfo = os.statvfs('/')
st_info = stinfo.f_bsize * stinfo.f_blocks / 1024 / 1024 / 1024 # 获取磁盘大小
st_free_info = stinfo.f_bavail * stinfo.f_frsize/1024/1024/1024 # 磁盘剩余大小
print('系统内存总数', mem_total)
print('内存已使用', mem_used)
print('内存空闲大小', mem_free)
print('内存使用率', mem_per)
print('cpu核数', cpu_count)
print('电脑名称', host_name)
print('获取磁盘大小', st_info)
print('磁盘剩余大小', st_free_info)
# os.system('python3 /home/KL/DigapisKl/mastercontrol/es_search.py')
if mem_per >= 90:
   print(1)
a ='%.2f' % (st_free_info / st_info)
print(a)
评论 (0)

点击这里取消回复。

欢迎您 游客  

Copyright © 2025 网站备案号 : 蜀ICP备2022017747号
smarty_hankin 主题. Designed by hankin
主页
页面
  • #1742(无标题)
博主
tang.show
tang.show 管理员
linux、centos、docker 、k8s、mysql等技术相关的总结文档
210 文章 2 评论 201194 浏览
测试
测试