É possível calcular a utilização da CPU a partir da coluna load average & top CPU%

0

Eu tenho um arquivo que contém 2 saídas de tempo médio de carregamento e & Coluna% da CPU como uma saída do comando superior.

Então, é possível calcular isso na utilização da CPU ou no uso da CPU por vez?

Exemplo:

=====================================================================
        APPLIANCE CPU USAGE
=====================================================================

0.90 1.05 0.84 1/151 13615

=====================================================================
        APPLIANCE PROCESSES
=====================================================================

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   2184   700 ?        Ss   22:48   0:00 init [3]                          
root         2  0.0  0.0      0     0 ?        S<   22:48   0:00 [migration/0]
root         3  0.0  0.0      0     0 ?        SN   22:48   0:00 [ksoftirqd/0]
root         4  0.0  0.0      0     0 ?        S<   22:48   0:00 [watchdog/0]
root         5  0.0  0.0      0     0 ?        S<   22:48   0:00 [migration/1]
root         6  0.0  0.0      0     0 ?        SN   22:48   0:00 [ksoftirqd/1]
root         7  0.0  0.0      0     0 ?        S<   22:48   0:00 [watchdog/1]
root         8  0.0  0.0      0     0 ?        S<   22:48   0:00 [events/0]
root         9  0.0  0.0      0     0 ?        S<   22:48   0:00 [events/1]
root        10  0.0  0.0      0     0 ?        S<   22:48   0:00 [khelper]
root        11  0.0  0.0      0     0 ?        S<   22:48   0:00 [kthread]
root        15  0.0  0.0      0     0 ?        S<   22:48   0:00 [kblockd/0]
root        16  0.0  0.0      0     0 ?        S<   22:48   0:00 [kblockd/1]
root        17  0.0  0.0      0     0 ?        S<   22:48   0:00 [kacpid]
root       163  0.0  0.0      0     0 ?        S<   22:48   0:00 [cqueue/0]
root       164  0.0  0.0      0     0 ?        S<   22:48   0:00 [cqueue/1]
root       167  0.0  0.0      0     0 ?        S<   22:48   0:00 [khubd]
root       169  0.0  0.0      0     0 ?        S<   22:48   0:00 [kseriod]
root       242  0.0  0.0      0     0 ?        S    22:48   0:00 [khungtaskd]
root       243  0.0  0.0      0     0 ?        S    22:48   0:00 [pdflush]
root       244  0.0  0.0      0     0 ?        S    22:48   0:00 [pdflush]
root       245  0.0  0.0      0     0 ?        S<   22:48   0:00 [kswapd0]
root       246  0.0  0.0      0     0 ?        S<   22:48   0:00 [aio/0]
root       247  0.0  0.0      0     0 ?        S<   22:48   0:00 [aio/1]
root       411  0.0  0.0      0     0 ?        S<   22:49   0:00 [kpsmoused]
root       440  0.0  0.0      0     0 ?        S<   22:49   0:00 [ata/0]
root       441  0.0  0.0      0     0 ?        S<   22:49   0:00 [ata/1]
root       442  0.0  0.0      0     0 ?        S<   22:49   0:00 [ata_aux]
root       446  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_0]
root       447  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_1]
root       448  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_2]
root       449  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_3]
root       450  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_4]
root       451  0.0  0.0      0     0 ?        S<   22:49   0:00 [scsi_eh_5]
root       452  1.0  0.0      0     0 ?        S<   22:49   0:00 [kjournald]
root       469  2.0  0.0      0     0 ?        S<   22:49   0:00 [kauditd]
root       497  3.0  0.0   2368   672 ?        S<s  22:49   0:00 /sbin/udevd -d
root      1395  4.0  0.0      0     0 ?        S<   22:49   0:00 [kjournald]
root      1397  5.0  0.0      0     0 ?        S<   22:49   0:00 [kjournald]
root      1399  6.0  0.0      0     0 ?        S<   22:49   0:00 [kjournald]
    
por ktikar 25.04.2018 / 05:58

1 resposta

0

Você pode calcular cpu% com o seguinte código:

#!/bin/bash 
FILE=<file path>  
CPU_USAGE='sed -n 'H; /^USER/h; ${g;p;}' $FILE | awk '{print $3}' | awk '{sum+=$1} END {print sum ;}'' 
CPU_CORES='nproc --all'
ACTUAL_CPU_USAGE='echo "$CPU_USAGE $CPU_CORES" | awk '{print $1/$2"%"}''
echo "CPU : $ACTUAL_CPU_USAGE"
    
por 25.04.2018 / 07:08