如何计算某个进程cpu的占用率
来源: 互联网 发布时间:2016-06-16
本文导语: 我使用的是snmp 可以得到所有进程的CUP占用时间。 HOST-RESOURCES-MIB::hrSWRunPerfCPU.1 = INTEGER: 248 HOST-RESOURCES-MIB::hrSWRunPerfCPU.2 = INTEGER: 3 HOST-RESOURCES-MIB::hrSWRunPerfCPU.3 = INTEGER: 20 HOST-RESOURCES-MIB::hrSWRunPerfCPU.4 = INTEGER: 13 HOS...
我使用的是snmp
可以得到所有进程的CUP占用时间。
HOST-RESOURCES-MIB::hrSWRunPerfCPU.1 = INTEGER: 248
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2 = INTEGER: 3
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3 = INTEGER: 20
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4 = INTEGER: 13
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.21 = INTEGER: 156
HOST-RESOURCES-MIB::hrSWRunPerfCPU.22 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.39 = INTEGER: 70
HOST-RESOURCES-MIB::hrSWRunPerfCPU.40 = INTEGER: 46
HOST-RESOURCES-MIB::hrSWRunPerfCPU.41 = INTEGER: 55
HOST-RESOURCES-MIB::hrSWRunPerfCPU.42 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.188 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.421 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.431 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.432 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.447 = INTEGER: 9471
HOST-RESOURCES-MIB::hrSWRunPerfCPU.1670 = INTEGER: 33
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2427 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2569 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2980 = INTEGER: 2296
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2984 = INTEGER: 11
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3008 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3028 = INTEGER: 3
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3056 = INTEGER: 128
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3142 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3154 = INTEGER: 74
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3202 = INTEGER: 24
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3217 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3236 = INTEGER: 449
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3245 = INTEGER: 10
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3256 = INTEGER: 308
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3287 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3288 = INTEGER: 14
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3298 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3323 = INTEGER: 19
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3342 = INTEGER: 21
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3361 = INTEGER: 75
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3374 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3385 = INTEGER: 10038
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3458 = INTEGER: 10
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3501 = INTEGER: 58176
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3532 = INTEGER: 12902
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3605 = INTEGER: 562
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3612 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3613 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3616 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3617 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3618 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3710 = INTEGER: 5
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3751 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3796 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3971 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4068 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4115 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4116 = INTEGER: 27
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4355 = INTEGER: 23
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4400 = INTEGER: 175464
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4473 = INTEGER: 157
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4499 = INTEGER: 417
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4500 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4504 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4506 = INTEGER: 207
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4537 = INTEGER: 58
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4540 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4541 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4547 = INTEGER: 21
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4550 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4552 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4554 = INTEGER: 46
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4560 = INTEGER: 2164
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4592 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4596 = INTEGER: 173
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4598 = INTEGER: 153
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4600 = INTEGER: 19
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4602 = INTEGER: 136
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4604 = INTEGER: 327
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4606 = INTEGER: 121802
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4609 = INTEGER: 357
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4612 = INTEGER: 26
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4619 = INTEGER: 102
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4621 = INTEGER: 1880
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4623 = INTEGER: 331
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4625 = INTEGER: 25
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4627 = INTEGER: 30
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4628 = INTEGER: 3980
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4630 = INTEGER: 92
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4907 = INTEGER: 11139
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5236 = INTEGER: 6
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5385 = INTEGER: 3697
但是现在的问题是
如何通过这些数据计算某个进程的CPU占用率呢????
如果这个方法无法计算,那么如何通过snmp远程得到远程主机上某个进程CPU的占用率呢???
请教高手了!!!
(前提是不可以自己定义oid,不可以自己在被监控端写脚本,只能在被监控端安装snmp。别的不可以添加。)
可以得到所有进程的CUP占用时间。
HOST-RESOURCES-MIB::hrSWRunPerfCPU.1 = INTEGER: 248
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2 = INTEGER: 3
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3 = INTEGER: 20
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4 = INTEGER: 13
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.21 = INTEGER: 156
HOST-RESOURCES-MIB::hrSWRunPerfCPU.22 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.39 = INTEGER: 70
HOST-RESOURCES-MIB::hrSWRunPerfCPU.40 = INTEGER: 46
HOST-RESOURCES-MIB::hrSWRunPerfCPU.41 = INTEGER: 55
HOST-RESOURCES-MIB::hrSWRunPerfCPU.42 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.188 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.421 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.431 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.432 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.447 = INTEGER: 9471
HOST-RESOURCES-MIB::hrSWRunPerfCPU.1670 = INTEGER: 33
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2427 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2569 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2980 = INTEGER: 2296
HOST-RESOURCES-MIB::hrSWRunPerfCPU.2984 = INTEGER: 11
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3008 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3028 = INTEGER: 3
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3056 = INTEGER: 128
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3142 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3154 = INTEGER: 74
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3202 = INTEGER: 24
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3217 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3236 = INTEGER: 449
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3245 = INTEGER: 10
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3256 = INTEGER: 308
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3287 = INTEGER: 0
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3288 = INTEGER: 14
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3298 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3323 = INTEGER: 19
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3342 = INTEGER: 21
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3361 = INTEGER: 75
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3374 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3385 = INTEGER: 10038
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3458 = INTEGER: 10
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3501 = INTEGER: 58176
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3532 = INTEGER: 12902
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3605 = INTEGER: 562
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3612 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3613 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3616 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3617 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3618 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3710 = INTEGER: 5
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3751 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3796 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.3971 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4068 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4115 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4116 = INTEGER: 27
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4355 = INTEGER: 23
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4400 = INTEGER: 175464
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4473 = INTEGER: 157
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4499 = INTEGER: 417
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4500 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4504 = INTEGER: 4
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4506 = INTEGER: 207
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4537 = INTEGER: 58
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4540 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4541 = INTEGER: 2
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4547 = INTEGER: 21
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4550 = INTEGER: 1
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4552 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4554 = INTEGER: 46
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4560 = INTEGER: 2164
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4592 = INTEGER: 40
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4596 = INTEGER: 173
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4598 = INTEGER: 153
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4600 = INTEGER: 19
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4602 = INTEGER: 136
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4604 = INTEGER: 327
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4606 = INTEGER: 121802
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4609 = INTEGER: 357
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4612 = INTEGER: 26
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4619 = INTEGER: 102
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4621 = INTEGER: 1880
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4623 = INTEGER: 331
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4625 = INTEGER: 25
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4627 = INTEGER: 30
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4628 = INTEGER: 3980
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4630 = INTEGER: 92
HOST-RESOURCES-MIB::hrSWRunPerfCPU.4907 = INTEGER: 11139
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5236 = INTEGER: 6
HOST-RESOURCES-MIB::hrSWRunPerfCPU.5385 = INTEGER: 3697
但是现在的问题是
如何通过这些数据计算某个进程的CPU占用率呢????
如果这个方法无法计算,那么如何通过snmp远程得到远程主机上某个进程CPU的占用率呢???
请教高手了!!!
(前提是不可以自己定义oid,不可以自己在被监控端写脚本,只能在被监控端安装snmp。别的不可以添加。)
|
stat文件中的数据对应的utime和stime就是进程的用户态和内核态中运行的滴答数读/proc/pid/stat文件,然后把这两个值sscanf出来,这两个值的和除以统计间隔时间(用gettimeofday填充struct timeval.tv_sec,取两次相差)就是该进程的cpu占有率
|
你在做什么项目?MAS?
LINUX系统是有查看CPU占用率的命令吗?如TOP,也有其它的。
LINUX系统是有查看CPU占用率的命令吗?如TOP,也有其它的。
|
不会,关注ing