-- Create a table containing a timestamp column and two columns with
-- normalized ratio between available memory (availrmem) and kernel pages
-- relative to total number of system pages (pagestotal).
-- We do not GROUP BY here, because we want to have each line from input
-- represented in output.
-- Input data was originally produced with kspgs tool.
SELECT
-- The `-6 hours` here tells SQLite to subtract 6 hours from the
-- timestamp, which will adjust for timezone delta between GMT
-- and Central Timezone. Adjust this number for correct timezone.
strftime('%s', timestamp, 'unixepoch','-6 hours') as timestamp,
ROUND((CAST(availrmem AS double) / CAST(pagestotal AS double)
- subq.avgAvRatio) / subq.sdAvRatio, 4) as "Z-score Ratio Available Total",
ROUND((CAST(pp_kernel AS double) / CAST(pagestotal AS double)
- subq.avgKernRatio) / subq.sdKernRatio, 4) as "Z-score Ratio Kernel Total"
FROM (
SELECT
avg(availrmem / CAST(pagestotal AS double)) as avgAvRatio,
stdev(availrmem / CAST(pagestotal AS double)) as sdAvRatio,
avg(pp_kernel / CAST(pagestotal AS double)) as avgKernRatio,
stdev(pp_kernel / CAST(pagestotal AS double)) as sdKernRatio
FROM mem
) subq, mem