You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 3
Next »
This page describes some queries that you can use to view aggregate resource usage.
You can use them as templates for your own queries to retrieve data from the replicated accounting database.
Previously the accounting system used views, which have been maintained for legacy applications only. See Abiquo accounting architecture.
Hourly Usage Sum Template Query ...
SELECT
v.startTime AS startTime,
v.endTime AS endTime,
v.idAccountingResourceType AS idAccountingResourceType,
v.resourceType AS resourceType,
SUM(v.resourceUnits) AS resourceUnits,
v.idEnterprise AS idEnterprise,
v.idVirtualDataCenter AS idVirtualDataCenter,
v.enterpriseName AS enterpriseName,
v.virtualDataCenter AS virtualDataCenter
FROM
kinton_accounting.HOURLY_USAGE_MAX_VW v
WHERE
# APPLY CUSTOM QUERY FILTERS HERE, E.G. BY DATE RANGE AS BELOW
v.startTime >= '2012-04-16' AND v.endTime < '2012-04-17'
GROUP BY
v.startTime,
v.idAccountingResourceType,
v.idEnterprise, v.idVirtualDataCenter;
Daily Usage Sum Template Query ...
SELECT
CAST(a.startTime AS DATE) AS startTime,
CAST(a.startTime AS DATE) AS endTime,
a.idAccountingResourceType AS idAccountingResourceType,
a.resourceType AS resourceType,
SUM(a.resourceUnits) AS resourceUnits,
a.idEnterprise AS idEnterprise,
a.idVirtualDataCenter AS idVirtualDataCenter,
a.enterpriseName AS enterpriseName,
a.virtualDataCenter AS virtualDataCenter
FROM
kinton_accounting.HOURLY_USAGE_MAX_VW a
WHERE
# APPLY CUSTOM QUERY FILTERS HERE, E.G. BY DATE RANGE AS BELOW
a.startTime >= '2012-04-16' AND a.endTime < '2012-04-17'
GROUP BY
CAST(a.startTime AS DATE),
a.idAccountingResourceType,
a.idEnterprise, a.idVirtualDataCenter;
Monthly Usage Sum Template Query ...
SELECT
CAST((a.startTime - INTERVAL (DAYOFMONTH(a.startTime) - 1) day) AS DATE) AS startTime,
LAST_DAY(a.startTime) AS endTime,
a.idAccountingResourceType AS idAccountingResourceType,
a.resourceType AS resourceType,
SUM(a.resourceUnits) AS resourceUnits,
a.idEnterprise AS idEnterprise,
a.idVirtualDataCenter AS idVirtualDataCenter,
a.enterpriseName AS enterpriseName,
a.virtualDataCenter AS virtualDataCenter
FROM
kinton_accounting.HOURLY_USAGE_MAX_VW a
WHERE
# APPLY CUSTOM QUERY FILTERS HERE, E.G. BY DATE RANGE AS BELOW
a.startTime >= '2012-04-01' AND a.endTime < '2012-05-01'
GROUP BY
CAST((a.startTime - INTERVAL (dayofmonth(a.startTime) - 1) day) AS DATE),
a.idAccountingResourceType,
a.idEnterprise, a.idVirtualDataCenter;