[LINUX] Simple traffic monitor on CentOS

Hello.

A while ago, I had the opportunity to try the platform itself and the virtual load balancer on the SDN / NFV platform, and I thought it would be uninteresting to just capture how the traffic was relayed and balanced, so it's just for viewing. I made a simple traffic monitor on CentOS 6.x.

Actually, I just refer to the interface statistics file (text) under / sys / class / net every second and update the screen with ncurses, but when I actually flow traffic, I can monitor it as it is (traffic) It feels like it's flowing), so it's interesting.

The file you are looking at

I'm looking at the files around here. There are many other collisions, so it's a good idea to take a look at the directory. Replace "eth0" with your interface name. These files simply contain numbers such as the number of packets and the number of bytes.

/sys/class/net/eth0/statistics/rx_packets
/sys/class/net/eth0/statistics/rx_bytes
/sys/class/net/eth0/statistics/rx_errors
/sys/class/net/eth0/statistics/rx_dropped
/sys/class/net/eth0/statistics/tx_packets
/sys/class/net/eth0/statistics/tx_bytes
/sys/class/net/eth0/statistics/tx_errors
/sys/class/net/eth0/statistics/tx_dropped

Like this

It's not "modern" because I used ncurses on the assumption that it will be viewed on the console from Horizon of OpenStack.

monitor_screen_shot.png

[Bonus] L2 transparent

Although it deviates from the main subject, I wanted to imitate L2 transparent VNF (Virtual Network Function) for testing on the NFV platform, and I connected the left and right interfaces with a Linux bridge on Linux that runs this monitor, so I hit the command Make a note of it. The "brvnf" below is an optional bridge name. In the example below, it is connected to [eth1-brvnf-eth2] to operate transparently.

  brctl addbr brvnf
  brctl addif brvnf eth1
  brctl addif brvnf eth2
  ifconfig brvnf up

Summary

At first glance, the traffic monitor may seem cumbersome to implement, but on Linux you can easily refer to these files. Since it is plain text, it can be easily handled by shell scripts.

The entire source is posted here (github) [https://github.com/msozawa/simple-tools/tree/master/simple_tra_mon), so feel free to take it if you are interested.

Well then.

Recommended Posts

Simple traffic monitor on CentOS
Monitor traffic on Linux
Install numba on CentOS 7.2
Install Python3.4 on CentOS 6.6
Install mecab-python on CentOS
Install Python 2.7.3 on CentOS 5.4
Installation on CentOS8 VirtualBox
Install awscli on centos7
Install Chainer on CentOS 6.7
Torque setup on CentOS 6
Setting up grub on CentOS 8
Until docker-compose up on CentOS7
Implemented retina net on CentOS
Anaconda environment construction on CentOS7
Monitor disk usage on Linux
Install ImageMagick-6.2.x series on CentOS7.7
Install Python 3.8 on CentOS 7 (SCL)
Apache installation fails on CentOS 8.2
Install Chrome on CentOS 7 series
Install Python 3.8 on CentOS 8 (AppStream)
Notes on installing Python on CentOS
Steps to deploy EMLauncher on CentOS 8
raspberry pi 4 centos7 install on docker
Steps to install VirtualBox on CentOS
Install java (Oracle JDK14) on CentOS7
[Linux] I installed CentOS on VirtualBox
How to install PyPy on CentOS
How to install TensorFlow on CentOS 7
Install pip on CentOS7. Also iPython.
Create a python environment on centos
Install VirtualBox on CentOS 7 on VirtualBox (mac + vagrant)
Install Python on CentOS using Pyenv
How to install Maven on CentOS
Build a python3 environment on CentOS7
Study Note 9_Install Jenkins on CentOS7
Install Python on CentOS using pyenv