Raspberry Pi

Monitor Network Traffic using Darkstat on Raspberry Pi

Darkstat is a lightweight Linux-based, real-time network traffic utility that runs in the background to capture your network traffic and calculate statistics on the go. It uses the web interface where you will be able to see your network traffic in the form of graphs. You will find information about your network traffic in minutes, hours, days, and months.

If you want to turn your device into a network monitoring device, you should need the services of Darkstat and this article presents an easy guide to installing this application on your Raspberry Pi device.

Install Darkstat on Raspberry Pi

The Darkstat repository is already included in the official repository list of Raspberry Pi; thus, it is easier for you to install it directly on your device. However, before the installation, you must update the packages on your system using the following command:

$ sudo apt update && sudo apt upgrade -y

After successfully updating the packages, use the following steps to complete the Darkstat installation:

Step 1: Install Darkstat on Raspberry Pi
To install Darkstat on Raspberry Pi, use the following command:

$ sudo apt install -y darkstat

After completing the installation, you can use the following command to confirm the latest version of Darkstat installed on your device.

$ darkstat --version

Step 2: Open Darkstat Configuration File
Now, open the Darkstat configuration file on Raspberry Pi via following command:

$ sudo nano /etc/darkstat/init.cfg

Inside the file, you will find two options as highlighted in the image below:

You must turn on the Darkstat service on your Raspberry Pi by relacing “no” with “yes”. Further, you will need to change the interface option in case you use the WIFI connection. If you don’t know your device’s WIFI interface, execute the following command to find out the wireless interface.

$ iwconfig

From the above command, you will see your wireless interface, which is “wlan0” in our case. You should change the interface accordingly and once it’s done save this file using “CTRL+X”, add Y and press enter to exit.

Step 3: Restart the Darkstat service on Raspberry Pi
Once you make the changes, restart the Darkstat service on your device using the following command:

$ sudo systemctl restart darkstat

After restarting the services, ensure that Darkstat is running with “active (running)” status using the following command:

$ sudo systemctl status darkstat

Step 4: Access Darkstat Web Interface on Raspberry Pi
After ensuring the Darkstat service is active on your device, you can access its web interface using the Raspberry Pi IP address, which you can find through the “hostname -I” command in the terminal.

Once the host address is known, you can use the address “http://hostaddress:667” on your browser to open the Darkstat web interface.

At the above web interface, you can see your network traffic of different timings and it ensures that you have successfully set up the Darkstat service on your Raspberry Pi device.

Removing Darkstat on Raspberry Pi

To remove Darkstat on Raspberry Pi, you should execute the following command:

$ sudo apt purge --autoremove -y darkstat

The above command will remove the application on your Raspberry Pi device; however, it doesn’t remove the “/var/lib/darkstat” folder from your device. To remove it, you will need to execute the following command:

$ sudo rm -rf /var/lib/darkstat

Conclusion

Darkstat is a cross-platform tool used for monitoring the network traffic on Linux-based systems. You can easily install this application on your Raspberry Pi device through the steps mentioned above that require a direct installation command and some changes in the configuration file to make it accessible on your system browser using the device’s IP address.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.