JSON统计
cpu_usage:
percpu_usage:Array(4)
0:14808372153
1:518274597399
2:42110957200
3:133104944364
length:4
__proto__:Array(0)
total_usage:708298871116
usage_in_kernelmode:15350000000
usage_in_usermode:692790000000
__proto__:Object
online_cpus:4
system_cpu_usage:16883147380000000
我得到一个这样的json,它给出了cpu_usage
我将码头工作者放在首位,使用率约为99-100%,但我的计算结果不到1%。像0,004
我做错了什么?
success: function (statistics) {
var totalUsage = statistics.cpu_stats.system_cpu_usage;
var currentUsage = statistics.cpu_stats.cpu_usage.total_usage;
var cpuUsage = (currentUsage / totalUsage) * 100;
}
你需要的公式是这个,但我没有precpu_stats所以我需要以某种方式保存以前的数据:
(cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage) / (cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage)