On a multicore linux server(54 cores), we are running services in docker container. In particular, am looking for how to calculate %CPU of a process using the %CPU value captured from TOP command for a specific process and calculate and assert if that process %CPU is beyond a user defined threshold say 75%.
For e.g, below are two process details captured from top command.
7180 user1 20 0 9855556 1.0g 9012 S 2100 6.4 332:06.06 java -cp /apps/service1 - %CPU is 2100 - here the %CPU is exceeding 100 i.e. it is using more than 1 core out of 54
6594 user1 20 0 7124652 235912 6888 S 0.7 1.5 272:53.89 java -cp /apps/service2 - %CPU is 0.7 - here the %CPU is 0.7
So, my requirement is to get the %CPU and calculate 75% threshold and then assert if 75% value with %CPU.
Threshold calculation,
threshold * total_core / 100 = 75 * 54 /100 = 40.5
And, getting %CPU from TOP command of a particular process and then, if it exceeding more than 100 then divide by 100 and then asserting with above threshold value. And, if it is below 100 then directly asserting with above threshold value.
Am not sure, this is correct. But out of my search in google and other places. I got the above and trying. But would like to conform from one of the experts from stackoverflow