Assuming you have root access to s Linux machine somewhere on the path (either endpoint, or even a router in between), you can write an iptables rule that matches the application traffic and directs it to a particular chain that does nothing but accept all packets. The kernel maintains a byte and packet counter on each chain. Assuming the packets you want to count go from IP 10.1.2.3 TCP port 42123 to IP 10.7.8.9 TCP port 42789:
iptables -I FORWARD -p tcp -s 10.1.2.3 --sport 42123 -d 10.7.8.9 --dport 42789 -j ACCEPT
OUTPUT on the source host, by
INPUT on the destination host.
You can read the counters with
iptables -nvxL FORWARD 42 where 42 is the number of the rules (the first rule is number 1).
Do this for each direction if you want to count both directions. Read the counters at known time intervals to measure bandwidth usage.
You can gain a little flexibility if you create an intermediate chain.
iptables -N myapp_counter
iptables -A myapp_counter -j ACCEPT
iptables -I FORWARD -p tcp -s 10.1.2.3 --sport 42123 -d 10.7.8.9 --dport 42789 -j myapp_counter
iptables -I FORWARD -p tcp -s 10.7.8.9 --sport 42789 -d 10.1.2.3 --dport 42123 -j myapp_counter
With this setup, the counter for the
myapp_counter will include traffic in both directions. Another benefit of going through a chain is that you can atomically read the counter on the chain and set it to 0 with
iptables -nvxZL myapp_counter. And you don't need to figure out the rule number, so it's easier to automate the setup.