Q:

Is there a way of monitoring how many bytes has my server tranferred?

So recently I saw a this website: https://0day.rocks/ and there is a text about this server being a Tor node. But under that is a number of bytes (terabytes) that server has transferred since last reset. I already saw similar thing on other websites but I'm really interested in how to do this in php (if it is even possible). And just to say I'm not asking you to write code for me, I just want someone to tell me what to read or where to get started, etc. Thanks in advance.

A:

On Linux it's easy to query interface statistics which will count all bytes transferred, and not just those by Tor, or Apache.
The stats from 0day are being collected directly from the Tor controller, which keeps track of it's own traffic usage.
If your public interface is eth0, you can get the bytes transferred and received from the following files:
/sys/class/net/eth0/statistics/tx_bytes
/sys/class/net/eth0/statistics/rx_bytes

With systemd predictable network interface naming, the interface may look more like enp3s0f0.
Alternatively you can parse info out of /proc/net/dev but the first two are easier.
In PHP, any user can read those using file_get_contents to display on a page.  You can use an answer like this to convert the bytes in another unit if you want.
The kernel documentation about the net statistics can be found here: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net-statistics

