If your customers shared across different Oracle container databases and you want to charge them based on they Utilizations then below queries will help you.
(CPU)
SELECT
s.con_id,
p.pdb_name,
ROUND((AVG(s.cpu_consumed_time) / SUM(AVG(s.cpu_consumed_time)) OVER()) * 100, 2) AS cpu_used_percent
FROM V$RSRCMGRMETRIC s
JOIN CDB_PDBS p ON s.con_id = p.con_id
GROUP BY s.con_id, p.pdb_name
HAVING AVG(s.cpu_consumed_time) > 0 -- Exclude zero CPU usage
ORDER BY cpu_used_percent DESC;
(CPU + Storage in GB)
WITH cpu_usage AS (
SELECT
s.con_id,
p.pdb_name,
ROUND((AVG(s.cpu_consumed_time) / SUM(AVG(s.cpu_consumed_time)) OVER()) * 100, 2) AS cpu_used_percent
FROM V$RSRCMGRMETRIC s
JOIN CDB_PDBS p ON s.con_id = p.con_id
GROUP BY s.con_id, p.pdb_name
HAVING AVG(s.cpu_consumed_time) > 0
),
storage_usage AS (
SELECT
a.con_id,
b.pdb_name,
ROUND(SUM(a.used_space) / 1024 / 1024, 2) AS used_gb,
ROUND(SUM(a.tablespace_size) / 1024 / 1024, 2) AS allocated_gb
FROM CDB_TABLESPACE_USAGE_METRICS a
JOIN CDB_PDBS b ON a.con_id = b.con_id
GROUP BY a.con_id, b.pdb_name
)
SELECT
c.con_id,
c.pdb_name,
c.cpu_used_percent,
s.used_gb,
s.allocated_gb
FROM cpu_usage c
LEFT JOIN storage_usage s ON c.con_id = s.con_id
ORDER BY cpu_used_percent DESC;
Expected Output
| CON_ID | PDB_NAME | CPU_USED_PERCENT | USED_GB | ALLOCATED_GB |
|---|---|---|---|---|
| 5 | P_DB1 | 51.36 | 14.65 | 17.58 |
| 6 | P_SAMCO | 39.07 | 11.72 | 14.65 |
| 9 | P_DBACO | 6.65 | 7.81 | 9.77 |
Leave a comment