I want to extract bandwidth for each site/client over a period of time even if disconnects/restarts occur etc.
Is this possible in the client config etc? As in CID = 0 1 2 3 4 5 etc
Or is there another way to achieve my aim?
Yes, there is a better way, and that's by using the client's commonName, which will be unique to the client you're connecting, at least assuming you're not doing silly things like re-using a single X509 cert between many clients.
On disconnect, the
--client-disconnect script hook exposes the bytes transferred in each direction that can be used for accounting purposes. Additionally, the bytes of any active connection as associated with its commonName can be seen with the
status management interface command (see
--management in the manpage for details.)
For a practical example of how on-disconnect accounting can work, please see the
user-accounting component of my
OpenVPN-dynamic github project,
available here.
If you need to keep persistent counters, use my sample code as a starting point and store the running total somewhere; obviously you can do more complex things once you have the values, like put them in an LDAP or SQL backend somewhere.