Pular para o conteúdo

Monitorar status de transferência das interfaces de rede

Sem ter muito o que fazer por hoje :P, escrevi esse Shell Script básico que mostra o status de consumo das interfaces de rede em tempo real no terminal! Não é lá essas coisas, mas o que tá valendo é a intenção... :)

P.S.: melhorias serão bem-vindas.
Sandro Marcell smarcell
Hits: 6.952 Categoria: Shell Script Subcategoria: Avançado
  • Download
  • Nova versão
  • Indicar
  • Denunciar
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Descrição

Sem ter muito o que fazer por hoje :P, escrevi esse Shell Script básico que mostra o status de consumo das interfaces de rede em tempo real no terminal! Não é lá essas coisas, mas o que tá valendo é a intenção... :)

P.S.: melhorias serão bem-vindas.
Download bwd_meter Enviar nova versão
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Versões atualizadas deste script

Esconder código-fonte

#!/bin/bash
#
# Copyright 2013 Sandro Marcell <smarcell@myopera.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
PATH='/bin:/usr/bin:/usr/local/bin'

trap 'echo -ne "\033[?12l\033[?25h"; exit 0' SIGINT SIGTERM SIGQUIT

[ $# -eq 0 ] && { echo "Usage: $0 -u K|M|G -i interface"; exit 1; }

unit='xxx'
iface='yyy'

while [ $# -ne 0 ]; do
    case "$1" in
        '-u')
            shift
            unit="$1"
            ;;
        '-i')
            shift
            iface="$1"
            ;;
        *)
            echo "Usage: $0 -u K|M|G -i interface"
            exit 1
    esac
    shift
done

echo "$unit" | grep -q '\(K\|M\|G\)' || { echo "Use only K(ilo), M(ega) or G(iga)"; exit 1; }
if [ ! -d "/sys/class/net/$iface" ]; then
    echo "$iface: interface not found"
    exit 1
fi

function bandwidthCalc {
    if [ "$1" == 'K' ]; then
        echo "scale = 2; $bytes_diff / 128" | bc
    elif [ "$1" == 'M' ]; then
        echo "scale = 2; $bytes_diff * 8 / 1048576" | bc
    elif [ "$1" == 'G' ]; then
        echo "scale = 2; $bytes_diff * 8 / 1073741824" | bc
    fi
}

echo -ne "\033[?25l"

while true; do
    exec 3< /sys/class/net/$iface/statistics/rx_bytes; read -u 3 rx_1; exec 3<&-
    sleep 1
    exec 3< /sys/class/net/$iface/statistics/rx_bytes; read -u 3 rx_2; exec 3<&-

    (( bytes_diff = rx_2 - rx_1 ))
    rx_bwd=$(bandwidthCalc $unit)
    echo -ne "$iface: transfer rate - \033[1;33m$rx_bwd\033[00m ${unit}bit/s\033[0K\r"
done
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Download do banco de dados NCBI NR (DNA)

SSH manager

mountcp1.sh

Configuração de failover de links de internet

Clientes TCP

#1 Comentário enviado por phoemur em 18/09/2013 - 13:08h
Cara, muito legal esse script
#2 Comentário enviado por viniciusraupp em 18/09/2013 - 15:05h
Legal, ta funcionado o/
#3 Comentário enviado por cesar em 20/09/2013 - 08:57h
Perfeito, estava precisando de alguma desse tipo!

Valeu!

Contribuir com comentário

Entre na sua conta para comentar.