ifconfig를 매시간 실행할 때 전송된 RX/TX 바이트에 대한 카운터가 재설정되는 것을 확인했습니다.
RX 바이트: 921640934(921.6MB) TX 바이트: 4001470884(4.0GB)
어떻게요? 매일 전송하는 데이터의 양을 추적하고 싶지만 계속 재설정됩니다.
답변1
나는 Shunz 씨의 대답이 정확하다고 생각합니다. 그러나 모든 희망이 사라지지는 않습니다. 하루 이체 금액을 계산하는 데 관심이 있는 경우 다음을 고려해 보세요.통계자료.
답변2
카운터는 32비트 정수인 것처럼 보이므로 약 4GB를 "감싸"게 됩니다.
답변3
문제는 확실히 위에 제공된 32비트 정수 답변입니다. 나는 같은 문제를 가지고있다. 이를 실행할 수 있는 프로세서에 설치된 운영 체제와 관련이 있습니다.
64비트 프로세서에서 32비트 운영 체제를 실행하는 경우에도 4Gb로 제한됩니다.
2^32 = 4294967296
4294967296/1024/1024/1024 = 4
저는 제(32비트) 파일 서버가 전송 중인 많은 테라바이트를 추적할 수 없다는 사실에 정말 실망했습니다. 그래서 데이터 사용량(eth0 및 wlan0)을 추적하기 위한 작은 스크립트를 만들었습니다.
getstats.sh
눕다/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
이렇게 하면 시스템 디렉터리에 많은 파일이 생성되지만 실제 총계는 다음 파일에 있습니다.
/usr/local/bin/system/rx_running
는 eth0에 다운로드된 총 바이트 수
/usr/local/bin/system/tx_running
, 는 eth0에 업로드된 총 바이트 수
/usr/local/bin/system/wlan_rx_running
, 는 wlan0에 다운로드된 총 바이트 수
/usr/local/bin/system/wlan_tx_running
, 는 wlan0에 업로드된 총 바이트 수입니다.
물론 이러한 값을 자동으로 업데이트하고 싶을 것입니다. 따라서 정기적으로 스크립트를 실행하는 것이 좋습니다 cron
.* * * * * chronic /usr/local/bin/system/getStats.sh
그런 다음 로드 평균, CPU 온도, 메모리 사용량 등을 포함한 다른 통계를 얻고 RRDTool
.
이 그래프는 32비트 운영 체제(Jessie를 실행하는 Raspberry Pi)가 여전히 4GB 이상의 사용 가능한 전송 데이터를 제공할 수 있음을 보여줍니다.
PS는 오류가 발생하지 않는 한 아무것도 출력하지 않는 명령을 실행할 수 있는 chronic
패키지의 일부입니다 .moreutils