Re:Show HN: pg_netstat, a Postgres extension to monitor data...
by djbusby on Tuesday September 13, 2022 @03:08PM
(#32828870)
I would like to see your magic please.
[ Parent
| on HN ]
Re:Show HN: pg_netstat, a Postgres extension to monitor data...
by hyperman1 on Thursday September 15, 2022 @03:13AM
(#32848207)
Not much magic in there, to be honest:
Setup like this:
CREATE EXTENSION file_fdw;
CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;
then do this for the easy interpretable proc files: CREATE FOREIGN TABLE IF NOT EXISTS proc_loadavg(
load1 decimal,
load5 decimal,
load15 decimal,
threads_runnable_total text,
most_recent_pid integer
) SERVER pglog OPTIONS ( filename '/proc/loadavg', header 'false',delimiter ' ' );For harder things, read the file as lines instead of fields, then create a view with some regexes to split it in fields:
CREATE FOREIGN TABLE IF NOT EXISTS proc_meminfo(
line text
) SERVER pglog OPTIONS ( filename '/proc/meminfo', header 'false',delimiter '$' );
CREATE OR REPLACE VIEW proc_meminfo_interpreted AS
WITH arr AS (SELECT regexp_split_to_array(line,':| +') a FROM proc_meminfo)
SELECT a[1] as name,a[3] as value FROM arr;
Hardest part is creating semi-legible source code in HN ;-)