개발자의 노트
반응형

vnstat 설치


# yum install -y vnstat


60초 동안 테스트를 수행하며 이상이 없는지 확인합니다. 

체크 결과 Everything is ok.가 나왔다면 바로 문제없이 사용할 수 있습니다


# vnstat --testkernel


사용할 수 있는 네트워크 인터페이스를 확인할 수 있습니다.


# vnstat --iflist

Available interfaces: lo usb0 eth0 eth1 eth2 eth3 bond0 virbr0 virbr0-nic


아래 명령어를 통해 기록을 위한 새로운 데이터베이스 파일을 생성합니다. 

저장 경로는 /var/lib/vnstat/eth0 으로 설정됩니다.


# vnstat -u -i eth0


서버가 bonding 되어있다면 bond된 인터페이스를 잡자.


# vnstat -u -i bond0


부팅시 자동 실행 설정


# chkconfig vnstat on


서비스 시작, 중지 등


# service vnstat start

# service vnstat stop

# service vnstat restart

# service vnstat status


 

실시간으로 트래픽을 모니터링할 수 있습니다. (-i 옵션은 인터페이스 선택, 기본은 eth0)


# vnstat -l -i bond0


그래프 형태로 상세 모니터링 내역을 보여줍니다.


# vnstat -h -i bond0


일별 사용량을 출력해줍니다.


# vnstat -d -i bond0


자세한 옵션 설명은 --help


# vnstat --help


-h, -d 옵션은 vnstat -u 명령어로 네트워크 트래픽 정보를 업데이트 해 줘야만 사용할 수 있습니다. 

일반적으로 해당 명령어를 크론에 등록하여 수행합니다.


# crontab -e


*/5 * * * * usr/bin/vnstat -u -i eth0

*/5 * * * * usr/bin/vnstat -u -i bond0



=================


(소스 설치는 아래 참조)


# wget http://humdi.net/vnstat/vnstat-1.17.tar.gz

# tar xvf vnstat-1.17.tar.gz

# cd vnstat-1.17

# ./configure

# make && make install

# which vnstat

/usr/local/bin/vnstat

# ln -s /usr/local/bin/vnstat /usr/bin/vnstat

# mkdir /var/lib/vnstat

# vi /etc/init.d/vnstat

아래 쉘 스크립트 저장

-----------------------------------------------------

#!/bin/sh

#

# chkconfig: 123 69 68

# description: vnstat

. /etc/init.d/functions

#

if [ -f /etc/sysconfig/vnstat ]; then

. /etc/sysconfig/vnstat

fi

case "$1" in

start)

echo -n "Start service vnstat"

/usr/sbin/vnstat start

;;

stop)

echo -n "Stop service vnstat"

/usr/sbin/vnstat stop

;;

restart)

echo -n "Restart service vnstat"

/usr/sbin/vnstat restart

;;

*)

echo "Usage: $0 {start|stop|restart}"

exit 1

;;

esac

-----------------------------------------------------

# chkconfig --add vnstat


profile

개발자의 노트

@곽코딩

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!