@@ -108,6 +108,8 @@ public function stats()
108
108
}
109
109
110
110
if (server ()->isLinux ()) {
111
+ $ cores = str_replace ("cpu cores \t: " , '' , trim (explode ("\n" , Command::runSudo ("cat /proc/cpuinfo | grep 'cpu cores' " ))[0 ]));
112
+
111
113
$ cpuPercent = Command::runSudo (
112
114
"ps -eo %cpu --no-headers | grep -v 0.0 | awk '{s+=$1} END {print s/NR*10}' "
113
115
);
@@ -124,7 +126,7 @@ public function stats()
124
126
$ secondUp = $ this ->calculateNetworkBytes (false );
125
127
126
128
return [
127
- 'cpu ' => round ((float ) $ cpuPercent , 2 ),
129
+ 'cpu ' => round ((float ) $ cpuPercent / $ cores , 2 ),
128
130
'ram ' => round ((float ) $ ramPercent , 2 ),
129
131
'io ' => round ((float ) $ ioPercent , 2 ),
130
132
'network ' => [
@@ -295,14 +297,16 @@ private function calculateNetworkBytes($download = true)
295
297
*/
296
298
private function parsePsOutput ($ output )
297
299
{
300
+ $ cores = str_replace ("cpu cores \t: " , '' , trim (explode ("\n" , Command::runSudo ("cat /proc/cpuinfo | grep 'cpu cores' " ))[0 ]));
301
+
298
302
$ data = [];
299
303
foreach (explode ("\n" , (string ) $ output ) as $ row ) {
300
304
$ row = explode ('*-* ' , $ row );
301
305
$ row [3 ] = str_replace ('\\' , '/ ' , $ row [3 ]);
302
306
$ fetch = explode ('/ ' , $ row [3 ]);
303
307
$ data [] = [
304
308
'pid ' => $ row [0 ],
305
- 'percent ' => $ row [1 ],
309
+ 'percent ' => round ( $ row [1 ] / $ cores , 1 ) ,
306
310
'user ' => $ row [2 ],
307
311
'cmd ' => end ($ fetch ),
308
312
];
0 commit comments