Bug 15691 - Vnstat is not enabled when accounting is activated in draknetcenter
Summary: Vnstat is not enabled when accounting is activated in draknetcenter
Status: NEW
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: Cauldron
Hardware: x86_64 Linux
Priority: Normal major
Target Milestone: ---
Assignee: Thierry Vignaud
QA Contact:
URL:
Whiteboard: MGA8TOO
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-13 15:54 CEST by Jude Ashvin Lobo Shenoy
Modified: 2021-03-15 12:16 CET (History)
6 users (show)

See Also:
Source RPM: draknetcenter
CVE:
Status comment:


Attachments
Vnstat off now on system start. (158.35 KB, image/png)
2015-04-13 15:56 CEST, Jude Ashvin Lobo Shenoy
Details
Vnstat now on after i manually started the service. (158.90 KB, image/png)
2015-04-13 15:57 CEST, Jude Ashvin Lobo Shenoy
Details
My system details as shown by webmin. (158.74 KB, image/png)
2015-04-13 15:58 CEST, Jude Ashvin Lobo Shenoy
Details
Webmin shows vnstat service is enabled to start at boot. (221.33 KB, image/png)
2015-04-13 16:00 CEST, Jude Ashvin Lobo Shenoy
Details
Minimum data recorded. Webmin shows vnstat is on but MCC says it has stopped on boot. (743.63 KB, image/png)
2015-04-13 16:02 CEST, Jude Ashvin Lobo Shenoy
Details
Journalctl log. (10.76 KB, text/plain)
2015-04-14 03:09 CEST, Jude Ashvin Lobo Shenoy
Details
Journalctl log with more details. (74.01 KB, text/plain)
2015-04-14 16:08 CEST, Jude Ashvin Lobo Shenoy
Details
Script to update nics in /etc/vnstat.conf (634 bytes, text/plain)
2021-03-12 07:09 CET, Dave Hodgins
Details

Description Jude Ashvin Lobo Shenoy 2015-04-13 15:54:32 CEST
I noticed that vnstat has not saved data for the last 2 months. It has saved data only when i manually start the service in MCC. Actually when i got Mageia 5 cauldron installed i had started the service and configured it to stay on across boots. Have had this done through MCC as well as webmin. The attached pics would give you an idea of the issue. Had started the vnstat service this morning and now when i check it i see it's stopped and that means no recording. I have restarted it now. In webmin it shows vnstat as always on.
Comment 1 Jude Ashvin Lobo Shenoy 2015-04-13 15:56:05 CEST
Created attachment 6258 [details]
Vnstat off now on system start.

Vnstat shows as stopped in spite of being on.
Comment 2 Jude Ashvin Lobo Shenoy 2015-04-13 15:57:05 CEST
Created attachment 6259 [details]
Vnstat now on after i manually started the service.

Manually started the service.
Comment 3 Jude Ashvin Lobo Shenoy 2015-04-13 15:58:08 CEST
Created attachment 6260 [details]
My system details as shown by webmin.
Comment 4 Jude Ashvin Lobo Shenoy 2015-04-13 16:00:05 CEST
Created attachment 6261 [details]
Webmin shows vnstat service is enabled to start at boot.

In MCC it shows vnstat service has stopped and has to be manually started.
Comment 5 Jude Ashvin Lobo Shenoy 2015-04-13 16:02:10 CEST
Created attachment 6262 [details]
Minimum data recorded. Webmin shows vnstat is on but MCC says it has stopped on boot.

In the last 2 months i have downloaded roughly 50GB of data.
Comment 6 David Walser 2015-04-14 01:44:59 CEST
Do you have any logs that indicate what might be going on with the service?

For example, you could run "journalctl -u vnstat.service"
Comment 7 Jude Ashvin Lobo Shenoy 2015-04-14 03:08:25 CEST
Hi David,

Attaching journalctl details for you.
Comment 8 Jude Ashvin Lobo Shenoy 2015-04-14 03:09:03 CEST
Created attachment 6264 [details]
Journalctl log.
Comment 9 Jude Ashvin Lobo Shenoy 2015-04-14 03:25:25 CEST
More details as follows:

Contents of /usr/share/doc/vnstat/examples/systemd/vnstat.service -

[Unit]
Description=vnStat network traffic monitor
Documentation=man:vnstatd(1) man:vnstat(1) man:vnstat.conf(5)
After=network.target

[Service]
ExecStart=/usr/sbin/vnstatd -n
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------------
Contents of /usr/lib/systemd/system/vnstat.service

[Unit]
Description=vnStat - a lightweight network traffic monitor
After=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/vnstatd -d
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/vnstat.pid

[Install]
WantedBy=multi-user.target
----------------------------------------------------------------------
Contents of /etc/systemd/system/multi-user.target.wants/vnstat.service

[Unit]
Description=vnStat - a lightweight network traffic monitor
After=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/vnstatd -d
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/vnstat.pid

[Install]
WantedBy=multi-user.target
Comment 10 Jude Ashvin Lobo Shenoy 2015-04-14 03:36:57 CEST
Contents of /usr/share/doc/vnstat/examples/upstart/vnstat.conf

description "vnStat network traffic monitor"

start on runlevel [2345]
stop on runlevel [016] or deconfiguring-networking or unmounting-filesystem

exec vnstatd -n
Comment 11 Jude Ashvin Lobo Shenoy 2015-04-14 16:08:39 CEST
Created attachment 6267 [details]
Journalctl log with more details.
David Walser 2015-04-14 23:51:14 CEST

Attachment 6264 mime type: application/octet-stream => text/plain

David Walser 2015-04-14 23:51:23 CEST

Attachment 6267 mime type: application/octet-stream => text/plain

Comment 12 David Walser 2015-04-14 23:52:31 CEST
Ooh, it's being disabled due to an ordering cycle.  CC'ing Colin.

Summary: Vnstat does not start on bootup. => Vnstat does not start on bootup due to ordering cycle
CC: (none) => mageia

Samuel Verschelde 2015-06-06 01:36:24 CEST

Whiteboard: (none) => MGA5TOO

Comment 13 papoteur 2016-01-09 22:59:27 CET
It seems that vnstat.service is not enabled when accounting is activated in draknetcenter.
In cauldron/virtualbox, I have a network connection. vnstat service is not enabled. In netcenter, I configure it to enable traffic accounting, then restart the connection.
vnstat.service is not enabled after that, even after a reboot.
Papoteur

CC: (none) => yves.brungard_mageia

Comment 14 Jude Ashvin Lobo Shenoy 2016-01-11 11:49:56 CET
I got it to work by enabling it through the webmin console. After that it starts accounting.
papoteur 2016-01-12 08:01:19 CET

Assignee: bugsquad => thierry.vignaud
Summary: Vnstat does not start on bootup due to ordering cycle => Vnstat is not enabled when accounting is activated in draknetcenter
Source RPM: (none) => draknetcenter

Thierry Vignaud 2016-01-12 09:23:53 CET

CC: (none) => mageia

papoteur 2021-03-09 09:00:14 CET

Whiteboard: MGA5TOO => MGA8TOO

Comment 15 Johnny A. Solbu 2021-03-09 20:12:41 CET
(In reply to papoteur from comment #13)
> It seems that vnstat.service is not enabled when accounting is activated in
> draknetcenter.
> In cauldron/virtualbox, I have a network connection. vnstat service is not
> enabled. In netcenter, I configure it to enable traffic accounting, then
> restart the connection.
> vnstat.service is not enabled after that, even after a reboot.

A reboot will never enable a service.
Don't confuse Enable a service with Starting a service. There's a difference.

A disabled service will not be automatically started on boot.
A service can be stopped _and_ enabled at the same time, likewize can a service be started _and_ disabled at the same time.

«systemctl status vnstat.service» will show if vnstat is running, if it is enabled and what the default is; enabled or disabled.

On my mga7 system:
====
systemctl status vnstat.service |egrep 'Loaded|Active'
   Loaded: loaded (/usr/lib/systemd/system/vnstat.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-01-27 01:14:22 CET; 1 months 11 days ago
====
«vendor preset» is just the default.
If the command shows the service to be disabled it can be reenables with «systemctl enable vnstat.service»


So the question is: When accounting is activated, does that Disable (not stopping) vnstat?

One way to figure this out is to have «etckeeper» installed, check that all changes are committed and then enable accounting. (etckeeper will put the /etc folder in a local git repo.)
«git diff» will show if the file/symlink /etc/systemd/system/multi-user.target.wants/vnstat.service is removed uppon activating accounting. (Disabling a service will remove the «/etc/systemd/system/<...>/foo.service» file.)

CC: (none) => cooker

Comment 16 Nicolas Nicolas 2021-03-12 00:23:26 CET
Hello,

In fact i think the accounting should launch the action to enable or disable the vnstat service ( if it is asked to be enabled or not) and perhaps it is not the case currently.

Issue with that there is a need to check all interfaces configuration ( either adsl,ppp, ethernet, wireless, bluetooth, etc..), because if only one interface (and can be not the one being configured) is set for accounting the service should not be disabled should only be disabled if no interface is set for accounting).

I don't know if any Perl/Bash file is implementing something like that ( of course if not, it can be normal that it is not working ;-) )

CC: (none) => joe_c_moi

Comment 17 Dave Hodgins 2021-03-12 01:23:48 CET
Shouldn't be difficult to parse the output of "ip link" to get the device names.
In my Mageia 7 install I have ...
Interface "eth0+enp7s0+p32p1"
as it changes depending on kernel options selected, so ideally the script should
be added to vnstat as a script run by an ExecStart in the service file.

CC: (none) => davidwhodgins

Comment 18 Dave Hodgins 2021-03-12 01:28:24 CET
Or easier to parse with ls /sys/class/net, just removing the lo@ and the
trailing @ for each link name.
Comment 19 Dave Hodgins 2021-03-12 07:09:23 CET
Created attachment 12454 [details]
Script to update nics in /etc/vnstat.conf

Here's an example script that will add all current interfaces except lo to
/etc/vnstat.conf
Dave Hodgins 2021-03-12 07:11:15 CET

Attachment 12454 mime type: application/x-shellscript => text/plain

Comment 20 papoteur 2021-03-12 08:43:23 CET
Hi Dave, thank you for you contribution.
I don't think this is the way which is expected. drakconnectcenter includes a way to select accounting by interface.
See http://gitweb.mageia.org/software/drakx-net/tree/lib/network/connection.pm#n279
ACCOUNTING=yes is written in the config file for the interface. What is to do is to scan interface files and to check which ones have ACCOUNTING=yes
What I don't know is what can be the trigger of such a scan.
Comment 21 Johnny A. Solbu 2021-03-12 11:17:27 CET
(In reply to Dave Hodgins from comment #19)
> Created attachment 12454 [details]
> Script to update nics in /etc/vnstat.conf
> 
> Here's an example script that will add all current interfaces except lo to
> /etc/vnstat.conf

My gw is a Mageia system, which obviously have two network cards, but it only track the internet facing card.
Some of us have deliberately selected only one network interface in our vnstat.conf, and I do not use any kind of accounting on my network. Nor do I want it to track the internal network card under any circumstances.

My main systems also have Virtualbox installed, which also means they have three additional virtual network interfaces.
===
ls -1 /sys/class/net/
enp3s0@
lo@
vboxnet0@
virbr0@
virbr0-nic@
===

Don't add something which will automatically add All interfaces – unless this is triggered by the manual activation of the accounting system.
I.e. It should not be periodically checking for interfaces.
Comment 22 Nicolas Nicolas 2021-03-13 10:09:27 CET
(In reply to papoteur from comment #20)
> Hi Dave, thank you for you contribution.
> I don't think this is the way which is expected. drakconnectcenter includes
> a way to select accounting by interface.
> See
> http://gitweb.mageia.org/software/drakx-net/tree/lib/network/connection.
> pm#n279
> ACCOUNTING=yes is written in the config file for the interface. What is to
> do is to scan interface files and to check which ones have ACCOUNTING=yes
> What I don't know is what can be the trigger of such a scan.

In fact i think that draknetcenter is not activating the vnstat systemd service ( so vnstat can't start this way).

As i understood when the accounting is written by the the tool in the interface file and when the /etc/init.d/network is launched (if not using networkmanager) at boot, it should bring up interfaces and consequently launch the scripts located in /etc/sysconfig/network-scripts/ifup.d ( and vnstat_ip-up which is checking the presence of the ACCOUNTING=yes presence ).

But this script seems to be not launched for other interfaces other than the lo interface ( and lo interface seems to be excluded to be added  !

Moreover the vnstat_ip-up seems to be buggy as the -u and -r ar not recognized by vnstat ( and probably --enable too).
Comment 23 Nicolas Nicolas 2021-03-15 01:24:30 CET
Hello,

i tried to play with the /etc/init.d/network script... ;-)

Below the things i changed during my tests:

edit the /etc/init.d/network script by modifying the line 133 from

action "Bringing up interface %s: " $i ./ifup $i boot

to

action "Bringing up interface %s: " $i ./ifup ifcfg-$i boot

This seems to allow the network script to bring up other interfaces trougth the ifup.d scripts ( seems not otherwise).

Then i change the /etc/sysconfig/network-scripts/ifup.d/vnstat_ip-up;provided by  the vnstat package to ( to remove not supported options):

#!/usr/bin/sh
if [ -r /etc/sysconfig/network-scripts/ifcfg-$1 ]; then
	. /etc/sysconfig/network-scripts/ifcfg-$1
	if [ "a$ACCOUNTING" = "ayes" ]; then
		if [ ! -w /var/lib/vnstat/$1 ]; then
			# creating database
			/usr/bin/vnstat --add -i $1 > /dev/null
		fi
		# enabling monitoring
		#/usr/bin/vnstat -r --enable -i $1
		# update daemon
		service vnstat start
		fi
fi

This way the vnstat seems to start ( seems running as root), even if the vnstat systemd service not activated (but should be better if activated/deactivated trougth draknetcenter and drakconnect ( seems theses two programs not using same functions to write interface settings)).
Comment 24 papoteur 2021-03-15 12:16:10 CET
Thanks Nicolas,
Thus, this explain why the service is not enable by default, but only through network.service.
I would replace
>service vnstat start
by
>systemctl start vnstat.service

There is still a question. Should we consider that when using NetworkManager, we don't access to the statistics this way?
Because recommendations for NetworkManager is to mask network.service.

Don"t forget https://bugs.mageia.org/show_bug.cgi?id=25417#c17 as storage means have changed with v2, and I don't remember how Jose fixed the above cited bug.

Note You need to log in before you can comment on or make changes to this bug.