Monitoring network usage

Hello, I was wondering whether there is a command I could type into the terminal of Dom0 to monitor network download and upload speed and total amounts of data received and sent? My internet provider has a cap on Gb used per month.

Why in dom0?

I personally use iftop under sys-net. It doesn’t log across reboots, though, but gives clear insights on throughput and bandwidth used in a session.

That means installing iftop on the template used by sys-net.

If looking for something that keeps track between reboots, maybe doing that inside of qubes is not the way to go, even less if you roam.

In my opinion, the best way to do this is from your router? (The capping “source”).

You seem to have missed architectural properties of Qubes OS. dom0 has no oversight of sys-net nor its network cards directly.

You would need to have that oversight in a qube where traffic can be observed, where sys-net is logical here since the actual qube from where all network traffic is going to/from your capped internet source either from wifi/ethernet.

1 Like

Yep. But I still think it would be more beneficial for @bill to hear from him first

And after that

http://www.catb.org/esr/faqs/smart-questions.html

Duh. I should have known. I was thinking sys-net after I left for my errands.

1 Like

Here I looked at the possibility of using xfce4-netload-plugin. It works for monitoring network speed. However, due to Qubes OS’s specifics, I need to start it in a Panel from sys-net which is not quite clean visually - the panel runs in its own small window with a title bar, floating etc.

For measuring used traffic on my Linux systems I usevnstat. However, it stores its db to `/var’ which means it will “forget” its data when sys-net is restarted. I am still looking for a proper way to fix this or for an alternative. If someone has the answer, this would be good completion to the current thread.

Look at bind-dirs
vnstat stores the data in /var/lib/vnstat/vnstat.db
Add this line to /rw/config/qubes-bind-dirs.d/50_user.conf, (creating
file if not present):
binds+=( '/var/lib/vnstat/' )
Reboot
Now the database will be persistent across reboots.

Of course you cant do this in a disposable qube. There you will have to
stream the db to a persistent qube, probably over qrexec. You could use
qubes-sync for this, but you will
have to resync back before starting monitoring.

I never presume to speak for the Qubes team.
When I comment in the Forum or in the mailing lists I speak for myself.

Thank you!

What about /etc/vnstat.conf which must store the settings persistently? Is it possible to add a single file to 50_user.conf or is there a more appropriate way (e.g. editing /etc/vnstat.conf in the template)? If more than one way is available, which one is better and why?

P.S. One more question: How do I persist the start of the vnstat service? I suppose that this needs some Qubes-tweak too, to make the vnstat service start when sys-net starts.

Whenever I want something to persist in disposable, I put corresponding files into disposable’s dvm-template /rw/bind-dirs, and/or /rw/config (probably rc.local there for your question, but I’m not sure), etc…

Yes, you can add a single file to bind-dirs array.
As enmus said, you can do this in the disposable template.
You can also use ~/.vnstatrc which will override that config file.

If you are using a disposable qube where you want to monitor the
traffic, bind-dirs wont be any use, as I said.

In an ordinary qube, you can just use bind-dirs and start the service
as normal. You can enable and start the service from rc.local, or enable
it in the template and add a dependency - this is the Qubes way. You
then have to enable the service with qvm-features.

In a disposable you want to sync the db in to the disposable and then
start the service, and you want to do this before the network comes up.
Depending on what tool you use to sync the db in and out, you will need
a systemd service to ensure the sync is completed before the vnstat
service is started.
You’ll need a similar service after bringing down the vnstat service to sync out
the db before the qube shuts down.

@enmus thanks for the extra tip but my questions are not for disposable sys-net. Could you answer them?

You should give that info 4 days before

https://www.catb.org/~esr/faqs/smart-questions.html

What question(s) aren’t exactly answered by @unman?
I’m quoting them here

However, it stores its db to `/var’ which means it will “forget” its data when sys-net is restarted. I am still looking for a proper way to fix this or for an alternative.

What about /etc/vnstat.conf which must store the settings persistently?

Is it possible to add a single file to 50_user.conf or is there a more appropriate way (e.g. editing /etc/vnstat.conf in the template)?

If more than one way is available, which one is better and why?

How do I persist the start of the vnstat service?

Damn. There is some issue with the forum and for some threads (current one included) I am not getting email notifications. This is a problem as I use the forum by email. I have contacted one of the mods and I hope to get a reply. Sorry for the confusion!

That said, now I see @unman replied too but I didn’t get his reply. Thank you @unman and @enmus.

In an ordinary qube, you can just use bind-dirs and start the service as normal. You can enable and start the service from rc.local, or enable it in the template and add a dependency - this is the Qubes way. You then have to enable the service with qvm-features.

I know how to systemctl enable/disable/start/stop a service but I don’t understand “the Qubes way”. Could you kindly ELI5?

What question(s) aren’t exactly answered by @unman?
I’m quoting them here

Now that I have seen his reply, perhaps only this one:

1 Like

Good we clarified it, I was rather confused.

I can’t speak on unmans behalf, but I think he basically said what I did: you can either use bind-dirs/qvm-features (and he added that is Qubes way), or rc.local (which he didn’t add is general, Linux way).

Even if he meant something else, basics are there and I’d recommend you to use bind-dirs/qvm-features to avoid casual issues with commands in rc.local not working always as expected (don’t ask me for examples, you can searx them)

IIUC (please correct me if I am wrong), “the Qubes way” would include opening the settings for the qube (sys-net) and adding the vnstat service manually in Services tab.

If the above is correct, then the only part I don’t understand is “and add a dependency”. I hope someone can clarify what is a dependency in the particular context and how to add it properly.

You could try and tell.

Example:

Install a new service in the template - say rsync
A systemd unit file will be placed in /usr/lib/systemd/system/rsync.service

Under systemd you can create a “drop-in” directory at foo.service.d/ - see here
.conf files placed here will modify the behaviour of the unit file.

Create the file /usr/lib/systemd/system/rsync.service.d/30_qubes.conf -

[Unit]
ConditionPathExists=/var/run/qubes-service/rsync
After=qubes-sysinit.service

The rsync service will be conditional on the existence of /var/run/qubes-service/rsync

Enabling the service for a qube in the Settings GUI, or by qvm-features QUBE service.rsync 1
will ensure that file exists, so the service can start.
Disabling the service means that the file will not be present, so the service cannot start.