GoAdmio

bandwidth

Calculate each domain's monthly bandwidth usage (HTTP and FTP) and store it in GoAdmio

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/bandwidth measures how much traffic every hosted domain has used this month and saves the total in GoAdmio. For each domain it:

The command does not set or enforce limits. Limits are set when the account is created (see create, --bandwidth); this command keeps the usage figure up to date.


Quick start

# Update bandwidth usage for all domains
/go/bandwidth

Run it on a schedule (for example once a day from cron) so every day has a row.


Syntax

/go/bandwidth

The command takes no options or arguments. It always processes every domain that has a www directory under /home.

If you run it without root, it re-runs itself with sudo.


Options

None. Any arguments you pass are ignored.


Output

The command prints nothing. Check the results in the databases or the log.

What Where
Daily HTTP bytes per domain Bandwidth table in /var/lib/sqlite/bandwidth.db
Monthly total per domain (bytes) BandwidthUsed column of the Site table in /var/lib/sqlite/site.db
Record of each run /var/log/go/bandwidth.log

Each run adds one line to the log, in this form:

[Nov 20 00:10:01]# bandwidth

Examples

# Run once, for all domains
/go/bandwidth
# Run every day at 00:10 (cron entry)
10 0 * * * /go/bandwidth
# Check the stored monthly usage of one domain (bytes)
sqlite3 /var/lib/sqlite/site.db "select BandwidthUsed from Site where Domain='example.com'"
# See the daily rows saved for a domain
sqlite3 /var/lib/sqlite/bandwidth.db "select Date,Bandwidth from Bandwidth where Domain='example.com' order by TimeStamp"

Troubleshooting

Symptom Likely cause Fix
BandwidthUsed is 0 for a domain No requests in the access log during the last 24 hours. Check that the domain receives traffic and that the access log is being written.
A domain is skipped It has no /home/<domain>/www directory. Check that the account exists and was created correctly.
No new row for today The command did not run. Check /var/log/go/bandwidth.log and your cron entry.
sqlite3 errors A database is missing or locked. Check the files in /var/lib/sqlite/ and run again.
FTP usage looks too high See Known issue. Fix the month filter in the script.

Details

How HTTP usage is calculated

The access log used by GoAdmio is read with awk. Lines are split on |, and a line counts for a domain when:

Field Meaning Condition
$2 Domain Equals the domain being processed
$6 Time stamp Newer than 24 hours ago
$9 Bytes sent Added to the total

The result is saved as today's row. The row is created on the first run of the day and replaced on every later run, so running the command more than once a day does not double-count.

The monthly HTTP total is the sum of all daily rows whose time stamp is on or after the first day of the current month.

How FTP usage is calculated

The FTP total is the sum of FileSize in the Ftplog table of /var/lib/sqlite/ftplog.db for the account's username. See ftplog for FTP reports.

Known issue: FTP month filter

The FTP query filters by month name and year, but the script never sets the month name. The filter therefore matches the whole year instead of the current month, and FTP usage can be counted for earlier months too.

What it does, in order

  1. Re-runs itself with sudo if not root.
  2. Appends a line to /var/log/go/bandwidth.log.
  3. Loads /go/function and the access log path.
  4. Sets today's date, the current time stamp, the time stamp 24 hours ago, and the time stamp of the start of the month.
  5. For each directory in /home that has a www folder:
    1. Looks up the account username in site.db.
    2. Adds the last 24 hours of HTTP bytes from the access log.
    3. Inserts today's row in bandwidth.db if missing, then updates it.
    4. Adds this month's HTTP rows.
    5. Adds the FTP transfer size.
    6. Saves HTTP + FTP as BandwidthUsed in site.db.

All values are stored in bytes.


See also

Command Description
create Create a GoAdmio account from the command line
ftplog Report FTP activity for a domain
usertop Check recent visitors per domain
visits Check daily visits and estimate capacity
cron Set up main cron jobs in GoAdmio