Coleta de Performance com SAR (systat package)
Publicado por Hertz Raya Zocolan Silva (última atualização em 06/07/2018)
[ Hits: 3.223 ]
Download coleta_performance.sh
Script para coleta de dados de performance. Pode ser inserido na cron do root. Necessita o pacote sysstat.
Informações levantadas:
Data;
Hora;
Total Memoria (Mb)
Memoria Utilizada (Mb)
Memoria Livre (Mb)
Total Swap (Mb)
Swap Utilizado (Mb)
Swap Livre (Mb)
CPU Livre
CPU USER
CPU SYSTEM
Transac P/Seg Disco
Total de Arqs em Aberto
Total de Inodes Utilizados
Tempo do Servidor Ligado
Formato do arquivo de saída: CSV com (;) separando os campos
#!/bin/bash # # Script : /usr/local/scripts/coleta_performance.sh # Feito : Hertz S. ( 11/04/2016 ) # Obs : Script para coleta de informacoes de performance # e gera dados estatisticos em arquivo # #exec 1>/dev/null #exec 2>&1 # # Rotina de Inclusao de Variaveis Globais ------------------------------------- # PROCESS_NAME="Coleta de Informacoes de Performance" export PATH=$PATH:/usr/bin SERVER="`hostname`" IP_LOCAL="`/sbin/ifconfig | grep \"cast\" | head -1 | awk '{print $2}' | cut -d\: -f2,2`" DT_FULL="`date +%d/%m/%Y`" DT_DT="`date +%d%m%Y`" DT_HORA="`date +%H:%M:%S`" DT_HR="`date +%H%M%S`" DT_MES="`date +%m_%Y`" DT_ano="`date +%Y`" DT_mes="`date +%m`" DT_DIA="`date +%a`" if [ "${DT_DIA}" = "Sun" ] ; then DT_DIA="Domingo" ; fi if [ "${DT_DIA}" = "Mon" ] ; then DT_DIA="Segunda" ; fi if [ "${DT_DIA}" = "Tue" ] ; then DT_DIA="Terca" ; fi if [ "${DT_DIA}" = "Wed" ] ; then DT_DIA="Quarta" ; fi if [ "${DT_DIA}" = "Thu" ] ; then DT_DIA="Quinta" ; fi if [ "${DT_DIA}" = "Fri" ] ; then DT_DIA="Sexta" ; fi if [ "${DT_DIA}" = "Sat" ] ; then DT_DIA="Sabado" ; fi if [ "${DT_mes}" = "01" ] ; then DT_MES_NAME="Janeiro" ; fi if [ "${DT_mes}" = "02" ] ; then DT_MES_NAME="Fevereiro" ; fi if [ "${DT_mes}" = "03" ] ; then DT_MES_NAME="Marco" ; fi if [ "${DT_mes}" = "04" ] ; then DT_MES_NAME="Abril" ; fi if [ "${DT_mes}" = "05" ] ; then DT_MES_NAME="Maio" ; fi if [ "${DT_mes}" = "06" ] ; then DT_MES_NAME="Junho" ; fi if [ "${DT_mes}" = "07" ] ; then DT_MES_NAME="Julho" ; fi if [ "${DT_mes}" = "08" ] ; then DT_MES_NAME="Agosto" ; fi if [ "${DT_mes}" = "09" ] ; then DT_MES_NAME="Setembro" ; fi if [ "${DT_mes}" = "10" ] ; then DT_MES_NAME="Outubro" ; fi if [ "${DT_mes}" = "11" ] ; then DT_MES_NAME="Novembro" ; fi if [ "${DT_mes}" = "12" ] ; then DT_MES_NAME="Dezembro" ; fi # Declaracao de Variaveis ----------------------------------------------------- DIRCOL="/usr/local/coleta_`hostname`/performance/${DT_MES}" mkdir -p ${DIRCOL} # # Inicio do Script ------------------------------------------------------------ # # # Variavel de UPTIME da maquina : Tempo que ela esta ligada ------------------- # # # uptime # 17:13:29 up 8:11, 9 users, load average: 0.04, 0.08, 0.05 UPTIME="`uptime | cut -d\, -f1,1 | awk '{print $2,$3,$4,$5}'`" # # Descricao das Variaveis relacionadas abaixo --[ free -b ]-------------------- # # MEM_TOT --> Total de Memoria # MEM_USED --> Total de Memoria Utilizada # MEM_FREE --> Total de Memoria Livre # SWP_TOT --> Total de Swap # SWP_USED --> Total de Swap utilizado # SWP_FREE --> Total de Swap Livre # free -m > /tmp/tmp.$$ MEM_TOT="`cat /tmp/tmp.$$ | grep Mem | awk '{print $2}'`" MEM_USED="`cat /tmp/tmp.$$ | grep Mem | awk '{print $3}'`" MEM_FREE="`cat /tmp/tmp.$$ | grep Mem | awk '{print $4}'`" SWP_TOT="`cat /tmp/tmp.$$ | grep Swap | awk '{print $2}'`" SWP_USED="`cat /tmp/tmp.$$ | grep Swap | awk '{print $3}'`" SWP_FREE="`cat /tmp/tmp.$$ | grep Swap | awk '{print $4}'`" rm /tmp/tmp.$$ # # Descricao das Variaveis relacionadas abaixo --[ sar -u 1 3 ]----------------- # # CPU_IDLE --> Porcentagem de Utilizacao de CPU # CPU_USER --> Porcentagem de Utilizacao de USER LEVEL ( Aplicacao ) # CPU_SYST --> Porcentagem de Utilizacao de SYSTEM LEVEL ( Kernel ) # sar -u 1 3 | tail -1 > /tmp/tmp.$$ CPU_IDLE="`cat /tmp/tmp.$$ | awk '{print $8}'`" CPU_USER="`cat /tmp/tmp.$$ | awk '{print $3}'`" CPU_SYST="`cat /tmp/tmp.$$ | awk '{print $5}'`" rm /tmp/tmp.$$ # # Descricao das Variaveis relacionadas abaixo --[ sar -b 1 3 ]----------------- # # DSK_TPS --> Total de Transferencias por segundo em disco # sar -b 1 3 | tail -1 > /tmp/tmp.$$ DSK_TPS="`cat /tmp/tmp.$$ | awk '{print $2}'`" rm /tmp/tmp.$$ # # Descricao das Variaveis relacionadas abaixo --[ sar -v 1 3 ]----------------- # # FILE_SZ --> Total de Arquivos Abertos # INODE_SZ --> Total de Inodes Utilizados # sar -v 1 3 | tail -1 > /tmp/tmp.$$ FILE_SZ="`cat /tmp/tmp.$$ | awk '{print $3}'`" INODE_SZ="`cat /tmp/tmp.$$ | awk '{print $4}'`" rm /tmp/tmp.$$ # # Criacao do Arquivo de Coleta de Performance --------------------------------- # MEM_TOT_X="Total Memoria (Mb)" #--> 01 MEM_USED_X="Memoria Utilizada (Mb)" #--> 02 MEM_FREE_X="Memoria Livre (Mb)" #--> 03 SWP_TOT_X="Total Swap (Mb)" #--> 04 SWP_USED_X="Swap Utilizado (Mb)" #--> 05 SWP_FREE_X="Swap Livre (Mb)" #--> 06 CPU_IDLE_X="CPU Livre" #--> 07 CPU_USER_X="CPU USER" #--> 08 CPU_SYST_X="CPU SYSTEM" #--> 09 DSK_TPS_X="Transac P/Seg Disco" #--> 10 FILE_SZ_X="Total de Arqs em Aberto" #--> 11 INODE_SZ_X="Total de Inodes Utilizados" #--> 12 UPTIME_X="Tempo do Servidor Ligado" #--> 13 # # Descomentar estas linhas para Debug ----------------------------------------- # # echo " MEM_TOT --> $MEM_TOT" # echo "MEM_USED --> $MEM_USED" # echo "MEM_FREE --> $MEM_FREE" # echo " SWP_TOT --> $SWP_TOT" # echo "SWP_USED --> $SWP_USED" # echo "SWP_FREE --> $SWP_FREE" # echo "CPU_IDLE --> $CPU_IDLE" # echo "CPU_USER --> $CPU_USER" # echo "CPU_SYST --> $CPU_SYST" # echo " DSK_TPS --> $DSK_TPS" # echo " FILE_SZ --> $FILE_SZ" # echo "INODE_SZ --> $INODE_SZ" # # Gravacao dos Dados da Coleta em Arquivo ------------------------------------- # PERFTXT="${DIRCOL}/${DT_DT}.txt" if [ -f ${PERFTXT} ] then echo $PERFTXT existe > /dev/null echo "${DT_FULL};${DT_HORA};${MEM_TOT};${MEM_USED};${MEM_FREE};${SWP_TOT};${SWP_USED};${SWP_FREE};${CPU_IDLE};${CPU_USER};${CPU_SYST};${DSK_TPS};${FILE_SZ};${INODE_SZ};${UPTIME}" >> ${PERFTXT} else echo $PERFTXT nao > /dev/null echo "[ ${SERVER} ${IP_LOCAL} ] - ${DT_MES_NAME} de ${DT_ano}" > ${PERFTXT} echo "" >> ${PERFTXT} echo "Data;Hora;${MEM_TOT_X};${MEM_USED_X};${MEM_FREE_X};${SWP_TOT_X};${SWP_USED_X};${SWP_FREE_X};${CPU_IDLE_X};${CPU_USER_X};${CPU_SYST_X};${DSK_TPS_X};${FILE_SZ_X};${INODE_SZ_X};${UPTIME_X}" >> ${PERFTXT} echo "${DT_FULL};${DT_HORA};${MEM_TOT};${MEM_USED};${MEM_FREE};${SWP_TOT};${SWP_USED};${SWP_FREE};${CPU_IDLE};${CPU_USER};${CPU_SYST};${DSK_TPS};${FILE_SZ};${INODE_SZ};${UPTIME}" >> ${PERFTXT} fi # # Final do Script ------------------------------------------------------------ #
Compilação do kernel linux-libre 4.4.6 com cflags -march=native + -Ofast
Instalar o Unity 3D Web Player Automatizado
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Título: Descobrindo o IP externo da VPN no Linux
Armazenando a senha de sua carteira Bitcoin de forma segura no Linux
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Instalando Brave Browser no Linux Mint 22
vídeo pra quem quer saber como funciona Proteção de Memória:
Encontre seus arquivos facilmente com o Drill
Mouse Logitech MX Ergo Advanced Wireless Trackball no Linux
Compartilhamento de Rede com samba em modo Público/Anônimo de forma simples, rápido e fácil
Programa duplicado no "Abrir com" e na barra de pesquisa do ... (1)
VMs e Interfaces de Rede desapareceram (13)
Como abrir o pycharm no linux [RESOLVIDO] (4)