Python获取系统及硬件信息(CPU、内存、硬盘、网络等),支持多平台 Windows、Linux

本文介绍了一个基于Python的跨平台系统信息API,能够获取Windows和Linux系统的详细信息,包括CPU、内存、磁盘、网络等各项指标,适用于系统监控和资源管理。
该文章已生成可运行项目,

即可获取windows系统及硬件信息

又可获取linux系统及硬件信息

一站式,全平台!

文章底部直接贴完整代码,先上介绍和函数说明


system-info

基于python3的linux和windows系统信息api
linux and windows system information api

Github: https://github.com/Pure-Peace/system-info

based on: python3.8(基本python3以上即可)


所有api均支持linux和windows
All apis support linux and windows


api列表:

CpuConstants
ExecShellUnix
GetBootTime
GetCpuConstants
GetCpuInfo
GetDiskInfo
GetDiskInfoUnix
GetDiskInfoWindows
GetErrorInfo
GetFullSystemData
GetIoRead
GetIoReadWrite
GetIoWrite
GetLoadAverage
GetMemInfo
GetMemInfoUnix
GetMemInfoWindows
GetNetWork
GetRegValue
GetSystemInfo
GetSystemVersion
GetSystemVersionUnix
GetSystemVersionWindows
ToSizeInt
ToSizeString
UNIX
cpuConstants
md5
readFile

api说明:

当前系统网络使用情况:上传下载速率,收发包

GetNetWork()
both
{
   
   
	'up': 1.54,
	'down': 0.37,
	'upTotal': 87688289,
	'downTotal': 336439316,
	'downPackets': 397399,
	'upPackets': 262468
}

当前系统磁盘IO情况:IO读写

GetIoReadWrite()
both
{
   
   'write': 1003332, 'read': 1466368}

当前系统CPU常量

GetCpuConstants()
windows
{
   
   'cpu_count': 1, 'cpu_name': 'AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx  ', 'cpu_core': 4, 'cpu_threads': 8}
linux
{
   
   'cpu_count': 1, 'cpu_name': 'Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz', 'cpu_core': 1, 'cpu_threads': 1}

当前系统CPU信息、使用率

GetCpuInfo()
windows
{
   
   
	'used': 17.2,
	'used_list': [23.8, 12.2, 19.6, 10.2, 20.3, 6.2, 12.6, 30.3],
	'cpu_count': 1,
	'cpu_name': 'AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx  ',
	'cpu_core': 4,
	'cpu_threads': 8
}
linux
{
   
   
	'used': 2.0,
	'used_list': [3.4],
	'cpu_count': 1,
	'cpu_name': 'Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz',
	'cpu_core': 1,
	'cpu_threads': 1
}

当前系统负载信息

GetLoadAverage()
windows
{
   
   
	'one': 0,
	'five': 0,
	'fifteen': 0,
	'max': 16,
	'limit': 16,
	'safe': 12.0
}
linux
{
   
   
	'one': 0.46,
	'five': 0.18,
	'fifteen': 0.14,
	'max': 2,
	'limit': 2,
	'safe': 1.5
}

当前系统内存使用情况(linux比windows多了cached和buffers)

GetMemInfo()
windows
{
   
   
	'memTotal': 7069,
	'memFree': 1202,
	'memRealUsed': 5866,
	'menUsedPercent': '82.98'
}
linux
{
   
   
	'memTotal': 1838,
	'memFree': 181,
	'memBuffers': 25,
	'memCached': 448,
	'memRealUsed': 1184,
	'memUsedPercent': 64.41784548422198
}

当前系统磁盘信息

GetDiskInfo()
windows
[{
   
   'path': 'C:/',
  'size': {
   
   'total': 85899341824,
   'used': 84512485376,
   'free': 1386856448,
   'percent': 98.4},
  'fstype': 'NTFS',
  'inodes': False},
 {
   
   'path': 'D:/',
  'size': {
   
   'total': 413524815872,
   'used': 367597920256,
   'free': 45926895616,
   'percent': 88.9},
  'fstype': 'NTFS',
  'inodes': False}]
linux
[{
   
   
	'path': '/',
	'size': ['50G', '16G', '32G', '33%'],
	'inodes': ['3276800', '261498', '3015302', '8%']
}]

获取系统注册表信息(仅windows可用)

GetRegValue(key: str, subkey: str, value: str)
    '''
  获取系统注册表信息

  Parameters
  ----------
  key : str
      类型.
  subkey : str
      路径.
  value : str
      key.

  Returns
  -------
  value : Any
      DESCRIPTION.

  '''

获取系统版本信息

GetSystemVersion()
windows
Windows 10 Home China (build 18362) x64 (Py3.8.5)
linux
CentOS  7.6.1810(Py 3.8.5)

获取系统启动时间及运行时间

GetBootTime()
both
{
   
   'timestamp': 1597574445.835271,
 'runtime': 33396.16829442978,
 'datetime': '2020-08-17 03:57:22'}

获取全部系统信息

GetFullSystemData()
windows
{
   
   
	'cpu': {
   
   
		'used': 16.0,
		'used_list': [29.0, 16.4, 30.5, 13.9, 28.1, 16.8, 24.0, 26.7],
		'cpu_count': 1,
		'cpu_name': 'AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx  ',
		'cpu_core': 4,
		'cpu_threads': 8
	},
	'load': {
   
   
		'one': 0,
		'five': 0,
		'fifteen': 0,
		'max': 16,
		'limit': 16,
		'safe': 12.0
	},
	'mem': {
   
   
		'memTotal': 7069,
		'memFree': 1181,
		'memRealUsed': 5888,
		'menUsedPercent': '83.29'
	},
	'disk': [{
   
   
		'path': 'C:/',
		'size': {
   
   
			'total': 85899341824,
			'used': 84515794944,
			'free': 1383546880,
			'percent': 98.4
		},
		'fstype': 'NTFS',
		'inodes': False
	}, {
   
   
		'path': 'D:/',
		'size': {
   
   
			'total': 413524815872,
			'used': 367597862912,
			'free': 45926952960,
			'percent': 88.9
		},
		'fstype': 'NTFS',
		'inodes': False
	}],
	'network': {
   
   
		
本文章已经生成可运行项目
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值