CPU utilization is not a base metric in DPA's Resource tab because the value is not available from within the database. However, by using Foreign Data Wrappers (FDW) we can make host information available to the database so that DPA can query it. If your Postgres database is running on Linux, there is a file name /proc/loadavg that provides CPU information, and /proc/meminfo that provides Memory information.
Note: if you are using Windows, Performance Monitor (perfmon) can be used to create a file and publish any metrics needed to a file. In this case, modify the FDW definitions accordingly.
The following statement creates a table within Postgres that points to the /proc/loadavg file, which contains CPU metrics and makes it available for querying:
CREATE FOREIGN TABLE loadavg (one_min text, five_min text, fifteen_min text, scheduled text, pid text)
SERVER fileserver OPTIONS (filename '/proc/loadavg', format 'text', delimiter ' ');
# cat /proc/loadavg 0.75 0.35 0.25 1/25 1747
The following statement uses the /proc/meminfo file to make memory metrics available for querying as well:
CREATE FOREIGN TABLE mem_data (metric text, value text)
SERVER fileserver OPTIONS (filename '/proc/meminfo', format 'csv', delimiter ':');
The queries that you can use for inclusion as metrics in DPA are as follows, and these assume you used 60 seconds as the metric collection frequency:
SELECT AVG(CAST(one_min as decimal)) FROM loadavg;
The free and total memory values appear in different lines in this file, so do a self join to get both values in the same query:
SELECT 100-(MemFree / MemTotal)
SELECT m1.value AS MemTotal, m2.value AS MemFree
FROM mem_data m1, mem_date m2
WHERE m1.metric = 'MemTotal'
AND m2.metric = 'MemFree') mem