Site::getByComposite('month') sums a Site’s daily buckets once per Site whose bandwidth_spans row covers that day. Spans are not filtered by Site.
cpcmd misc:cp-version
revision: 919c1b2c95d76375df87cecec233021fbf43a490
timestamp: 1795013517
ver_maj: 3
ver_min: 2
ver_patch: 49
ver_pre: ''
dirty: false
checksum: 13529048271e14d
debug: false
os: '8.10'
variant: rocky
kernel: 4.18.0-553.126.1.el8_10.x86_64
Flow
bandwidth:get-all-composite-bandwidth-data('month')
`- Site::getByComposite('month')
`- bandwidth_spans x site_totals_daily_view
| daily view filtered to site 1
| spans NOT filtered
v
+-----------------+ +-----------------+ +-----------------+
| span site 1 | | span site 2 | ... | span site 9 |
| 04-10 .. 05-10 | | 04-10 .. 05-10 | | 04-10 .. 05-10 |
+-----------------+ +-----------------+ +-----------------+
\ | /
+--------- each site 1 day bucket matches --------+
|
v
site 1 total x 9
Reproduce
9 Sites created the same day:
SELECT begindate, count(*) FROM bandwidth_spans WHERE begindate = '2026-04-10' GROUP BY 1;
begindate | count
------------+-------
2026-04-10 | 9
Raw log, site 1, 2026-04-10 to 2026-05-10:
SELECT sum(in_bytes), sum(out_bytes) FROM bandwidth_log
WHERE site_id = 1 AND ts >= '2026-04-10' AND ts < '2026-05-10';
sum | sum
----------+----------
11340567 | 11039535
API, same Site and span:
cpcmd -d <domain> bandwidth:get-all-composite-bandwidth-data
-
begin: 1775779200
end: 1778371200
in_bytes: !!float 102065103
out_bytes: !!float 99355815
+-----------+-----------+-----------+-------+
| | raw log | API | ratio |
+-----------+-----------+-----------+-------+
| in_bytes | 11340567 | 102065103 | 9 |
| out_bytes | 11039535 | 99355815 | 9 |
+-----------+-----------+-----------+-------+
site_totals_hourly_view and site_totals_daily_view match the raw log. bandwidth:get-all-composite-bandwidth-data('day') and bandwidth:usage are correct.