NethogsAnalyzer

Nethogs analyzer

Go/Golang Script Networking

Task

As part of my research at Sophia university (上智大学) I had to create a script that would help me create network traffic data needed to create analysis of how much data each application running on the Linux server was taking up.

Full paper available

Solution

I decided to create a simple script in Go, which would take in the raw text data generated by Nethogs (available here) and streamed into a text file using the sed text editor with the following command:


     sudo nethogs -t -d 1 | sed 's/[^[:print:][:cntrl:]]//g' > in.txt
        

The script takes in the .txt file and transforms it into a .csv file which can later be used in programs such as LibreOffice Spreadsheet or Excel for further processing or visualization. As Nethogs with the above command is configured to take a snapshot every second, we get a per second frame of the network situation. The script can produce either a per process data file or a sum of all processes per second file.

Demo

The project is publicly available on GitHub here.

As a demonstration, please refer to the images below. The first image shows the .txt file created with Nethogs, which is the input for this script:

NethogsAnalyzer

After the processing, the script generates the following .csv file:

NethogsAnalyzer

Please feel free to take a look and try out the script!