Ajax.php里面GetCpuPercentages函数- function GetCpuPercentages($stat1, $stat2) {
- if(count($stat1)!==count($stat2)){
- return;
- }
- $cpus=array();
- for( $i = 0, $l = count($stat1); $i < $l; $i++) {
- $dif = array();
- $dif['user'] = $stat2[$i]['user'] - $stat1[$i]['user'];
- $dif['nice'] = $stat2[$i]['nice'] - $stat1[$i]['nice'];
- $dif['sys'] = $stat2[$i]['sys'] - $stat1[$i]['sys'];
- $dif['idle'] = $stat2[$i]['idle'] - $stat1[$i]['idle'];
- $dif['iowait'] = $stat2[$i]['iowait'] - $stat1[$i]['iowait'];
- $dif['irq'] = $stat2[$i]['irq'] - $stat1[$i]['irq'];
- $dif['softirq'] = $stat2[$i]['softirq'] - $stat1[$i]['softirq'];
- $total = array_sum($dif);
- $cpu = array();
- foreach($dif as $x=>$y) $cpu[$x] = round($y / $total * 100, 2);
- $cpus['cpu' . $i] = $cpu;
- }
- return $cpus;
- }
复制代码 $total计算出来的数字可能是0 后面除法错误 导致出现了一个 float(NAN)的数据 这个无法被json_encode 最后导致这个ajax无法请求到结果
然后首页请求不到结果 layer的遮罩层不会消失 无法做任何操作
多次刷新后会正常
|
|