Vnstat delete and remove network interface

I installed vnstat and it is working great as per this page https://www.cyberciti.biz/faq/ubuntu-install-vnstat-console-network-traffic-monitor/ How can I remove and delete interface name such as veth54018b55? Example:

                      rx      /      tx      /     total    /   estimated
 eth0:
       2020-08     13.94 GiB  /    8.88 GiB  /   22.82 GiB
       2020-09      8.31 GiB  /    5.88 GiB  /   14.20 GiB  /   18.92 GiB
     yesterday    364.85 MiB  /  232.03 MiB  /  596.88 MiB
         today    242.94 MiB  /  126.53 MiB  /  369.47 MiB  /  723.85 MiB

 veth54018b55 [disabled]:
       2020-06      3.98 MiB  /   79.66 MiB  /   83.64 MiB  /  103.82 MiB

 veth615aa727 [disabled]:
       2020-06    470.19 KiB  /   51.36 MiB  /   51.81 MiB  /   61.80 MiB

 vethb9b0f32c [disabled]:
       2020-06     78.11 KiB  /  100.43 KiB  /  178.54 KiB  /     --     

As per vnstat --longhelp | egrep 'remove|delete' you need to use the --remove option. To delete and remove network interface permanently:

vnstat  --remove -i veth54018b55 

You might see

The current option would remove all data
about interface "veth54018b55" from the database.
Use --force in order to really do that.

Hence, pass the --force option.

vnstat  --remove -i veth54018b55 --force
1 Like

This solves my problem as Linux containers created many such interfaces and those changes upon reboot. I ended up running a little hackjob on my Ubuntu cloud server :stuck_out_tongue:

# remove all disabled vnstat interfaces from sqlite database
disabled=$(vnstat | grep -w '\[disabled\]:' | awk '{ print $1}')
for n in $disabled
do
  vnstat  --remove -i "$n" --force
done

I confirmed it by running vnstat again:

vnstat
                      rx      /      tx      /     total    /   estimated
 eth0:
       2020-08     13.94 GiB  /    8.88 GiB  /   22.82 GiB
       2020-09      8.31 GiB  /    5.88 GiB  /   14.20 GiB  /   18.92 GiB
     yesterday    364.85 MiB  /  232.03 MiB  /  596.88 MiB
         today    243.20 MiB  /  126.85 MiB  /  370.06 MiB  /  720.11 MiB

PS: No need to restart the vnstat service.


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki