Introduction
This document explains how to retrieve cPanel account statistics using the UAPI command-line interface. The StatsBar::get_stats API allows administrators to obtain usage information such as:
- Monthly Bandwidth Transfer
- Disk Space Usage
- Email usage
- Database usage
- Other cPanel account statistics
In this example, we retrieve only the bandwidth usage and disk space usage for a cPanel account.
Prerequisites
Before running the command, ensure the following requirements are met:
- Root SSH access to the cPanel server.
- WHM/cPanel installed.
- The target cPanel account exists.
- The
uapicommand is available. - Sufficient privileges to execute UAPI commands for the target account.
Verify the UAPI command:
$ which uapi
Example output:
$ /usr/bin/uapi
Reference Links:
How to check cPanel User Resource Usage using UAPI
Command Syntax
$ uapi --output=jsonpretty --user=<cpanel user name > StatsBar get_stats display='bandwidthusage|diskusage'
Example
Suppose the cPanel account username is example.
Run:
$ uapi --output=jsonpretty --user=example StatsBar get_stats display='bandwidthusage|diskusage'
Example Output
{
"apiversion": 3,
"func": "get_stats",
"module": "StatsBar",
"result": {
"data": [
{
"item": "Monthly Bandwidth Transfer",
"id": "bandwidthusage",
"count": "6.73 GB",
"max": "unlimited",
"percent": 0
},
{
"item": "Disk Space Usage",
"id": "diskusage",
"count": "78.71 GB",
"max": "unlimited",
"percent": 0
}
],
"status": 1
}
}
Expected Result
A successful execution returns:
- Current monthly bandwidth usage.
- Current disk space usage.
- Quota information (or
unlimitedif no quota is configured). - JSON output suitable for automation and scripting.
Common Use Cases
- Monitor customer resource usage.
- Integrate account statistics into monitoring scripts.
- Generate hosting usage reports.
- Validate disk usage before migrations.
- Check bandwidth consumption for hosted websites.
Conclusion
The StatsBar::get_stats UAPI function provides a simple and efficient way to retrieve cPanel account resource statistics from the command line. By specifying the desired statistics using the display parameter, administrators can obtain structured JSON output that is easy to read, automate, and integrate into monitoring or reporting workflows. This method is particularly useful for auditing account usage, tracking resource consumption, and supporting operational tasks such as capacity planning and migrations.
Related Articles:
How to create a database user in cpanel via cli using the uapi tool
How to create db user and password and give privileges in cpanel using uapi in terminal