当前位置: 首页 > news >正文

电商网站建设书空间设计师工资一般多少

电商网站建设书,空间设计师工资一般多少,网页被禁用了怎么解除,长沙做网站哪家好一、工具#xff1a;psutil模块 psutil是一个跨平台模块#xff0c;试用相应方法可以直接获取计算机CPU#xff0c;内存#xff0c;磁盘#xff0c;网络等资源使用情况#xff1b;可以使用我们学习知识与这模块用来做系统监控#xff0c;性能分析#xff1b;如果大家熟…一、工具psutil模块 psutil是一个跨平台模块试用相应方法可以直接获取计算机CPU内存磁盘网络等资源使用情况可以使用我们学习知识与这模块用来做系统监控性能分析如果大家熟悉Linux系统它能够实现ps、top、lsof、netstat、df等命令功能。 1.1、psutil安装 psutil是第三方模块使用时候需要要安装相关说明链接地址https://pypi.org/project/psutil/  pip安装方式 pip install psutil 验证 #导入模块import psutil#查看版本信息psutil.version_info 输出信息 (5, 4, 8) 这里说明安装成功版本可能会不同但是不影响使用 1.2 获取CPU信息 使用下面这些方法可以获取计算机CPU数量CPU使用率 方法说明cpu_count(logicalTrue)获取CPU数量cpu_times(percpuFalse)获取不同状态下CPU运行时间cpu_percent(intervalNone, percpuFalse)获取CPU使用率cpu_times_percent(intervalNone, percpuFalse)获取CPU各状态占百分比 两个个知识点需要简单介绍下这里只需要了解即可 1CPU数量CPU分为物理CPU与逻辑CPU之间关系如下 1物理CPU计算机实际CPU数量一般个人电脑1个 2核数现在CPU基本都是多核比如双核4核 3逻辑CPU物理CPU*核数*超线程数 2CPU运行状态分为用户态与内核态 1用户态是指程序在内存运行不直接访问硬件资源 2用户需要访问硬件资源需要系统调用这部分有操作系统内核完成称为内核态例如读写文件网络数据收发键盘事件获取等 下面我们来实际操作下windows环境 import psutil#获取CPU不同状态运行时间print(psutil.cpu_times())print(CPU 执行用户进程时间, psutil.cpu_times().user)print(CPU 执行系统调用时间, psutil.cpu_times().system)print(CPU 空闲等待 时间, psutil.cpu_times().idle)print(CPU 响应中断 时间, psutil.cpu_times().interrupt)#CPU使用率不加参数为上一次调用到现在使用率print(CPU 使用率,psutil.cpu_percent())#3秒内CPU使用率print(CPU 3秒内使用率,psutil.cpu_percent(interval3))#3秒内每个CPU使用率print(每个逻辑CPU使用率,psutil.cpu_percent( percpu True))#CPU各个状态使用情况百分比print(CPU 各个状态使用情况,psutil.cpu_times_percent())#每个CPU各个状态使用情况print(各个CPU 各个状态使用情况:)cpuinfos psutil.cpu_times_percent(percpu True)for info in cpuinfos:print(info) 运行结果如下: scputimes(user85326.484375, system56630.8125, idle2245745.0625, interrupt5347.296875, dpc1395.984375)CPU 执行用户进程时间 85326.484375CPU 执行系统调用时间 56630.8125CPU 空闲等待 时间 2245745.0625CPU 响应中断 时间 5347.296875CPU 使用率 3.4CPU 3秒内使用率 2.5每个逻辑CPU使用率 [7.0, 2.1, 4.5, 2.5, 2.7, 2.1, 2.1, 2.7]CPU 各个状态使用情况 scputimes(user1.4, system1.5, idle96.8, interrupt0.3, dpc0.0)各个CPU 各个状态使用情况:scputimes(user1.8, system3.1, idle93.0, interrupt1.9, dpc0.2)scputimes(user0.4, system1.6, idle97.9, interrupt0.1, dpc0.0)scputimes(user1.6, system2.8, idle95.5, interrupt0.1, dpc0.0)scputimes(user1.0, system1.4, idle97.5, interrupt0.1, dpc0.0)scputimes(user2.4, system0.2, idle97.3, interrupt0.0, dpc0.0)scputimes(user1.1, system1.0, idle97.9, interrupt0.0, dpc0.0)scputimes(user0.8, system1.2, idle97.9, interrupt0.0, dpc0.0)scputimes(user1.8, system0.7, idle97.3, interrupt0.1, dpc0.0) 对于不同系统获取内容稍微有所不同大家可以在linux尝试下操作。 1.3 获取系统内存信息 程序在内存中运行实际工作中我们需要对内存进行监控如果内存使用接近100%可能存在内存泄漏等问题我们主要关注内存的total(内存总数)used(已使用)free(未使用)情况相关方法如下 方法说明psutil.virtual_memory获取内存使用情况不同系统返回值不同psutil.swap_memory()获取swap内存使用情况 实际操作如下windows环境下 import psutilmem psutil.virtual_memory()print(系统内存, mem)print(总 内存, mem.total)print(空闲内存, mem.available)print(使用内存, mem.used)print(未使用内存, mem.free)print(内存使用率, mem.percent)print(swap 内存, psutil.swap_memory()) 输出结果 系统内存 svmem(total8494747648, available5058498560, percent40.5, used3436249088, free5058498560)总 内存 8494747648空闲内存 5058498560使用内存 3436249088未使用内存 5058498560内存使用率 40.5swap 内存 sswap(total15205634048, used4902215680, free10303418368, percent32.2, sin0, sout0) 看到这些数字有点晕我们更喜欢M或者G来堆内存进行描述修改下代码 import psutil#1M 1024*1024#1G 1024*1024*1024M 1024*1024G M * 1024mem psutil.virtual_memory()print(系统内存, mem)print(总 内存%dM %fG%(mem.total//M, mem.total/G))print(空闲内存%dM %fG%(mem.available//M, mem.available/G))print(使用内存%dM %fG%(mem.used//M, mem.used/G))print(未使用内存%dM %fG%(mem.free//M, mem.free/G))print(内存使用率%d%%% mem.percent)print(swap 内存, psutil.swap_memory()) 输出结果如下 系统内存 svmem(total8494747648, available4726083584, percent44.4, used3768664064, free4726083584)总 内存8101M 7.911350G空闲内存4507M 4.401508G使用内存3594M 3.509842G未使用内存4507M 4.401508G内存使用率44%swap 内存 sswap(total14668763136, used5127331840, free9541431296, percent35.0, sin0, sout0) 1.4 获取系统磁盘 实际工作中我们需要关注硬盘空间及IO读写如果硬盘空间不足就需要添加硬盘或者动态扩容硬盘相应的方法如下 方法说明disk_partitions(allFalse)获取硬盘分区信息返回分区列表disk_usage(path)获取硬盘使用情况path为路径disk_io_counters(perdiskFalse, nowrapTrue)硬盘IO读取信息 下面我们实际操作下 import psutil#获取硬盘分区devs psutil.disk_partitions()#显示硬盘信息print(devs)#硬盘名称与挂载点文件类型for dev in devs:print(硬盘名%s, 挂载点%s, 文件类型%s%(dev.device, dev.mountpoint, dev.fstype)) 输出结果如下 [sdiskpart(deviceC:\\, mountpointC:\\, fstypeNTFS, optsrw,fixed), sdiskpart(deviceD:\\, mountpointD:\\, fstypeNTFS, optsrw,fixed), sdiskpart(deviceE:\\, mountpointE:\\, fstypeNTFS, optsrw,fixed), sdiskpart(deviceF:\\, mountpointF:\\, fstypeNTFS, optsrw,fixed), sdiskpart(deviceG:\\, mountpointG:\\, fstypeNTFS, optsrw,fixed)]硬盘名C:\, 挂载点C:\, 文件类型NTFS硬盘名D:\, 挂载点D:\, 文件类型NTFS硬盘名E:\, 挂载点E:\, 文件类型NTFS硬盘名F:\, 挂载点F:\, 文件类型NTFS硬盘名G:\, 挂载点G:\, 文件类型NTFS 下面使用disk_usage方法来获取G盘使用情况 #根据前面打印信息G盘使用G:\表示print(psutil.disk_usage(G:\)) 实际输出结果 File , line 2print(psutil.disk_usage(G:\))^SyntaxError: EOL while scanning string literal 因为Python解释器将\转义为单引号所有会报错在这里我们表示\表示反斜杠 修改后代码 import psutil#定义函数参数为路径def showDiskInfo(path):G 1024*1024*1024diskinfo psutil.disk_usage(path)print(path, diskinfo)#将字节转换成Gprint(%s 大小: %dG, 已使用: %dG, 未使用: %dG, 使用百分比:%d%%%\(path, diskinfo.total//G, diskinfo.used//G, diskinfo.free//G,diskinfo.percent))showDiskInfo(G:\\) 输出结果​​​​​​​ G:\ sdiskusage(total188978556928, used166646931456, free22331625472, percent88.2)G:\ 大小: 175G, 已使用: 155G, 未使用: 20G, 使用百分比:88% 下面我们查看每个硬盘信息 import psutil#定义函数参数为路径def showDiskInfo(path):G 1024*1024*1024diskinfo psutil.disk_usage(path)#将字节转换成Gprint(%s 大小: %dG, 已使用: %dG, 未使用: %dG, 使用百分比:%d%%%\(path, diskinfo.total//G, diskinfo.used//G, diskinfo.free//G,diskinfo.percent))#获取硬盘分区devs psutil.disk_partitions()for dev in devs:#分别显示每个showDiskInfo(dev.device) 输出结果 C:\ 大小: 118G, 已使用: 66G, 未使用: 51G, 使用百分比:56%D:\ 大小: 117G, 已使用: 10G, 未使用: 107G, 使用百分比:8%E:\ 大小: 150G, 已使用: 58G, 未使用: 92G, 使用百分比:38%F:\ 大小: 149G, 已使用: 71G, 未使用: 78G, 使用百分比:47%G:\ 大小: 175G, 已使用: 155G, 未使用: 20G, 使用百分比:88% 这样每个硬盘使用情况我们都清楚了。 最后我们来看硬盘读写主要信息为读写数读写字节读写时间操作如下 import psutildiskrw psutil.disk_io_counters()#diskrw为硬盘总的读写信息print(diskrw)diskrws psutil.disk_io_counters(perdiskTrue)#diskrws为字典类型表示每个分区读写信息观察diskrw与diskrws值的关系print(diskrws) 输出信息 sdiskio(read_count2702580, write_count3112627, read_bytes92492292608, write_bytes72206786048, read_time2702, write_time3049){PhysicalDrive0: sdiskio(read_count98229, write_count392179, read_bytes8924618240, write_bytes4908920832, read_time37, write_time289), PhysicalDrive1: sdiskio(read_count2604351, write_count2720448, read_bytes83567674368, write_bytes67297865216, read_time2665, write_time2760)} 通过这些方法我们可以监控硬盘使用情况如果硬盘空间不足可以通过邮件报警发送邮件方法我们后面章节详细讲解。 1.5 获取进程信息 计算机中每个程序都是一个进程或者多个进程除去系统占用资源其他都被这些进程占用比如我们的web服务数据库等很多情况下因为程序自身问题会导致CPU运行100%内存耗尽磁盘写满最后导致服务崩溃我们可以通过psutil下面2个方法获取进程相关信息主要方法如下 方法说明psutil.pids()获取进程ID每个进程都有唯一IDpsutil.Process(pid)根据进程ID获取进程Process对象 实际操作 import psutil#获取当前所有进程pids psutil.pids()print(pids)#获取ID为pids[0]的进程,process psutil.Process(pids[0])print(process) 输出结果 [0, 4, 120, 440, 624, 736, 744, ... ...]psutil.Process(pid0, nameSystem Idle Process, started19:55:14) 结果中可以看到进程的ID为0 名称为System Idle Process 我们再来看Process对象属性(不同系统方法可能不同)​​​​​​​ import psutil#主要信息进程名状态创建时间CPU内存使用情况线程数p psutil.Process(0)print(进程名称:, p.name()) #进程名称print(运行状态:, p.status()) #当前状态print(创建时间:, p.create_time()) #创建时间print(CPU信息:, p.cpu_times()) #进程的cpu时间信息,主要user,system运行时间print(内存信息:, p.memory_percent())#进程内存利用率print(内存使用:, p.memory_info()) #进程内存使用详情print(IO信息, p.io_counters() ) #进程的IO信息,包括读写IO数字及参数print(线程数, p.num_threads() ) #进程开启的线程数 输出结果如下 进程名称: System Idle Process运行状态: running创建时间: 1543290248.0CPU信息: pcputimes(user0.0, system367377.99999999994, children_user0.0, children_system0.0)内存信息: 4.969912151832804e-05内存使用: pmem(rss4096, vms0, num_page_faults2, peak_wset4096, wset4096, peak_paged_pool0, paged_pool0, peak_nonpaged_pool0, nonpaged_pool0, pagefile0, peak_pagefile0, private0)IO信息 pio(read_count0, write_count0, read_bytes0, write_bytes0, other_count0, other_bytes0)线程数 4 p.memory_info()返回pmem对象其中rss为进程实际使用内存大小 二、python获取磁盘使用、GPU信息、根据进程号获取进程信息 pynvml 获取GPU信息psutil 获取进程信息,系统信息等示例另一台电脑 1、代码 import pynvml #获取GPU信息 import psutil #获取进程信息,系统信息等class Utils(object):# 获取硬盘信息staticmethoddef get_disk_info(path):G 1024*1024diskinfo psutil.disk_usage(path)# 将字节转换成Ginfo path:%s total:%dG, used:%dG, free:%dG, used_percent:%d%%%(path,diskinfo.total/G, diskinfo.used/G, diskinfo.free/G, diskinfo.percent)return info# 获取硬盘分区staticmethoddef get_disk_partitions():return psutil.disk_partitions()# 获取当前所有进程staticmethoddef get_current_process_pid():pids psutil.pids()return pids# 获取进程信息staticmethoddef get_process_info(pid):#主要信息进程名状态创建时间CPU内存使用情况线程数p psutil.Process(pid) # print(进程名称:, p.name()) #进程名称# print(运行状态:, p.status()) #当前状态# print(创建时间:, p.create_time()) #创建时间# print(CPU信息:, p.cpu_times()) #进程的cpu时间信息,主要user,system运行时间# print(内存信息:, p.memory_percent())#进程内存利用率# print(内存使用:, p.memory_info()) #进程内存使用详情# print(IO信息, p.io_counters()) #进程的IO信息,包括读写IO数字及参数# print(线程数, p.num_threads()) #进程开启的线程数info name:{} pid:{} \nstatus:{} \ncreate_time:{} \ncpu_times:{} \nmemory_percent:{} \nmemory_info:{} \nio_counters{} \nnum_threads{}.format(p.name(), pid, p.status(), p.create_time(), p.cpu_times(), p.memory_percent(), p.memory_info(), p.io_counters(), p.num_threads()) return infoclass GpuInfo(object):def __init__(self):#初始化pynvml.nvmlInit()def get_gpu_device(self):deviceCount pynvml.nvmlDeviceGetCount()gpu_list []for i in range(deviceCount):handle pynvml.nvmlDeviceGetHandleByIndex(i)print(GPU, i, :, pynvml.nvmlDeviceGetName(handle))gpu_list.append(i)return gpu_listdef get_free_rate(self, gpu_id):handle pynvml.nvmlDeviceGetHandleByIndex(gpu_id)info pynvml.nvmlDeviceGetMemoryInfo(handle)free_rate int((info.free / info.total) * 100)return free_ratedef get_gpu_info(self, gpu_id):handle pynvml.nvmlDeviceGetHandleByIndex(gpu_id)info pynvml.nvmlDeviceGetMemoryInfo(handle)M 1024*1024gpu_info id:{} total:{}M free:{}M used:{}M free_rate:{}%.format(gpu_id, info.total/M, info.free/M, info.used/M, self.get_free_rate(gpu_id))return gpu_infodef release(self):#最后要关闭管理工具pynvml.nvmlShutdown()if __name__ __main__:print(磁盘信息----------------------------)devs Utils.get_disk_partitions()for dev in devs:print(Utils.get_disk_info(dev.device))print(Utils.get_disk_info(/home))print(Utils.get_disk_info(/data))print(进程信息----------------------------)# # 需要管理员权限# pids Utils.get_current_process_pid()# for pid in pids:# print(Utils.get_process_info(pid))print(Utils.get_process_info(6403))print(GPU信息----------------------------)gpu_info GpuInfo()gpu_devices gpu_info.get_gpu_device()print(GPU使用信息----------------------------)for gpuid in gpu_devices:print(gpu_info.get_gpu_info(gpuid))gpu_info.release() 2、结果 xyavs05:~/test_code/test$ python utils.py 磁盘信息---------------------------- path:/dev/sda1 total:128773G, used:0G, free:128773G, used_percent:0% path:/dev/sdb1 total:128773G, used:0G, free:128773G, used_percent:0% path:/home total:899747G, used:844714G, free:9306G, used_percent:98% path:/data total:6811979G, used:3515451G, free:2953201G, used_percent:54% 进程信息---------------------------- name:python pid:6403 status:sleeping create_time:1572787886.51 cpu_times:pcputimes(user16.6, system2.32, children_user0.0, children_system0.0) memory_percent:0.01580510616382157 memory_info:pmem(rss42692608, vms510906368, shared8900608, text2342912, lib0, data56336384, dirty0) io_counterspio(read_count5249, write_count8001, read_bytes16384, write_bytes26464256, read_chars1097175, write_chars24049039) num_threads2 GPU信息---------------------------- GPU 0 : bGeForce RTX 2080 Ti GPU 1 : bGeForce RTX 2080 Ti GPU 2 : bGeForce RTX 2080 Ti GPU 3 : bGeForce RTX 2080 Ti GPU 4 : bGeForce RTX 2080 Ti GPU 5 : bGeForce RTX 2080 Ti GPU 6 : bGeForce RTX 2080 Ti GPU 7 : bGeForce RTX 2080 Ti GPU使用信息---------------------------- id:0 total:10989.4375M free:7344.9375M used:3644.5M free_rate:66% id:1 total:10989.4375M free:6308.9375M used:4680.5M free_rate:57% id:2 total:10989.4375M free:10876.5625M used:112.875M free_rate:98% id:3 total:10989.4375M free:10978.5625M used:10.875M free_rate:99% id:4 total:10989.4375M free:10978.5625M used:10.875M free_rate:99% id:5 total:10989.4375M free:10978.5625M used:10.875M free_rate:99% id:6 total:10989.4375M free:9497.5625M used:1491.875M free_rate:86% id:7 total:10989.4375M free:5090.0625M used:5899.375M free_rate:46%
http://www.yutouwan.com/news/145597/

相关文章:

  • 做相册集什么网站抖音代运营报价表
  • 东莞路桥投资建设公司招聘北京网站推广优化公司
  • 如何与对方网站做相互链接wordpress鼠标点击文字手机端
  • 深圳市企业网站seo点击软件建网站用什么浏览器
  • 短租房网站哪家做最好wordpress 文章页面怎样全屏显示
  • 网站开发要求网站服务器租一个月
  • 八度 网站建设新农宝网站建设方案
  • 天元建设集团有限公司审计项目烟台优化公司
  • 建设网站的公司兴田德润在哪里国外做图片识别训练的网站
  • 网站加载特效代码php做的网站怎么运行
  • 网站建设 调研报告深圳设计工作室有哪些
  • 中英网站建立湖南州省郴州
  • 如何自己编写网站wordpress访客ip地址插件
  • 先买域名不建设网站吗无锡网页制作报价
  • 贵州旅游网站建设策划书html做的好看的网站
  • 网站建设源程序清单宁波seo推广优化
  • 自己做的网站出现广告北京专业建设网站公司
  • 南通专业做网站wordpress应用在虚拟主机上
  • 做土地租赁买卖的网站有哪些win服务器做网站
  • 网站建设制作设计开发找别人做网站怎么防止别人修改
  • 天津营销类网站设计营销推广
  • 惠州网站建设怎么样网商网官网
  • 免费素材哪个网站比较好想建立一个网站怎么做
  • 网站建设合同范本学做各种糕点的网站
  • app手机网站模板免费下载设计教育培训
  • 个人网站推广怎么做宁波网络推广方案公司推荐
  • 企业门户网站的主要技术指标宁波网站推广优化联系电话
  • 学校网站建设制度高中作文网站
  • 论文中引用网站怎么写杭州网站建设过程
  • 站长工具网站推广合优人才网下载