Shomehow os contadores rx / tx na interface são redefinidos

2

Ao fazer ifconfig de hora a hora, percebo que os contadores de bytes RX / TX transferem as redefinições:

bytes RX: 921640934 (921,6 MB) bytes TX: 4001470884 (4,0 GB)

Como assim? Gostaria de acompanhar quantos dados são transferidos do dia para dia, mas eles continuam sendo redefinidos.

    
por jonasl 23.10.2010 / 21:22

3 respostas

3

Parece que os contadores são inteiros de 32 bits, então eles "envolvem" a ~ 4 GB.

    
por 23.10.2010 / 22:30
4

Eu acredito que a resposta de MrShunz está correta. No entanto, nem toda a esperança está perdida. Se você estiver interessado em manter estatísticas sobre quanto você transfere todos os dias, considere vnstat .

    
por 24.10.2010 / 00:02
2

O problema é definitivamente a resposta de inteiro de 32 bits fornecida acima. Eu tive o mesmo problema. Está relacionado ao sistema operacional instalado no processador que pode executá-lo.

Se você estiver executando um O / S de 32 bits em um processador de 64 bits, também estará limitado ao limite de 4 Gb. 2 ^ 32 = 4294967296
4294967296/1024/1024/1024 = 4

Eu fiquei realmente frustrado com o fato de meu servidor de arquivos (32 bits) não conseguir controlar os muitos Terabytes que ele estava transferindo, então eu criei um pequeno script para acompanhar o uso de dados para ele (eth0 e wlan0 ):

getstats.sh está localizado em /usr/local/bin/system/

#! /bin/bash

# CHECK FOR FILE IN /USR/LOCAL/BIN/SYSTEM
#       COPY ACTUAL FILES TO MAINTAIN DATA CONSISTENCY DURING CALCULATIONS
        cp /sys/class/net/eth0/statistics/rx_bytes /usr/local/bin/system/rx_actual
        cp /sys/class/net/eth0/statistics/tx_bytes /usr/local/bin/system/tx_actual
        cp /sys/class/net/wlan0/statistics/rx_bytes /usr/local/bin/system/wlan_rx_actual
        cp /sys/class/net/wlan0/statistics/tx_bytes /usr/local/bin/system/wlan_tx_actual

#       BYTES FILES
if [ ! -e /usr/local/bin/system/rx_bytes ]; then                            # IF RX_BYTES DOESN'T EXIST
        cp /usr/local/bin/system/rx_actual /usr/local/bin/system/rx_bytes   # MAKE A NEW COPY FROM THE ACTUAL FILE
else
    mv /usr/local/bin/system/rx_bytes /usr/local/bin/system/rx_bytes_old    # IF IT DOES EXIST, RENAME IT
        cp /usr/local/bin/system/rx_actual /usr/local/bin/system/rx_bytes   # AND COPY IN A NEW ONE
fi
if [ ! -e /usr/local/bin/system/tx_bytes ]; then                            # REPEAT THIS FOR TX_BYTES
        cp /usr/local/bin/system/tx_actual /usr/local/bin/system/tx_bytes
else
    mv /usr/local/bin/system/tx_bytes /usr/local/bin/system/tx_bytes_old
        cp /usr/local/bin/system/tx_actual /usr/local/bin/system/tx_bytes
fi

#       BYTES FILES (WLAN0)
if [ ! -e /usr/local/bin/system/wlan_rx_bytes ]; then                                     # IF RX_BYTES DOESN'T EXIST
        cp /usr/local/bin/system/wlan_rx_actual /usr/local/bin/system/wlan_rx_bytes       # MAKE A NEW COPY FROM THE ACTUAL FILE
else
        mv /usr/local/bin/system/wlan_rx_bytes /usr/local/bin/system/wlan_rx_bytes_old    # IF IT DOES EXIST, RENAME IT
        cp /usr/local/bin/system/wlan_rx_actual /usr/local/bin/system/wlan_rx_bytes       # AND COPY IN A NEW ONE
fi
if [ ! -e /usr/local/bin/system/wlan_tx_bytes ]; then                                     # REPEAT THIS FOR TX_BYTES
        cp /usr/local/bin/system/wlan_tx_actual /usr/local/bin/system/wlan_tx_bytes
else
        mv /usr/local/bin/system/wlan_tx_bytes /usr/local/bin/system/wlan_tx_bytes_old
        cp /usr/local/bin/system/wlan_tx_actual /usr/local/bin/system/wlan_tx_bytes
fi

#       RUNNING TOTAL FILES
if [ ! -e /usr/local/bin/system/rx_running ]; then
    cp /usr/local/bin/system/rx_bytes /usr/local/bin/system/rx_running
fi
if [ ! -e /usr/local/bin/system/tx_running ]; then
        cp /usr/local/bin/system/tx_bytes /usr/local/bin/system/tx_running
fi

#       RUNNING TOTAL FILES (WLAN0)
if [ ! -e /usr/local/bin/system/wlan_rx_running ]; then
        cp /usr/local/bin/system/wlan_rx_bytes /usr/local/bin/system/wlan_rx_running
fi
if [ ! -e /usr/local/bin/system/wlan_tx_running ]; then
        cp /usr/local/bin/system/wlan_tx_bytes /usr/local/bin/system/wlan_tx_running
fi

#       OLD FILES
if [ ! -e /usr/local/bin/system/rx_bytes_old ]; then
        cp /usr/local/bin/system/rx_bytes /usr/local/bin/system/rx_bytes_old
fi
if [ ! -e /usr/local/bin/system/tx_bytes_old ]; then
        cp /usr/local/bin/system/tx_bytes /usr/local/bin/system/tx_bytes_old
fi

#       OLD FILES (WLAN0)
if [ ! -e /usr/local/bin/system/wlan_rx_bytes_old ]; then
        cp /usr/local/bin/system/wlan_rx_bytes /usr/local/bin/system/wlan_rx_bytes_old
fi
if [ ! -e /usr/local/bin/system/wlan_tx_bytes_old ]; then
        cp /usr/local/bin/system/wlan_tx_bytes /usr/local/bin/system/wlan_tx_bytes_old
fi


# SET VARIABLES FOR CALCULATION
OLDRX='cat /usr/local/bin/system/rx_bytes_old'
NEWRX='cat /usr/local/bin/system/rx_bytes'
RUNRX='cat /usr/local/bin/system/rx_running'
OLDTX='cat /usr/local/bin/system/tx_bytes_old'
NEWTX='cat /usr/local/bin/system/tx_bytes'
RUNTX='cat /usr/local/bin/system/tx_running'
OLDWRX='cat /usr/local/bin/system/wlan_rx_bytes_old'
NEWWRX='cat /usr/local/bin/system/wlan_rx_bytes'
RUNWRX='cat /usr/local/bin/system/wlan_rx_running'
OLDWTX='cat /usr/local/bin/system/wlan_tx_bytes_old'
NEWWTX='cat /usr/local/bin/system/wlan_tx_bytes'
RUNWTX='cat /usr/local/bin/system/wlan_tx_running'
MAX=4294967296

# COMPARE AND DO MATH
if [ $NEWRX -lt $OLDRX ]; then                         # IF NEW VALUE IS LESS THAN OLD VALUE (max reached and LOOPED AROUND)
        TOPRX='expr $MAX - $OLDRX'                             # SUBTRACT THE OLD VALUE FROM THE MAX VALUE
        USERX='expr $TOPRX + $RUNRX'                           # ADD IT TO RUNNING TOTAL
        $USERX='expr $USERX + $NEWRX'                          # ADD THAT TO THE NEW VALUE
        echo $USERX > /usr/local/bin/system/rx_running         # OUTPUT THAT TO THE NEW RUNNING TOTAL
else                                                   # OTHERWISE (it hasn't looped around)
        TOPRX='expr $NEWRX - $OLDRX'                           # SUBTRACT THE OLD VALUE FROM THE NEW
        USERX='expr $RUNRX + $TOPRX'                           # ADD IT TO THE RUNNING VALUE
        echo $USERX > /usr/local/bin/system/rx_running         # OUTPUT THAT TO THE NEW RUNNING TOTAL
fi
if [ $NEWTX -lt $OLDTX ]; then                         # REPEAT ABOVE FOR UPLOADS
        TOPTX='expr $MAX - $OLDTX'
        USETX='expr $TOPTX + $RUNTX'
        $USETX='expr $USETX + $NEWTX'
        echo $USETX > /usr/local/bin/system/tx_running
else
        TOPTX='expr $NEWTX - $OLDTX'
        USETX='expr $RUNTX + $TOPTX'
        echo $USETX > /usr/local/bin/system/tx_running
fi
 #COMPARE AND DO MATH (WLAN0)
if [ $NEWWRX -lt $OLDWRX ]; then                         # IF NEW VALUE IS LESS THAN OLD VALUE (max reached and LOOPED AROUND)
        TOPWRX='expr $MAX - $OLDWRX'                             # SUBTRACT THE OLD VALUE FROM THE MAX VALUE
        USEWRX='expr $TOPWRX + $RUNWRX'                           # ADD IT TO RUNNING TOTAL
        $USEWRX='expr $USEWRX + $NEWWRX'                          # ADD THAT TO THE NEW VALUE
        echo $USEWRX > /usr/local/bin/system/wlan_rx_running         # OUTPUT THAT TO THE NEW RUNNING TOTAL
else                                                     # OTHERWISE (it hasn't looped around)
        TOPWRX='expr $NEWWRX - $OLDWRX'                           # SUBTRACT THE OLD VALUE FROM THE NEW
        USEWRX='expr $RUNWRX + $TOPWRX'                           # ADD IT TO THE RUNNING VALUE
        echo $USEWRX > /usr/local/bin/system/wlan_rx_running         # OUTPUT THAT TO THE NEW RUNNING TOTAL
fi
if [ $NEWWTX -lt $OLDWTX ]; then                         # REPEAT ABOVE FOR UPLOADS
        TOPWTX='expr $MAX - $OLDWTX'
        USEWTX='expr $TOPWTX + $RUNWTX'
        $USEWTX='expr $USEWTX + $NEWWTX'
        echo $USEWTX > /usr/local/bin/system/wlan_tx_running
else
        TOPWTX='expr $NEWWTX - $OLDWTX'
        USEWTX='expr $RUNWTX + $TOPWTX'
        echo $USEWTX > /usr/local/bin/system/wlan_tx_running
fi

Isso criará vários arquivos no diretório do sistema, no entanto, os totais reais estarão localizados nos seguintes arquivos:

/usr/local/bin/system/rx_running é o total de bytes baixados em eth0
/usr/local/bin/system/tx_running é o total de bytes enviados em eth0
/usr/local/bin/system/wlan_rx_running é o total de bytes baixados em wlan0
/usr/local/bin/system/wlan_tx_running é o total de bytes enviados em wlan0

Naturalmente, você desejará atualizar esses valores automaticamente. Então, eu recomendo executar o script periodicamente (eu faço o meu uma vez por minuto usando cron com * * * * * chronic /usr/local/bin/system/getStats.sh

Depois disso, fui atrás de outras estatísticas, incluindo médias de carga, temperaturas da CPU, uso da memória, etc., e as imprimi em gráficos usando RRDTool .

Este gráfico demonstra o fato de que um sistema operacional de 32 bits (raspberry Pi2 rodando Jessie) ainda pode fornecer dados transferíveis utilizáveis que são maiores que o 4Gb:

P.S. chronic é uma parte do pacote moreutils que permite que você execute um comando que não produzirá nada a menos que haja um erro.

    
por 07.07.2016 / 11:51