Tap total traffic of a VM via API

Profdanibest

Active Member
May 14, 2019
9
0
41
32
Hello,

Since I pay my provider for the traffic consumed for my VM and container every month, I would like to have an overview of how much traffic my VM and container have caused per month. I know that there is a column on the Proxmox GUI at cluster level, but it is reset after a VM restart. Therefore, I would like to use the API to capture the total traffic per container and VM and save it in a database.

I've seen documentation that you can access the rrdata.
Example :
Code:
pvesh get /nodes/<node>/qemu/<vmid>/rrddata --timeframe day --cf AVERAGE --output-format json | jq '.[] | {netin,netout,time}'
Answer:
Code:
{
  "netin": 4513759.48166667,
  "netout": 3806487.17,
  "time": 1675764000
}
{
  "netin": 4989408.575,
  "netout": 1991200.405,
  "time": 1675765800
}
{
  "netin": 5045404.40333333,
  "netout": 1300799.97166667,
  "time": 1675767600
}
{
  "netin": 5143381.78166667,
  "netout": 3196785.02666667,
  "time": 1675769400
}
{
  "netin": 5112009.09333333,
  "netout": 4100376.28666667,
  "time": 1675771200
}
{
  "netin": 5171156.83333333,
  "netout": 2866577.02333333,
  "time": 1675773000
}

is this correct? As far as I understand it, the information is given in bytes and I would have to add the in and out values one day. Collect these for a month and then I have the total traffic consumption.

Can someone tell me if this is the right way or did I miss something? :) I would be grateful for any answer. But it's also a pity that you can't specify a time slot in the API. Or have I overlooked because what? :)

[EDIT]

I also found the following endpoint.
Code:
API GET /nodes/<node>/netstat
However, this counter is reset each time. Can someone explain the difference between the two api endpoints? especially since the two access points also appear to show different NetIn/NetOut values.
 
Last edited: