Operating System & Version
CloudLinux 7
cPanel & WHM Version
v92.0.12

jam230

Registered
Mar 5, 2021
4
0
1
Canada
cPanel Access Level
Root Administrator
I am running the bandwidth query command but I am not sure how to interpret the data:

Code:
uapi --user=user Bandwidth query grouping='year_month' protocols='http|imap|smtp|pop3|ftp' --output=jsonpretty
I'm pretty sure it's returning the right data and I can parse using PHP but let's say I want to get the bandwidth for the current month; which number would that be and I assume this is in bytes?:

JSON:
{
   "module" : "Bandwidth",
   "result" : {
      "status" : 1,
      "warnings" : null,
      "metadata" : {},
      "data" : {
         "1612155600" : 459031956,
         "1614574800" : 219154161,
         "1609477200" : 122039871,
         "1601524800" : 114754161,
         "1606798800" : 68911489,
         "1604203200" : 125230028
      },
      "messages" : null,
      "errors" : null
   },
   "func" : "query",
   "apiversion" : 3
}
I tried converting those numbers without the quotes into GB by multiplying by 1,073,741,824 but this doesn't seem to match up or even close to the bandwidth data in the Bandwidth Usage section in WHM. Is someone able to explain this?

API Doc for reference: Return cPanel account's bandwidth usage report · cPanel & WHM Developer Portal
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
4,483
566
273
cPanel Access Level
Root Administrator
Hey hey! I checked with our developers and confirmed those are epoch stamps for month on the left and then the bytes for the service on the right. I thought it looked slightly better when running the command this way:

Code:
uapi --user=username Bandwidth query grouping='domain|protocol|year_month' protocols='http|imap|smtp|pop3|ftp' --output=jsonpretty
As that broke up the protocols a bit so you could see specifically where the bandwidth is.

If you convert the epoch dates, they should be the first of the month in question.
 

jam230

Registered
Mar 5, 2021
4
0
1
Canada
cPanel Access Level
Root Administrator
Thanks! Converting the epoch time stamps really helped track down the numbers I was looking for and when divided by (not multiplied as stated before) that large number, I was able to get the GB.