cpu io disk mem监控 python
import psutil def cpu_information():
#scputimes(user=26.9, nice=0.1, system=50.27, idle=8551.89, iowait=1.97, irq=0.0, softirq=1.86, steal=0.0, guest=0.0, guest_nice=0.0)
cpu_schemas=[ ("%usertime","%Nice", "%system","%idle" ,"%iowait","irq","softirq","steal","guest","guest_nice" )]
cpuinfo_list=psutil.cpu_times(percpu=True)
for cpu in cpuinfo_list:
user=cpu.user
nice=cpu.nice
system=cpu.system
idle=cpu.idle
iowait=cpu.iowait
irq=cpu.irq
softirq=cpu.softirq
steal=cpu.steal
guest=cpu.guest
guest_nice=cpu.guest_nice
info=[user,nice,system,idle,iowait,irq,softirq,steal,guest,guest_nice]
cpu_schemas.append(info)
# cpu_schemas.append(psutil.cpu_percent(percpu=True))
for i in cpu_schemas:
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9]]
b=[str(i) for i in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9])
def disk_info():
# disk=psutil.cpu_percent(percpu=True)
infos=[["r_count","w_count","r_bytes","w_bytes","r_time","w_time","r_merge_count","w_merge_count","busy_time"]]
disks=psutil.disk_io_counters(perdisk=True)
for k,v in disks.items():
read_count=v.read_count
write_count=v.write_count
read_bytes=v.read_bytes
write_bytes=v.write_bytes
read_time=v.read_time
write_time=v.write_time
read_merge_count=v.read_merged_count
write_merge_count=v.write_merged_count
busy_time=v.busy_time one_disk=[k,read_count,write_count,read_bytes,write_bytes,read_time,write_time,read_merge_count,write_merge_count,busy_time]
infos.append(one_disk)
for i in infos:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8]]
b = [str(m) for m in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8]) def network_info():
nets=psutil.net_io_counters(pernic=True)
nets_info=[["network_card","sent_bytes","recv_bytes","packets_sent","packets_recv","errin","errout","dropin","dropout"]]
for k,v in nets.items():
network=k
bytes_sent=v.bytes_sent
bytes_recv=v.bytes_recv
packets_sent=v.packets_sent
packets_recv=v.packets_recv
errorin=v.errin
errout=v.errout
dropin=v.dropin
dropout=v.dropout
one_net=[network,bytes_sent,bytes_recv,packets_sent,packets_recv,errorin,errout,dropin,dropout]
nets_info.append(one_net)
for i in nets_info:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8]]
b=[str(m) for m in a]
print(b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8]) def mem_info():
mems=psutil.virtual_memory()
total=mems.total
used=mems.used
free=mems.free
available=mems.available
percent=mems.percent
active=mems.active
inactive=mems.inactive
buffers=mems.buffers
cached=mems.cached
shared=mems.shared
slab=mems.slab swaps=psutil.swap_memory()
swap_total=swaps.total
# swap_available=swaps.available swap_used=swaps.used
swap_free=swaps.free
swap_percent = swaps.percent
sin=swaps.sin
sout=swaps.sout # swap_active=swaps.active
# swap_inactive=swaps.inactive
# swap_buffers=swaps.buffers
# swap_cached=swaps.cached
# swap_shared=swaps.shared
# swap_slab=swaps.slab
virtual_mem_info =[["total","used","free","available","percent","active","inactive","buffers","cached","shared","slab"]]
swaps_mem_info=[["swap_total","swap_used","swap_free","swap_percent","sin","sout"]]
virtual_mem_info.append([total,used,free,available,percent,active,inactive,buffers,cached,shared,slab])
swaps_mem_info.append([swap_total,swap_used,swap_free,swap_percent,sin,sout])
# virtual_mem_info.extend(swaps_mem_info)
for i in virtual_mem_info:
#print(i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10])
a=[i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7],i[8],i[9],i[10]]
b=[str(m) for m in a]
print(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10])
for j in swaps_mem_info:
#print(j[0],j[1],j[2],j[3],j[4],j[5])
c=[j[0],j[1],j[2],j[3],j[4],j[5]]
d=[str(y) for y in c]
print(d[0],d[1],d[2],d[3],d[4],d[5]) def unions():
print("=====cpuinfo=======")
cpu_information()
print("======disk info=====")
disk_info()
print("=====meminfo========")
mem_info()
print("======netioinfo=====")
network_info() if __name__ == '__main__':
unions()
cpu io disk mem监控 python的更多相关文章
- Linux 性能监控之CPU&内存&I/O监控Shell脚本1
Linux 性能监控之CPU&内存&I/O监控Shell脚本1 by:授客 QQ:1033553122 #!/bin/bash # 获取要监控的本地服务器IP地址 IP=`if ...
- Linux 性能监控之CPU&内存&I/O监控Shell脚本2
Linux 性能监控之CPU&内存&I/O监控Shell脚本2 by:授客 QQ:1033553122 思路: 捕获数据->停止捕获数据->提取数据 备注:一些命令的输 ...
- java 7中新增的CPU和负载的监控
java 7中新增的CPU和负载的监控 import java.lang.management.ManagementFactory; import java.lang.management.Opera ...
- CPU IO MEM NETWork 监控命令
性能优化中CPU.内存.磁盘IO.网络性能的依赖(上) 性能优化中CPU.内存.磁盘IO.网络性能的依赖(下)
- 性能分析之工具使用——cpu、io 、mem【工具分析】
nmon nmon 是一种在aix 与各种 Linux 操作系统上广泛使 用的监控与与分析工具,他主要记录以下内容: • cpu 占用率 • 内存使用情况 • 磁盘I/O 速度.传输和读写比率 • 文 ...
- stress施压案例分析——cpu、io、mem【命令分析】
stress施压命令分析 一.stress --cpu 1 --timeout 600 分析现象?负载为啥这么高?top命令查看用户进程消耗的cpu过高(stress进程消耗的) 分析现象,可以看出 ...
- Linux系统资源查询命令(cpu、io、mem)
cpu/mem: 1. 指定pid top -p pid1,pid2,... 2. top排序 先top,然后 输入大写P,则结果按CPU占用降序排序.输入大写M,结果按内存占用降序排序. io: ...
- CPU、io、mem之间的关系
https://blog.csdn.net/weixin_38250126/article/details/83412749 https://blog.csdn.net/joeyon1985/arti ...
- 分布式监控系统Zabbix3.2添加自动发现磁盘IO并注册监控
zabbix并没有给我们提供这么一个模板来完成在Linux中磁盘IO的监控,所以我们需要自己来创建一个,在此还是在Linux OS中添加. 由于一台服务器中磁盘众多,如果只一两台可以手动添加,但服务 ...
随机推荐
- yii消息提示扩展
//安装 composer.phar require --prefer-dist yiister/yii2-gentelella "~1.0" //消息存入 Yii::$app-& ...
- python接口自动化测试之根据excel中的期望结果是否存在于请求返回的响应值中来判断用例是否执行成功
1.首先在excel中填写好预期结果的值 这里判断接口成功的依据是预期结果值是否存在于接口的返回数据中. 一般接口的返回值都是json对象,我们需要将json对象转换为json格式的字符串 如下图,进 ...
- Codeforces Round #601 (Div. 2) C League of Leesins
把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和 ...
- 连接本地mysql报错
报错信息如下: 原因为未启动本地mysql,没设置开机自启动.
- SVN merge(合并) 时看不到以前的已经合并过的记录的标识
今天遇到这么一个事情,merge的时候以前merge过的提交记录,咩有已合并过的标识了,就是下面这样的尾巴分叉向下的箭头 通常出现这样的情况,都是工程路径不对,检查了一下,没有问题,这些meng B ...
- 题解【Codeforces859C】Pie Rules
题面 一道需要一定思考的 \(\text{DP}\) . 设 \(dp_i\) 表示第 \(i\) 步走的人能得到的最大分数, \(sum_i\) 表示 \(\sum_{j=i}^n a_j\) ,即 ...
- scp知识点
小伙伴的博客(详细): https://www.cnblogs.com/ppp204-is-a-VC/p/11673567.html
- ssh: connect to git@gitlab.xxxxx.com:xxxxx.git port 22: Connection refused
公司服务器上的gitlab项目添加了ssh密钥,但是操作时却报错ssh: connect to git@gitlab.xxxxx.com:xxxxx.git port 22: Connection r ...
- css实现移动端滚动条隐藏仍然可以滚动内容
.g-panel { height: calc(100% - 112px); overflow: auto; &::-webkit-scrollbar { display: none; // ...
- 题解【洛谷P1514】[NOIP2010]引水入城
题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 \(N\) 行 \(M\) 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市 ...