python获得linux服务器的内存使用率,虚拟内存使用率

python获得linux服务器的内存使用率,虚拟内存使用率,第1张

概述python获得linux服务器内存使用率,虚拟内存使用率

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

@H_419_5@def get_mem_usage_percent(): try: f = open('/proc/meminfo','r') for line in f: if line.startswith('MemTotal:'): mem_total = int(line.split()[1]) elif line.startswith('MemFree:'): mem_free = int(line.split()[1]) elif line.startswith('Buffers:'): mem_buffer = int(line.split()[1]) elif line.startswith('Cached:'): mem_cache = int(line.split()[1]) elif line.startswith('SwapTotal:'): vmem_total = int(line.split()[1]) elif line.startswith('SwapFree:'): vmem_free = int(line.split()[1]) else: continue f.close() except: return None physical_percent = usage_percent(mem_total - (mem_free + mem_buffer + mem_cache),mem_total) virtual_percent = 0 if vmem_total > 0: virtual_percent = usage_percent((vmem_total - vmem_free),vmem_total) return physical_percent,virtual_percentdef usage_percent(use,total): try: ret = (float(use) / total) * 100 except ZerodivisionError: raise Exception("ERROR - zero division error") return ret

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的python获得linux服务器的内存使用率,虚拟内存使用率全部内容,希望文章能够帮你解决python获得linux服务器的内存使用率,虚拟内存使用率所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1198727.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-03
下一篇2022-06-03

发表评论

登录后才能评论

评论列表(0条)

    保存